Skip to content

Commit

Permalink
test wordpress transaction naming
Browse files Browse the repository at this point in the history
  • Loading branch information
lavarou committed Dec 4, 2023
1 parent 54ad95d commit d08c585
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
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($wp_filters[$hook_name], $value);
}

// 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");
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?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/add_filter
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($wp_filters[$hook_name], $value);
}

// 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");

0 comments on commit d08c585

Please sign in to comment.