-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
tests/integration/frameworks/wordpress/test_wordpress_transaction_name_hooks_off.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/*DESCRIPTION | ||
The agent should name WordPress web transaction as an 'Action' with the | ||
name generated from the template used to generate the page even when | ||
WordPress hooks are disabled. | ||
*/ | ||
|
||
/*SKIPIF*/ | ||
|
||
/*INI | ||
newrelic.framework = wordpress | ||
newrelic.framework.wordpress.hooks = false | ||
*/ | ||
|
||
/*ENVIRONMENT | ||
REQUEST_METHOD=GET | ||
*/ | ||
|
||
/*EXPECT_METRICS_EXIST | ||
Supportability/InstrumentedFunction/apply_filters | ||
WebTransaction/Action/template | ||
*/ | ||
|
||
/*EXPECT_ERROR_EVENTS null */ | ||
|
||
// Mock WordPress hooks; only a single callback for a given hook can be defined | ||
$wp_filters = []; | ||
|
||
function add_filter($hook_name, $callback) { | ||
global $wp_filters; | ||
$wp_filters[$hook_name] = $callback; | ||
} | ||
|
||
function apply_filters($hook_name, $value, ...$args) { | ||
global $wp_filters; | ||
return call_user_func_array($wp_filters[$hook_name], array($value, $args)); | ||
} | ||
|
||
// Hook 'template_include' with an identity filter | ||
function identity_filter($value) { | ||
return $value; | ||
} | ||
add_filter("template_include", "identity_filter"); | ||
|
||
// Emulate WordPress loading a template to render a page: | ||
$template = apply_filters("template_include", "./path/to/templates/template.php"); |
53 changes: 53 additions & 0 deletions
53
tests/integration/frameworks/wordpress/test_wordpress_transaction_name_hooks_on.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/*DESCRIPTION | ||
The agent should name WordPress web transaction as an 'Action' with the | ||
name generated from the template used to generate the page. Additionally | ||
since WordPress hooks are enabled, Framework/WordPress/Hook/template_include | ||
metric should be generated and the hook function should be instrumented. | ||
*/ | ||
|
||
/*SKIPIF*/ | ||
|
||
/*INI | ||
newrelic.framework = wordpress | ||
newrelic.framework.wordpress.hooks = true | ||
*/ | ||
|
||
/*ENVIRONMENT | ||
REQUEST_METHOD=GET | ||
*/ | ||
|
||
/*EXPECT_METRICS_EXIST | ||
Framework/WordPress/Hook/template_include | ||
Supportability/InstrumentedFunction/apply_filters | ||
WebTransaction/Action/template | ||
*/ | ||
|
||
/*EXPECT_ERROR_EVENTS null */ | ||
|
||
// Mock WordPress hooks; only a single callback for a given hook can be defined | ||
$wp_filters = []; | ||
|
||
function add_filter($hook_name, $callback) { | ||
global $wp_filters; | ||
$wp_filters[$hook_name] = $callback; | ||
} | ||
|
||
function apply_filters($hook_name, $value, ...$args) { | ||
global $wp_filters; | ||
return call_user_func_array($wp_filters[$hook_name], array($value, $args)); | ||
} | ||
|
||
// Hook 'template_include' with an identity filter | ||
function identity_filter($value) { | ||
return $value; | ||
} | ||
add_filter("template_include", "identity_filter"); | ||
|
||
// Emulate WordPress loading a template to render a page: | ||
$template = apply_filters("template_include", "./path/to/templates/template.php"); |