mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Tests: Update the terminology used for action or filter names in hook tests.
This replaces the `$tag` variables with `$hook_name`, to match the core function signatures. Follow-up to [24/tests], [62/tests], [866/tests], [1294/tests], [38571], [50807]. See #55652. git-svn-id: https://develop.svn.wordpress.org/trunk@53804 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
65e266ede6
commit
0ec5fb339b
@ -11,16 +11,16 @@ class Tests_Actions extends WP_UnitTestCase {
|
||||
* @covers ::do_action
|
||||
*/
|
||||
public function test_simple_action() {
|
||||
$a = new MockAction();
|
||||
$tag = __FUNCTION__;
|
||||
$a = new MockAction();
|
||||
$hook_name = __FUNCTION__;
|
||||
|
||||
add_action( $tag, array( &$a, 'action' ) );
|
||||
do_action( $tag );
|
||||
add_action( $hook_name, array( &$a, 'action' ) );
|
||||
do_action( $hook_name );
|
||||
|
||||
// Only one event occurred for the hook, with empty args.
|
||||
$this->assertSame( 1, $a->get_call_count() );
|
||||
// Only our hook was called.
|
||||
$this->assertSame( array( $tag ), $a->get_tags() );
|
||||
$this->assertSame( array( $hook_name ), $a->get_tags() );
|
||||
|
||||
$argsvar = $a->get_args();
|
||||
$args = array_pop( $argsvar );
|
||||
@ -31,21 +31,21 @@ class Tests_Actions extends WP_UnitTestCase {
|
||||
* @covers ::remove_action
|
||||
*/
|
||||
public function test_remove_action() {
|
||||
$a = new MockAction();
|
||||
$tag = __FUNCTION__;
|
||||
$a = new MockAction();
|
||||
$hook_name = __FUNCTION__;
|
||||
|
||||
add_action( $tag, array( &$a, 'action' ) );
|
||||
do_action( $tag );
|
||||
add_action( $hook_name, array( &$a, 'action' ) );
|
||||
do_action( $hook_name );
|
||||
|
||||
// Make sure our hook was called correctly.
|
||||
$this->assertSame( 1, $a->get_call_count() );
|
||||
$this->assertSame( array( $tag ), $a->get_tags() );
|
||||
$this->assertSame( array( $hook_name ), $a->get_tags() );
|
||||
|
||||
// Now remove the action, do it again, and make sure it's not called this time.
|
||||
remove_action( $tag, array( &$a, 'action' ) );
|
||||
do_action( $tag );
|
||||
remove_action( $hook_name, array( &$a, 'action' ) );
|
||||
do_action( $hook_name );
|
||||
$this->assertSame( 1, $a->get_call_count() );
|
||||
$this->assertSame( array( $tag ), $a->get_tags() );
|
||||
$this->assertSame( array( $hook_name ), $a->get_tags() );
|
||||
|
||||
}
|
||||
|
||||
@ -53,17 +53,19 @@ class Tests_Actions extends WP_UnitTestCase {
|
||||
* @covers ::has_action
|
||||
*/
|
||||
public function test_has_action() {
|
||||
$tag = __FUNCTION__;
|
||||
$func = __FUNCTION__ . '_func';
|
||||
$hook_name = __FUNCTION__;
|
||||
$callback = __FUNCTION__ . '_func';
|
||||
|
||||
$this->assertFalse( has_action( $tag, $func ) );
|
||||
$this->assertFalse( has_action( $tag ) );
|
||||
add_action( $tag, $func );
|
||||
$this->assertSame( 10, has_action( $tag, $func ) );
|
||||
$this->assertTrue( has_action( $tag ) );
|
||||
remove_action( $tag, $func );
|
||||
$this->assertFalse( has_action( $tag, $func ) );
|
||||
$this->assertFalse( has_action( $tag ) );
|
||||
$this->assertFalse( has_action( $hook_name, $callback ) );
|
||||
$this->assertFalse( has_action( $hook_name ) );
|
||||
|
||||
add_action( $hook_name, $callback );
|
||||
$this->assertSame( 10, has_action( $hook_name, $callback ) );
|
||||
$this->assertTrue( has_action( $hook_name ) );
|
||||
|
||||
remove_action( $hook_name, $callback );
|
||||
$this->assertFalse( has_action( $hook_name, $callback ) );
|
||||
$this->assertFalse( has_action( $hook_name ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,15 +74,15 @@ class Tests_Actions extends WP_UnitTestCase {
|
||||
* @covers ::do_action
|
||||
*/
|
||||
public function test_multiple_actions() {
|
||||
$a1 = new MockAction();
|
||||
$a2 = new MockAction();
|
||||
$tag = __FUNCTION__;
|
||||
$a1 = new MockAction();
|
||||
$a2 = new MockAction();
|
||||
$hook_name = __FUNCTION__;
|
||||
|
||||
// Add both actions to the hook.
|
||||
add_action( $tag, array( &$a1, 'action' ) );
|
||||
add_action( $tag, array( &$a2, 'action' ) );
|
||||
add_action( $hook_name, array( &$a1, 'action' ) );
|
||||
add_action( $hook_name, array( &$a2, 'action' ) );
|
||||
|
||||
do_action( $tag );
|
||||
do_action( $hook_name );
|
||||
|
||||
// Both actions called once each.
|
||||
$this->assertSame( 1, $a1->get_call_count() );
|
||||
@ -93,13 +95,13 @@ class Tests_Actions extends WP_UnitTestCase {
|
||||
* @covers ::do_action
|
||||
*/
|
||||
public function test_action_args_1() {
|
||||
$a = new MockAction();
|
||||
$tag = __FUNCTION__;
|
||||
$val = __FUNCTION__ . '_val';
|
||||
$a = new MockAction();
|
||||
$hook_name = __FUNCTION__;
|
||||
$val = __FUNCTION__ . '_val';
|
||||
|
||||
add_action( $tag, array( &$a, 'action' ) );
|
||||
add_action( $hook_name, array( &$a, 'action' ) );
|
||||
// Call the action with a single argument.
|
||||
do_action( $tag, $val );
|
||||
do_action( $hook_name, $val );
|
||||
|
||||
$call_count = $a->get_call_count();
|
||||
$this->assertSame( 1, $call_count );
|
||||
@ -113,17 +115,17 @@ class Tests_Actions extends WP_UnitTestCase {
|
||||
* @covers ::do_action
|
||||
*/
|
||||
public function test_action_args_2() {
|
||||
$a1 = new MockAction();
|
||||
$a2 = new MockAction();
|
||||
$tag = __FUNCTION__;
|
||||
$val1 = __FUNCTION__ . '_val1';
|
||||
$val2 = __FUNCTION__ . '_val2';
|
||||
$a1 = new MockAction();
|
||||
$a2 = new MockAction();
|
||||
$hook_name = __FUNCTION__;
|
||||
$val1 = __FUNCTION__ . '_val1';
|
||||
$val2 = __FUNCTION__ . '_val2';
|
||||
|
||||
// $a1 accepts two arguments, $a2 doesn't.
|
||||
add_action( $tag, array( &$a1, 'action' ), 10, 2 );
|
||||
add_action( $tag, array( &$a2, 'action' ) );
|
||||
add_action( $hook_name, array( &$a1, 'action' ), 10, 2 );
|
||||
add_action( $hook_name, array( &$a2, 'action' ) );
|
||||
// Call the action with two arguments.
|
||||
do_action( $tag, $val1, $val2 );
|
||||
do_action( $hook_name, $val1, $val2 );
|
||||
|
||||
$call_count = $a1->get_call_count();
|
||||
// $a1 should be called with both args.
|
||||
@ -147,19 +149,19 @@ class Tests_Actions extends WP_UnitTestCase {
|
||||
* @covers ::do_action
|
||||
*/
|
||||
public function test_action_args_3() {
|
||||
$a1 = new MockAction();
|
||||
$a2 = new MockAction();
|
||||
$a3 = new MockAction();
|
||||
$tag = __FUNCTION__;
|
||||
$val1 = __FUNCTION__ . '_val1';
|
||||
$val2 = __FUNCTION__ . '_val2';
|
||||
$a1 = new MockAction();
|
||||
$a2 = new MockAction();
|
||||
$a3 = new MockAction();
|
||||
$hook_name = __FUNCTION__;
|
||||
$val1 = __FUNCTION__ . '_val1';
|
||||
$val2 = __FUNCTION__ . '_val2';
|
||||
|
||||
// $a1 accepts two arguments, $a2 doesn't, $a3 accepts two arguments.
|
||||
add_action( $tag, array( &$a1, 'action' ), 10, 2 );
|
||||
add_action( $tag, array( &$a2, 'action' ) );
|
||||
add_action( $tag, array( &$a3, 'action' ), 10, 2 );
|
||||
add_action( $hook_name, array( &$a1, 'action' ), 10, 2 );
|
||||
add_action( $hook_name, array( &$a2, 'action' ) );
|
||||
add_action( $hook_name, array( &$a3, 'action' ), 10, 2 );
|
||||
// Call the action with two arguments.
|
||||
do_action( $tag, $val1, $val2 );
|
||||
do_action( $hook_name, $val1, $val2 );
|
||||
|
||||
$call_count = $a1->get_call_count();
|
||||
// $a1 should be called with both args.
|
||||
@ -186,13 +188,13 @@ class Tests_Actions extends WP_UnitTestCase {
|
||||
* @covers ::do_action
|
||||
*/
|
||||
public function test_action_args_with_php4_syntax() {
|
||||
$a = new MockAction();
|
||||
$tag = __FUNCTION__;
|
||||
$val = new stdClass();
|
||||
$a = new MockAction();
|
||||
$hook_name = __FUNCTION__;
|
||||
$val = new stdClass();
|
||||
|
||||
add_action( $tag, array( &$a, 'action' ) );
|
||||
add_action( $hook_name, array( &$a, 'action' ) );
|
||||
// Call the action with PHP 4 notation for passing object by reference.
|
||||
do_action( $tag, array( &$val ) );
|
||||
do_action( $hook_name, array( &$val ) );
|
||||
|
||||
$call_count = $a->get_call_count();
|
||||
$argsvar = $a->get_args();
|
||||
@ -200,12 +202,12 @@ class Tests_Actions extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_action_priority() {
|
||||
$a = new MockAction();
|
||||
$tag = __FUNCTION__;
|
||||
$a = new MockAction();
|
||||
$hook_name = __FUNCTION__;
|
||||
|
||||
add_action( $tag, array( &$a, 'action' ), 10 );
|
||||
add_action( $tag, array( &$a, 'action2' ), 9 );
|
||||
do_action( $tag );
|
||||
add_action( $hook_name, array( &$a, 'action' ), 10 );
|
||||
add_action( $hook_name, array( &$a, 'action2' ), 9 );
|
||||
do_action( $hook_name );
|
||||
|
||||
// Two events, one per action.
|
||||
$this->assertSame( 2, $a->get_call_count() );
|
||||
@ -214,13 +216,13 @@ class Tests_Actions extends WP_UnitTestCase {
|
||||
// 'action2' is called first because it has priority 9.
|
||||
array(
|
||||
'action' => 'action2',
|
||||
'tag' => $tag,
|
||||
'tag' => $hook_name,
|
||||
'args' => array( '' ),
|
||||
),
|
||||
// 'action' is called second.
|
||||
array(
|
||||
'action' => 'action',
|
||||
'tag' => $tag,
|
||||
'tag' => $hook_name,
|
||||
'args' => array( '' ),
|
||||
),
|
||||
);
|
||||
@ -232,23 +234,23 @@ class Tests_Actions extends WP_UnitTestCase {
|
||||
* @covers ::did_action
|
||||
*/
|
||||
public function test_did_action() {
|
||||
$tag1 = 'action1';
|
||||
$tag2 = 'action2';
|
||||
$hook_name1 = 'action1';
|
||||
$hook_name2 = 'action2';
|
||||
|
||||
// Do action $tag1 but not $tag2.
|
||||
do_action( $tag1 );
|
||||
$this->assertSame( 1, did_action( $tag1 ) );
|
||||
$this->assertSame( 0, did_action( $tag2 ) );
|
||||
// Do action $hook_name1 but not $hook_name2.
|
||||
do_action( $hook_name1 );
|
||||
$this->assertSame( 1, did_action( $hook_name1 ) );
|
||||
$this->assertSame( 0, did_action( $hook_name2 ) );
|
||||
|
||||
// Do action $tag2 10 times.
|
||||
// Do action $hook_name2 10 times.
|
||||
$count = 10;
|
||||
for ( $i = 0; $i < $count; $i++ ) {
|
||||
do_action( $tag2 );
|
||||
do_action( $hook_name2 );
|
||||
}
|
||||
|
||||
// $tag1's count hasn't changed, $tag2 should be correct.
|
||||
$this->assertSame( 1, did_action( $tag1 ) );
|
||||
$this->assertSame( $count, did_action( $tag2 ) );
|
||||
// $hook_name1's count hasn't changed, $hook_name2 should be correct.
|
||||
$this->assertSame( 1, did_action( $hook_name1 ) );
|
||||
$this->assertSame( $count, did_action( $hook_name2 ) );
|
||||
|
||||
}
|
||||
|
||||
@ -256,23 +258,23 @@ class Tests_Actions extends WP_UnitTestCase {
|
||||
* @covers ::do_action
|
||||
*/
|
||||
public function test_all_action() {
|
||||
$a = new MockAction();
|
||||
$tag1 = __FUNCTION__ . '_1';
|
||||
$tag2 = __FUNCTION__ . '_2';
|
||||
$a = new MockAction();
|
||||
$hook_name1 = __FUNCTION__ . '_1';
|
||||
$hook_name2 = __FUNCTION__ . '_2';
|
||||
|
||||
// Add an 'all' action.
|
||||
add_action( 'all', array( &$a, 'action' ) );
|
||||
$this->assertSame( 10, has_filter( 'all', array( &$a, 'action' ) ) );
|
||||
// Do some actions.
|
||||
do_action( $tag1 );
|
||||
do_action( $tag2 );
|
||||
do_action( $tag1 );
|
||||
do_action( $tag1 );
|
||||
do_action( $hook_name1 );
|
||||
do_action( $hook_name2 );
|
||||
do_action( $hook_name1 );
|
||||
do_action( $hook_name1 );
|
||||
|
||||
// Our action should have been called once for each tag.
|
||||
$this->assertSame( 4, $a->get_call_count() );
|
||||
// Only our hook was called.
|
||||
$this->assertSame( array( $tag1, $tag2, $tag1, $tag1 ), $a->get_tags() );
|
||||
$this->assertSame( array( $hook_name1, $hook_name2, $hook_name1, $hook_name1 ), $a->get_tags() );
|
||||
|
||||
remove_action( 'all', array( &$a, 'action' ) );
|
||||
$this->assertFalse( has_filter( 'all', array( &$a, 'action' ) ) );
|
||||
@ -283,36 +285,36 @@ class Tests_Actions extends WP_UnitTestCase {
|
||||
* @covers ::remove_action
|
||||
*/
|
||||
public function test_remove_all_action() {
|
||||
$a = new MockAction();
|
||||
$tag = __FUNCTION__;
|
||||
$a = new MockAction();
|
||||
$hook_name = __FUNCTION__;
|
||||
|
||||
add_action( 'all', array( &$a, 'action' ) );
|
||||
$this->assertSame( 10, has_filter( 'all', array( &$a, 'action' ) ) );
|
||||
do_action( $tag );
|
||||
do_action( $hook_name );
|
||||
|
||||
// Make sure our hook was called correctly.
|
||||
$this->assertSame( 1, $a->get_call_count() );
|
||||
$this->assertSame( array( $tag ), $a->get_tags() );
|
||||
$this->assertSame( array( $hook_name ), $a->get_tags() );
|
||||
|
||||
// Now remove the action, do it again, and make sure it's not called this time.
|
||||
remove_action( 'all', array( &$a, 'action' ) );
|
||||
$this->assertFalse( has_filter( 'all', array( &$a, 'action' ) ) );
|
||||
do_action( $tag );
|
||||
do_action( $hook_name );
|
||||
$this->assertSame( 1, $a->get_call_count() );
|
||||
$this->assertSame( array( $tag ), $a->get_tags() );
|
||||
$this->assertSame( array( $hook_name ), $a->get_tags() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::do_action_ref_array
|
||||
*/
|
||||
public function test_action_ref_array() {
|
||||
$obj = new stdClass();
|
||||
$a = new MockAction();
|
||||
$tag = __FUNCTION__;
|
||||
$obj = new stdClass();
|
||||
$a = new MockAction();
|
||||
$hook_name = __FUNCTION__;
|
||||
|
||||
add_action( $tag, array( &$a, 'action' ) );
|
||||
add_action( $hook_name, array( &$a, 'action' ) );
|
||||
|
||||
do_action_ref_array( $tag, array( &$obj ) );
|
||||
do_action_ref_array( $hook_name, array( &$obj ) );
|
||||
|
||||
$args = $a->get_args();
|
||||
$this->assertSame( $args[0][0], $obj );
|
||||
@ -329,12 +331,12 @@ class Tests_Actions extends WP_UnitTestCase {
|
||||
public function test_action_keyed_array() {
|
||||
$a = new MockAction();
|
||||
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
|
||||
add_action( $tag, array( &$a, 'action' ) );
|
||||
add_action( $hook_name, array( &$a, 'action' ) );
|
||||
|
||||
$context = array( 'key1' => 'val1' );
|
||||
do_action( $tag, $context );
|
||||
do_action( $hook_name, $context );
|
||||
|
||||
$args = $a->get_args();
|
||||
$this->assertSame( $args[0][0], $context );
|
||||
@ -343,7 +345,7 @@ class Tests_Actions extends WP_UnitTestCase {
|
||||
'key2' => 'val2',
|
||||
'key3' => 'val3',
|
||||
);
|
||||
do_action( $tag, $context2 );
|
||||
do_action( $hook_name, $context2 );
|
||||
|
||||
$args = $a->get_args();
|
||||
$this->assertSame( $args[1][0], $context2 );
|
||||
@ -369,14 +371,14 @@ class Tests_Actions extends WP_UnitTestCase {
|
||||
* @covers ::do_action
|
||||
*/
|
||||
public function test_action_recursion() {
|
||||
$tag = __FUNCTION__;
|
||||
$a = new MockAction();
|
||||
$b = new MockAction();
|
||||
$hook_name = __FUNCTION__;
|
||||
$a = new MockAction();
|
||||
$b = new MockAction();
|
||||
|
||||
add_action( $tag, array( $a, 'action' ), 11, 1 );
|
||||
add_action( $tag, array( $b, 'action' ), 13, 1 );
|
||||
add_action( $tag, array( $this, 'action_that_causes_recursion' ), 12, 1 );
|
||||
do_action( $tag, $tag );
|
||||
add_action( $hook_name, array( $a, 'action' ), 11, 1 );
|
||||
add_action( $hook_name, array( $b, 'action' ), 13, 1 );
|
||||
add_action( $hook_name, array( $this, 'action_that_causes_recursion' ), 12, 1 );
|
||||
do_action( $hook_name, $hook_name );
|
||||
|
||||
$this->assertSame( 2, $a->get_call_count(), 'recursive actions should call all callbacks with earlier priority' );
|
||||
$this->assertSame( 2, $b->get_call_count(), 'recursive actions should call callbacks with later priority' );
|
||||
@ -385,11 +387,11 @@ class Tests_Actions extends WP_UnitTestCase {
|
||||
/**
|
||||
* @covers ::do_action
|
||||
*/
|
||||
public function action_that_causes_recursion( $tag ) {
|
||||
public function action_that_causes_recursion( $hook_name ) {
|
||||
static $recursing = false;
|
||||
if ( ! $recursing ) {
|
||||
$recursing = true;
|
||||
do_action( $tag, $tag );
|
||||
do_action( $hook_name, $hook_name );
|
||||
}
|
||||
$recursing = false;
|
||||
}
|
||||
@ -402,19 +404,19 @@ class Tests_Actions extends WP_UnitTestCase {
|
||||
* @covers ::add_action
|
||||
*/
|
||||
public function test_action_callback_manipulation_while_running() {
|
||||
$tag = __FUNCTION__;
|
||||
$a = new MockAction();
|
||||
$b = new MockAction();
|
||||
$c = new MockAction();
|
||||
$d = new MockAction();
|
||||
$e = new MockAction();
|
||||
$hook_name = __FUNCTION__;
|
||||
$a = new MockAction();
|
||||
$b = new MockAction();
|
||||
$c = new MockAction();
|
||||
$d = new MockAction();
|
||||
$e = new MockAction();
|
||||
|
||||
add_action( $tag, array( $a, 'action' ), 11, 2 );
|
||||
add_action( $tag, array( $this, 'action_that_manipulates_a_running_hook' ), 12, 2 );
|
||||
add_action( $tag, array( $b, 'action' ), 12, 2 );
|
||||
add_action( $hook_name, array( $a, 'action' ), 11, 2 );
|
||||
add_action( $hook_name, array( $this, 'action_that_manipulates_a_running_hook' ), 12, 2 );
|
||||
add_action( $hook_name, array( $b, 'action' ), 12, 2 );
|
||||
|
||||
do_action( $tag, $tag, array( $a, $b, $c, $d, $e ) );
|
||||
do_action( $tag, $tag, array( $a, $b, $c, $d, $e ) );
|
||||
do_action( $hook_name, $hook_name, array( $a, $b, $c, $d, $e ) );
|
||||
do_action( $hook_name, $hook_name, array( $a, $b, $c, $d, $e ) );
|
||||
|
||||
$this->assertSame( 2, $a->get_call_count(), 'callbacks should run unless otherwise instructed' );
|
||||
$this->assertSame( 1, $b->get_call_count(), 'callback removed by same priority callback should still get called' );
|
||||
@ -423,11 +425,11 @@ class Tests_Actions extends WP_UnitTestCase {
|
||||
$this->assertSame( 1, $e->get_call_count(), 'callback added by later priority callback should not get called' );
|
||||
}
|
||||
|
||||
public function action_that_manipulates_a_running_hook( $tag, $mocks ) {
|
||||
remove_action( $tag, array( $mocks[1], 'action' ), 12, 2 );
|
||||
add_action( $tag, array( $mocks[2], 'action' ), 12, 2 );
|
||||
add_action( $tag, array( $mocks[3], 'action' ), 13, 2 );
|
||||
add_action( $tag, array( $mocks[4], 'action' ), 10, 2 );
|
||||
public function action_that_manipulates_a_running_hook( $hook_name, $mocks ) {
|
||||
remove_action( $hook_name, array( $mocks[1], 'action' ), 12, 2 );
|
||||
add_action( $hook_name, array( $mocks[2], 'action' ), 12, 2 );
|
||||
add_action( $hook_name, array( $mocks[3], 'action' ), 13, 2 );
|
||||
add_action( $hook_name, array( $mocks[4], 'action' ), 10, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -439,12 +441,12 @@ class Tests_Actions extends WP_UnitTestCase {
|
||||
* @covers ::remove_filter
|
||||
*/
|
||||
public function test_remove_anonymous_callback() {
|
||||
$tag = __FUNCTION__;
|
||||
$a = new MockAction();
|
||||
add_action( $tag, array( $a, 'action' ), 12, 1 );
|
||||
$this->assertTrue( has_action( $tag ) );
|
||||
$hook_name = __FUNCTION__;
|
||||
$a = new MockAction();
|
||||
add_action( $hook_name, array( $a, 'action' ), 12, 1 );
|
||||
$this->assertTrue( has_action( $hook_name ) );
|
||||
|
||||
$hook = $GLOBALS['wp_filter'][ $tag ];
|
||||
$hook = $GLOBALS['wp_filter'][ $hook_name ];
|
||||
|
||||
// From http://wordpress.stackexchange.com/a/57088/6445
|
||||
foreach ( $hook as $priority => $filter ) {
|
||||
@ -454,7 +456,7 @@ class Tests_Actions extends WP_UnitTestCase {
|
||||
&& 'action' === $function['function'][1]
|
||||
) {
|
||||
remove_filter(
|
||||
$tag,
|
||||
$hook_name,
|
||||
array( $function['function'][0], 'action' ),
|
||||
$priority
|
||||
);
|
||||
@ -462,7 +464,7 @@ class Tests_Actions extends WP_UnitTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertFalse( has_action( $tag ) );
|
||||
$this->assertFalse( has_action( $hook_name ) );
|
||||
}
|
||||
|
||||
|
||||
@ -477,23 +479,24 @@ class Tests_Actions extends WP_UnitTestCase {
|
||||
*/
|
||||
public function test_array_access_of_wp_filter_global() {
|
||||
global $wp_filter;
|
||||
$tag = __FUNCTION__;
|
||||
|
||||
add_action( $tag, '__return_null', 11, 1 );
|
||||
$hook_name = __FUNCTION__;
|
||||
|
||||
$this->assertArrayHasKey( 11, $wp_filter[ $tag ] );
|
||||
$this->assertArrayHasKey( '__return_null', $wp_filter[ $tag ][11] );
|
||||
add_action( $hook_name, '__return_null', 11, 1 );
|
||||
|
||||
unset( $wp_filter[ $tag ][11] );
|
||||
$this->assertFalse( has_action( $tag, '__return_null' ) );
|
||||
$this->assertArrayHasKey( 11, $wp_filter[ $hook_name ] );
|
||||
$this->assertArrayHasKey( '__return_null', $wp_filter[ $hook_name ][11] );
|
||||
|
||||
$wp_filter[ $tag ][11] = array(
|
||||
unset( $wp_filter[ $hook_name ][11] );
|
||||
$this->assertFalse( has_action( $hook_name, '__return_null' ) );
|
||||
|
||||
$wp_filter[ $hook_name ][11] = array(
|
||||
'__return_null' => array(
|
||||
'function' => '__return_null',
|
||||
'accepted_args' => 1,
|
||||
),
|
||||
);
|
||||
$this->assertSame( 11, has_action( $tag, '__return_null' ) );
|
||||
$this->assertSame( 11, has_action( $hook_name, '__return_null' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -505,6 +508,7 @@ class Tests_Actions extends WP_UnitTestCase {
|
||||
*/
|
||||
public function test_current_action() {
|
||||
global $wp_current_filter;
|
||||
|
||||
$wp_current_filter[] = 'first';
|
||||
$wp_current_filter[] = 'second'; // Let's say a second action was invoked.
|
||||
|
||||
@ -518,6 +522,7 @@ class Tests_Actions extends WP_UnitTestCase {
|
||||
*/
|
||||
public function test_doing_filter() {
|
||||
global $wp_current_filter;
|
||||
|
||||
$wp_current_filter = array(); // Set to an empty array first.
|
||||
|
||||
$this->assertFalse( doing_filter() ); // No filter is passed in, and no filter is being processed.
|
||||
@ -539,6 +544,7 @@ class Tests_Actions extends WP_UnitTestCase {
|
||||
*/
|
||||
public function test_doing_action() {
|
||||
global $wp_current_filter;
|
||||
|
||||
$wp_current_filter = array(); // Set to an empty array first.
|
||||
|
||||
$this->assertFalse( doing_action() ); // No action is passed in, and no filter is being processed.
|
||||
|
||||
@ -11,14 +11,14 @@ class Tests_Actions_Callbacks extends WP_UnitTestCase {
|
||||
* @covers ::add_action
|
||||
*/
|
||||
public function test_callback_representations() {
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
|
||||
$this->assertFalse( has_action( $tag ) );
|
||||
$this->assertFalse( has_action( $hook_name ) );
|
||||
|
||||
add_action( $tag, array( 'Class', 'method' ) );
|
||||
add_action( $hook_name, array( 'Class', 'method' ) );
|
||||
|
||||
$this->assertSame( 10, has_action( $tag, array( 'Class', 'method' ) ) );
|
||||
$this->assertSame( 10, has_action( $hook_name, array( 'Class', 'method' ) ) );
|
||||
|
||||
$this->assertSame( 10, has_action( $tag, 'Class::method' ) );
|
||||
$this->assertSame( 10, has_action( $hook_name, 'Class::method' ) );
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,32 +15,32 @@ class Tests_Actions_Closures extends WP_UnitTestCase {
|
||||
* @covers ::do_action
|
||||
*/
|
||||
public function test_action_closure() {
|
||||
$tag = 'test_action_closure';
|
||||
$closure = static function( $a, $b ) {
|
||||
$hook_name = 'test_action_closure';
|
||||
$closure = static function( $a, $b ) {
|
||||
$GLOBALS[ $a ] = $b;
|
||||
};
|
||||
add_action( $tag, $closure, 10, 2 );
|
||||
add_action( $hook_name, $closure, 10, 2 );
|
||||
|
||||
$this->assertSame( 10, has_action( $tag, $closure ) );
|
||||
$this->assertSame( 10, has_action( $hook_name, $closure ) );
|
||||
|
||||
$context = array( 'val1', 'val2' );
|
||||
do_action( $tag, $context[0], $context[1] );
|
||||
do_action( $hook_name, $context[0], $context[1] );
|
||||
|
||||
$this->assertSame( $GLOBALS[ $context[0] ], $context[1] );
|
||||
|
||||
$tag2 = 'test_action_closure_2';
|
||||
$closure2 = static function() {
|
||||
$hook_name2 = 'test_action_closure_2';
|
||||
$closure2 = static function() {
|
||||
$GLOBALS['closure_no_args'] = true;
|
||||
};
|
||||
add_action( $tag2, $closure2 );
|
||||
add_action( $hook_name2, $closure2 );
|
||||
|
||||
$this->assertSame( 10, has_action( $tag2, $closure2 ) );
|
||||
$this->assertSame( 10, has_action( $hook_name2, $closure2 ) );
|
||||
|
||||
do_action( $tag2 );
|
||||
do_action( $hook_name2 );
|
||||
|
||||
$this->assertTrue( $GLOBALS['closure_no_args'] );
|
||||
|
||||
remove_action( $tag, $closure );
|
||||
remove_action( $tag2, $closure2 );
|
||||
remove_action( $hook_name, $closure );
|
||||
remove_action( $hook_name2, $closure2 );
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,17 +8,17 @@
|
||||
class Tests_Filters extends WP_UnitTestCase {
|
||||
|
||||
public function test_simple_filter() {
|
||||
$a = new MockAction();
|
||||
$tag = __FUNCTION__;
|
||||
$val = __FUNCTION__ . '_val';
|
||||
$a = new MockAction();
|
||||
$hook_name = __FUNCTION__;
|
||||
$val = __FUNCTION__ . '_val';
|
||||
|
||||
add_filter( $tag, array( $a, 'filter' ) );
|
||||
$this->assertSame( $val, apply_filters( $tag, $val ) );
|
||||
add_filter( $hook_name, array( $a, 'filter' ) );
|
||||
$this->assertSame( $val, apply_filters( $hook_name, $val ) );
|
||||
|
||||
// Only one event occurred for the hook, with empty args.
|
||||
$this->assertSame( 1, $a->get_call_count() );
|
||||
// Only our hook was called.
|
||||
$this->assertSame( array( $tag ), $a->get_tags() );
|
||||
$this->assertSame( array( $hook_name ), $a->get_tags() );
|
||||
|
||||
$argsvar = $a->get_args();
|
||||
$args = array_pop( $argsvar );
|
||||
@ -26,53 +26,53 @@ class Tests_Filters extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_remove_filter() {
|
||||
$a = new MockAction();
|
||||
$tag = __FUNCTION__;
|
||||
$val = __FUNCTION__ . '_val';
|
||||
$a = new MockAction();
|
||||
$hook_name = __FUNCTION__;
|
||||
$val = __FUNCTION__ . '_val';
|
||||
|
||||
add_filter( $tag, array( $a, 'filter' ) );
|
||||
$this->assertSame( $val, apply_filters( $tag, $val ) );
|
||||
add_filter( $hook_name, array( $a, 'filter' ) );
|
||||
$this->assertSame( $val, apply_filters( $hook_name, $val ) );
|
||||
|
||||
// Make sure our hook was called correctly.
|
||||
$this->assertSame( 1, $a->get_call_count() );
|
||||
$this->assertSame( array( $tag ), $a->get_tags() );
|
||||
$this->assertSame( array( $hook_name ), $a->get_tags() );
|
||||
|
||||
// Now remove the filter, do it again, and make sure it's not called this time.
|
||||
remove_filter( $tag, array( $a, 'filter' ) );
|
||||
$this->assertSame( $val, apply_filters( $tag, $val ) );
|
||||
remove_filter( $hook_name, array( $a, 'filter' ) );
|
||||
$this->assertSame( $val, apply_filters( $hook_name, $val ) );
|
||||
$this->assertSame( 1, $a->get_call_count() );
|
||||
$this->assertSame( array( $tag ), $a->get_tags() );
|
||||
$this->assertSame( array( $hook_name ), $a->get_tags() );
|
||||
|
||||
}
|
||||
|
||||
public function test_has_filter() {
|
||||
$tag = __FUNCTION__;
|
||||
$func = __FUNCTION__ . '_func';
|
||||
$hook_name = __FUNCTION__;
|
||||
$callback = __FUNCTION__ . '_func';
|
||||
|
||||
$this->assertFalse( has_filter( $tag, $func ) );
|
||||
$this->assertFalse( has_filter( $tag ) );
|
||||
$this->assertFalse( has_filter( $hook_name, $callback ) );
|
||||
$this->assertFalse( has_filter( $hook_name ) );
|
||||
|
||||
add_filter( $tag, $func );
|
||||
$this->assertSame( 10, has_filter( $tag, $func ) );
|
||||
$this->assertTrue( has_filter( $tag ) );
|
||||
add_filter( $hook_name, $callback );
|
||||
$this->assertSame( 10, has_filter( $hook_name, $callback ) );
|
||||
$this->assertTrue( has_filter( $hook_name ) );
|
||||
|
||||
remove_filter( $tag, $func );
|
||||
$this->assertFalse( has_filter( $tag, $func ) );
|
||||
$this->assertFalse( has_filter( $tag ) );
|
||||
remove_filter( $hook_name, $callback );
|
||||
$this->assertFalse( has_filter( $hook_name, $callback ) );
|
||||
$this->assertFalse( has_filter( $hook_name ) );
|
||||
}
|
||||
|
||||
// One tag with multiple filters.
|
||||
public function test_multiple_filters() {
|
||||
$a1 = new MockAction();
|
||||
$a2 = new MockAction();
|
||||
$tag = __FUNCTION__;
|
||||
$val = __FUNCTION__ . '_val';
|
||||
$a1 = new MockAction();
|
||||
$a2 = new MockAction();
|
||||
$hook_name = __FUNCTION__;
|
||||
$val = __FUNCTION__ . '_val';
|
||||
|
||||
// Add both filters to the hook.
|
||||
add_filter( $tag, array( $a1, 'filter' ) );
|
||||
add_filter( $tag, array( $a2, 'filter' ) );
|
||||
add_filter( $hook_name, array( $a1, 'filter' ) );
|
||||
add_filter( $hook_name, array( $a2, 'filter' ) );
|
||||
|
||||
$this->assertSame( $val, apply_filters( $tag, $val ) );
|
||||
$this->assertSame( $val, apply_filters( $hook_name, $val ) );
|
||||
|
||||
// Both filters called once each.
|
||||
$this->assertSame( 1, $a1->get_call_count() );
|
||||
@ -80,14 +80,14 @@ class Tests_Filters extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_filter_args_1() {
|
||||
$a = new MockAction();
|
||||
$tag = __FUNCTION__;
|
||||
$val = __FUNCTION__ . '_val';
|
||||
$arg1 = __FUNCTION__ . '_arg1';
|
||||
$a = new MockAction();
|
||||
$hook_name = __FUNCTION__;
|
||||
$val = __FUNCTION__ . '_val';
|
||||
$arg1 = __FUNCTION__ . '_arg1';
|
||||
|
||||
add_filter( $tag, array( $a, 'filter' ), 10, 2 );
|
||||
add_filter( $hook_name, array( $a, 'filter' ), 10, 2 );
|
||||
// Call the filter with a single argument.
|
||||
$this->assertSame( $val, apply_filters( $tag, $val, $arg1 ) );
|
||||
$this->assertSame( $val, apply_filters( $hook_name, $val, $arg1 ) );
|
||||
|
||||
$this->assertSame( 1, $a->get_call_count() );
|
||||
$argsvar = $a->get_args();
|
||||
@ -95,18 +95,18 @@ class Tests_Filters extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_filter_args_2() {
|
||||
$a1 = new MockAction();
|
||||
$a2 = new MockAction();
|
||||
$tag = __FUNCTION__;
|
||||
$val = __FUNCTION__ . '_val';
|
||||
$arg1 = __FUNCTION__ . '_arg1';
|
||||
$arg2 = __FUNCTION__ . '_arg2';
|
||||
$a1 = new MockAction();
|
||||
$a2 = new MockAction();
|
||||
$hook_name = __FUNCTION__;
|
||||
$val = __FUNCTION__ . '_val';
|
||||
$arg1 = __FUNCTION__ . '_arg1';
|
||||
$arg2 = __FUNCTION__ . '_arg2';
|
||||
|
||||
// $a1 accepts two arguments, $a2 doesn't.
|
||||
add_filter( $tag, array( $a1, 'filter' ), 10, 3 );
|
||||
add_filter( $tag, array( $a2, 'filter' ) );
|
||||
add_filter( $hook_name, array( $a1, 'filter' ), 10, 3 );
|
||||
add_filter( $hook_name, array( $a2, 'filter' ) );
|
||||
// Call the filter with two arguments.
|
||||
$this->assertSame( $val, apply_filters( $tag, $val, $arg1, $arg2 ) );
|
||||
$this->assertSame( $val, apply_filters( $hook_name, $val, $arg1, $arg2 ) );
|
||||
|
||||
// $a1 should be called with both args.
|
||||
$this->assertSame( 1, $a1->get_call_count() );
|
||||
@ -120,14 +120,14 @@ class Tests_Filters extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_filter_priority() {
|
||||
$a = new MockAction();
|
||||
$tag = __FUNCTION__;
|
||||
$val = __FUNCTION__ . '_val';
|
||||
$a = new MockAction();
|
||||
$hook_name = __FUNCTION__;
|
||||
$val = __FUNCTION__ . '_val';
|
||||
|
||||
// Make two filters with different priorities.
|
||||
add_filter( $tag, array( $a, 'filter' ), 10 );
|
||||
add_filter( $tag, array( $a, 'filter2' ), 9 );
|
||||
$this->assertSame( $val, apply_filters( $tag, $val ) );
|
||||
add_filter( $hook_name, array( $a, 'filter' ), 10 );
|
||||
add_filter( $hook_name, array( $a, 'filter2' ), 9 );
|
||||
$this->assertSame( $val, apply_filters( $hook_name, $val ) );
|
||||
|
||||
// There should be two events, one per filter.
|
||||
$this->assertSame( 2, $a->get_call_count() );
|
||||
@ -136,13 +136,13 @@ class Tests_Filters extends WP_UnitTestCase {
|
||||
// 'filter2' is called first because it has priority 9.
|
||||
array(
|
||||
'filter' => 'filter2',
|
||||
'tag' => $tag,
|
||||
'tag' => $hook_name,
|
||||
'args' => array( $val ),
|
||||
),
|
||||
// 'filter' is called second.
|
||||
array(
|
||||
'filter' => 'filter',
|
||||
'tag' => $tag,
|
||||
'tag' => $hook_name,
|
||||
'args' => array( $val ),
|
||||
),
|
||||
);
|
||||
@ -154,45 +154,45 @@ class Tests_Filters extends WP_UnitTestCase {
|
||||
* @covers ::did_filter
|
||||
*/
|
||||
public function test_did_filter() {
|
||||
$tag1 = 'filter1';
|
||||
$tag2 = 'filter2';
|
||||
$val = __FUNCTION__ . '_val';
|
||||
$hook_name1 = 'filter1';
|
||||
$hook_name2 = 'filter2';
|
||||
$val = __FUNCTION__ . '_val';
|
||||
|
||||
// Apply filter $tag1 but not $tag2.
|
||||
apply_filters( $tag1, $val );
|
||||
$this->assertSame( 1, did_filter( $tag1 ) );
|
||||
$this->assertSame( 0, did_filter( $tag2 ) );
|
||||
// Apply filter $hook_name1 but not $hook_name2.
|
||||
apply_filters( $hook_name1, $val );
|
||||
$this->assertSame( 1, did_filter( $hook_name1 ) );
|
||||
$this->assertSame( 0, did_filter( $hook_name2 ) );
|
||||
|
||||
// Apply filter $tag2 10 times.
|
||||
// Apply filter $hook_name2 10 times.
|
||||
$count = 10;
|
||||
for ( $i = 0; $i < $count; $i++ ) {
|
||||
apply_filters( $tag2, $val );
|
||||
apply_filters( $hook_name2, $val );
|
||||
}
|
||||
|
||||
// $tag1's count hasn't changed, $tag2 should be correct.
|
||||
$this->assertSame( 1, did_filter( $tag1 ) );
|
||||
$this->assertSame( $count, did_filter( $tag2 ) );
|
||||
// $hook_name1's count hasn't changed, $hook_name2 should be correct.
|
||||
$this->assertSame( 1, did_filter( $hook_name1 ) );
|
||||
$this->assertSame( $count, did_filter( $hook_name2 ) );
|
||||
|
||||
}
|
||||
|
||||
public function test_all_filter() {
|
||||
$a = new MockAction();
|
||||
$tag1 = __FUNCTION__ . '_1';
|
||||
$tag2 = __FUNCTION__ . '_2';
|
||||
$val = __FUNCTION__ . '_val';
|
||||
$a = new MockAction();
|
||||
$hook_name1 = __FUNCTION__ . '_1';
|
||||
$hook_name2 = __FUNCTION__ . '_2';
|
||||
$val = __FUNCTION__ . '_val';
|
||||
|
||||
// Add an 'all' filter.
|
||||
add_filter( 'all', array( $a, 'filterall' ) );
|
||||
// Apply some filters.
|
||||
$this->assertSame( $val, apply_filters( $tag1, $val ) );
|
||||
$this->assertSame( $val, apply_filters( $tag2, $val ) );
|
||||
$this->assertSame( $val, apply_filters( $tag1, $val ) );
|
||||
$this->assertSame( $val, apply_filters( $tag1, $val ) );
|
||||
$this->assertSame( $val, apply_filters( $hook_name1, $val ) );
|
||||
$this->assertSame( $val, apply_filters( $hook_name2, $val ) );
|
||||
$this->assertSame( $val, apply_filters( $hook_name1, $val ) );
|
||||
$this->assertSame( $val, apply_filters( $hook_name1, $val ) );
|
||||
|
||||
// Our filter should have been called once for each apply_filters call.
|
||||
$this->assertSame( 4, $a->get_call_count() );
|
||||
// The right hooks should have been called in order.
|
||||
$this->assertSame( array( $tag1, $tag2, $tag1, $tag1 ), $a->get_tags() );
|
||||
$this->assertSame( array( $hook_name1, $hook_name2, $hook_name1, $hook_name1 ), $a->get_tags() );
|
||||
|
||||
remove_filter( 'all', array( $a, 'filterall' ) );
|
||||
$this->assertFalse( has_filter( 'all', array( $a, 'filterall' ) ) );
|
||||
@ -200,59 +200,59 @@ class Tests_Filters extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_remove_all_filter() {
|
||||
$a = new MockAction();
|
||||
$tag = __FUNCTION__;
|
||||
$val = __FUNCTION__ . '_val';
|
||||
$a = new MockAction();
|
||||
$hook_name = __FUNCTION__;
|
||||
$val = __FUNCTION__ . '_val';
|
||||
|
||||
add_filter( 'all', array( $a, 'filterall' ) );
|
||||
$this->assertTrue( has_filter( 'all' ) );
|
||||
$this->assertSame( 10, has_filter( 'all', array( $a, 'filterall' ) ) );
|
||||
$this->assertSame( $val, apply_filters( $tag, $val ) );
|
||||
$this->assertSame( $val, apply_filters( $hook_name, $val ) );
|
||||
|
||||
// Make sure our hook was called correctly.
|
||||
$this->assertSame( 1, $a->get_call_count() );
|
||||
$this->assertSame( array( $tag ), $a->get_tags() );
|
||||
$this->assertSame( array( $hook_name ), $a->get_tags() );
|
||||
|
||||
// Now remove the filter, do it again, and make sure it's not called this time.
|
||||
remove_filter( 'all', array( $a, 'filterall' ) );
|
||||
$this->assertFalse( has_filter( 'all', array( $a, 'filterall' ) ) );
|
||||
$this->assertFalse( has_filter( 'all' ) );
|
||||
$this->assertSame( $val, apply_filters( $tag, $val ) );
|
||||
$this->assertSame( $val, apply_filters( $hook_name, $val ) );
|
||||
// Call cound should remain at 1.
|
||||
$this->assertSame( 1, $a->get_call_count() );
|
||||
$this->assertSame( array( $tag ), $a->get_tags() );
|
||||
$this->assertSame( array( $hook_name ), $a->get_tags() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 20920
|
||||
*/
|
||||
public function test_remove_all_filters_should_respect_the_priority_argument() {
|
||||
$a = new MockAction();
|
||||
$tag = __FUNCTION__;
|
||||
$a = new MockAction();
|
||||
$hook_name = __FUNCTION__;
|
||||
|
||||
add_filter( $tag, array( $a, 'filter' ), 12 );
|
||||
$this->assertTrue( has_filter( $tag ) );
|
||||
add_filter( $hook_name, array( $a, 'filter' ), 12 );
|
||||
$this->assertTrue( has_filter( $hook_name ) );
|
||||
|
||||
// Should not be removed.
|
||||
remove_all_filters( $tag, 11 );
|
||||
$this->assertTrue( has_filter( $tag ) );
|
||||
remove_all_filters( $hook_name, 11 );
|
||||
$this->assertTrue( has_filter( $hook_name ) );
|
||||
|
||||
remove_all_filters( $tag, 12 );
|
||||
$this->assertFalse( has_filter( $tag ) );
|
||||
remove_all_filters( $hook_name, 12 );
|
||||
$this->assertFalse( has_filter( $hook_name ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 53218
|
||||
*/
|
||||
public function test_filter_with_ref_value() {
|
||||
$obj = new stdClass();
|
||||
$ref = &$obj;
|
||||
$a = new MockAction();
|
||||
$tag = __FUNCTION__;
|
||||
$obj = new stdClass();
|
||||
$ref = &$obj;
|
||||
$a = new MockAction();
|
||||
$hook_name = __FUNCTION__;
|
||||
|
||||
add_action( $tag, array( $a, 'filter' ) );
|
||||
add_action( $hook_name, array( $a, 'filter' ) );
|
||||
|
||||
$filtered = apply_filters( $tag, $ref );
|
||||
$filtered = apply_filters( $hook_name, $ref );
|
||||
|
||||
$args = $a->get_args();
|
||||
$this->assertSame( $args[0][0], $obj );
|
||||
@ -267,15 +267,15 @@ class Tests_Filters extends WP_UnitTestCase {
|
||||
* @ticket 53218
|
||||
*/
|
||||
public function test_filter_with_ref_argument() {
|
||||
$obj = new stdClass();
|
||||
$ref = &$obj;
|
||||
$a = new MockAction();
|
||||
$tag = __FUNCTION__;
|
||||
$val = 'Hello';
|
||||
$obj = new stdClass();
|
||||
$ref = &$obj;
|
||||
$a = new MockAction();
|
||||
$hook_name = __FUNCTION__;
|
||||
$val = 'Hello';
|
||||
|
||||
add_action( $tag, array( $a, 'filter' ), 10, 2 );
|
||||
add_action( $hook_name, array( $a, 'filter' ), 10, 2 );
|
||||
|
||||
apply_filters( $tag, $val, $ref );
|
||||
apply_filters( $hook_name, $val, $ref );
|
||||
|
||||
$args = $a->get_args();
|
||||
$this->assertSame( $args[0][1], $obj );
|
||||
@ -288,13 +288,13 @@ class Tests_Filters extends WP_UnitTestCase {
|
||||
* @ticket 9886
|
||||
*/
|
||||
public function test_filter_ref_array() {
|
||||
$obj = new stdClass();
|
||||
$a = new MockAction();
|
||||
$tag = __FUNCTION__;
|
||||
$obj = new stdClass();
|
||||
$a = new MockAction();
|
||||
$hook_name = __FUNCTION__;
|
||||
|
||||
add_action( $tag, array( $a, 'filter' ) );
|
||||
add_action( $hook_name, array( $a, 'filter' ) );
|
||||
|
||||
apply_filters_ref_array( $tag, array( &$obj ) );
|
||||
apply_filters_ref_array( $hook_name, array( &$obj ) );
|
||||
|
||||
$args = $a->get_args();
|
||||
$this->assertSame( $args[0][0], $obj );
|
||||
@ -307,15 +307,15 @@ class Tests_Filters extends WP_UnitTestCase {
|
||||
* @ticket 12723
|
||||
*/
|
||||
public function test_filter_ref_array_result() {
|
||||
$obj = new stdClass();
|
||||
$a = new MockAction();
|
||||
$b = new MockAction();
|
||||
$tag = __FUNCTION__;
|
||||
$obj = new stdClass();
|
||||
$a = new MockAction();
|
||||
$b = new MockAction();
|
||||
$hook_name = __FUNCTION__;
|
||||
|
||||
add_action( $tag, array( $a, 'filter_append' ), 10, 2 );
|
||||
add_action( $tag, array( $b, 'filter_append' ), 10, 2 );
|
||||
add_action( $hook_name, array( $a, 'filter_append' ), 10, 2 );
|
||||
add_action( $hook_name, array( $b, 'filter_append' ), 10, 2 );
|
||||
|
||||
$result = apply_filters_ref_array( $tag, array( 'string', &$obj ) );
|
||||
$result = apply_filters_ref_array( $hook_name, array( 'string', &$obj ) );
|
||||
|
||||
$this->assertSame( $result, 'string_append_append' );
|
||||
|
||||
@ -337,25 +337,25 @@ class Tests_Filters extends WP_UnitTestCase {
|
||||
* @ticket 29070
|
||||
*/
|
||||
public function test_has_filter_after_remove_all_filters() {
|
||||
$a = new MockAction();
|
||||
$tag = __FUNCTION__;
|
||||
$a = new MockAction();
|
||||
$hook_name = __FUNCTION__;
|
||||
|
||||
// No priority.
|
||||
add_filter( $tag, array( $a, 'filter' ), 11 );
|
||||
add_filter( $tag, array( $a, 'filter' ), 12 );
|
||||
$this->assertTrue( has_filter( $tag ) );
|
||||
add_filter( $hook_name, array( $a, 'filter' ), 11 );
|
||||
add_filter( $hook_name, array( $a, 'filter' ), 12 );
|
||||
$this->assertTrue( has_filter( $hook_name ) );
|
||||
|
||||
remove_all_filters( $tag );
|
||||
$this->assertFalse( has_filter( $tag ) );
|
||||
remove_all_filters( $hook_name );
|
||||
$this->assertFalse( has_filter( $hook_name ) );
|
||||
|
||||
// Remove priorities one at a time.
|
||||
add_filter( $tag, array( $a, 'filter' ), 11 );
|
||||
add_filter( $tag, array( $a, 'filter' ), 12 );
|
||||
$this->assertTrue( has_filter( $tag ) );
|
||||
add_filter( $hook_name, array( $a, 'filter' ), 11 );
|
||||
add_filter( $hook_name, array( $a, 'filter' ), 12 );
|
||||
$this->assertTrue( has_filter( $hook_name ) );
|
||||
|
||||
remove_all_filters( $tag, 11 );
|
||||
remove_all_filters( $tag, 12 );
|
||||
$this->assertFalse( has_filter( $tag ) );
|
||||
remove_all_filters( $hook_name, 11 );
|
||||
remove_all_filters( $hook_name, 12 );
|
||||
$this->assertFalse( has_filter( $hook_name ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -412,6 +412,7 @@ class Tests_Filters extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
private $current_priority;
|
||||
|
||||
/**
|
||||
* @ticket 39007
|
||||
*/
|
||||
@ -425,6 +426,7 @@ class Tests_Filters extends WP_UnitTestCase {
|
||||
|
||||
public function current_priority_action() {
|
||||
global $wp_filter;
|
||||
|
||||
$this->current_priority = $wp_filter[ current_filter() ]->current_priority();
|
||||
}
|
||||
|
||||
|
||||
@ -14,13 +14,13 @@ class Tests_Hooks_AddFilter extends WP_UnitTestCase {
|
||||
public function test_add_filter_with_function() {
|
||||
$callback = '__return_null';
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
|
||||
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
|
||||
|
||||
$function_index = _wp_filter_build_unique_id( $tag, $callback, $priority );
|
||||
$function_index = _wp_filter_build_unique_id( $hook_name, $callback, $priority );
|
||||
$this->assertSame( $callback, $hook->callbacks[ $priority ][ $function_index ]['function'] );
|
||||
$this->assertSame( $accepted_args, $hook->callbacks[ $priority ][ $function_index ]['accepted_args'] );
|
||||
}
|
||||
@ -29,13 +29,13 @@ class Tests_Hooks_AddFilter extends WP_UnitTestCase {
|
||||
$a = new MockAction();
|
||||
$callback = array( $a, 'action' );
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
|
||||
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
|
||||
|
||||
$function_index = _wp_filter_build_unique_id( $tag, $callback, $priority );
|
||||
$function_index = _wp_filter_build_unique_id( $hook_name, $callback, $priority );
|
||||
$this->assertSame( $callback, $hook->callbacks[ $priority ][ $function_index ]['function'] );
|
||||
$this->assertSame( $accepted_args, $hook->callbacks[ $priority ][ $function_index ]['accepted_args'] );
|
||||
}
|
||||
@ -43,13 +43,13 @@ class Tests_Hooks_AddFilter extends WP_UnitTestCase {
|
||||
public function test_add_filter_with_static_method() {
|
||||
$callback = array( 'MockAction', 'action' );
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
|
||||
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
|
||||
|
||||
$function_index = _wp_filter_build_unique_id( $tag, $callback, $priority );
|
||||
$function_index = _wp_filter_build_unique_id( $hook_name, $callback, $priority );
|
||||
$this->assertSame( $callback, $hook->callbacks[ $priority ][ $function_index ]['function'] );
|
||||
$this->assertSame( $accepted_args, $hook->callbacks[ $priority ][ $function_index ]['accepted_args'] );
|
||||
}
|
||||
@ -58,14 +58,14 @@ class Tests_Hooks_AddFilter extends WP_UnitTestCase {
|
||||
$callback_one = '__return_null';
|
||||
$callback_two = '__return_false';
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
|
||||
$hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback_one, $priority, $accepted_args );
|
||||
$this->assertCount( 1, $hook->callbacks[ $priority ] );
|
||||
|
||||
$hook->add_filter( $tag, $callback_two, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback_two, $priority, $accepted_args );
|
||||
$this->assertCount( 2, $hook->callbacks[ $priority ] );
|
||||
}
|
||||
|
||||
@ -73,14 +73,14 @@ class Tests_Hooks_AddFilter extends WP_UnitTestCase {
|
||||
$callback_one = '__return_null';
|
||||
$callback_two = '__return_false';
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
|
||||
$hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback_one, $priority, $accepted_args );
|
||||
$this->assertCount( 1, $hook->callbacks[ $priority ] );
|
||||
|
||||
$hook->add_filter( $tag, $callback_two, $priority + 1, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback_two, $priority + 1, $accepted_args );
|
||||
$this->assertCount( 1, $hook->callbacks[ $priority ] );
|
||||
$this->assertCount( 1, $hook->callbacks[ $priority + 1 ] );
|
||||
}
|
||||
@ -88,48 +88,48 @@ class Tests_Hooks_AddFilter extends WP_UnitTestCase {
|
||||
public function test_readd_filter() {
|
||||
$callback = '__return_null';
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
|
||||
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
|
||||
$this->assertCount( 1, $hook->callbacks[ $priority ] );
|
||||
|
||||
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
|
||||
$this->assertCount( 1, $hook->callbacks[ $priority ] );
|
||||
}
|
||||
|
||||
public function test_readd_filter_with_different_priority() {
|
||||
$callback = '__return_null';
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
|
||||
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
|
||||
$this->assertCount( 1, $hook->callbacks[ $priority ] );
|
||||
|
||||
$hook->add_filter( $tag, $callback, $priority + 1, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback, $priority + 1, $accepted_args );
|
||||
$this->assertCount( 1, $hook->callbacks[ $priority ] );
|
||||
$this->assertCount( 1, $hook->callbacks[ $priority + 1 ] );
|
||||
}
|
||||
|
||||
public function test_sort_after_add_filter() {
|
||||
$a = new MockAction();
|
||||
$b = new MockAction();
|
||||
$c = new MockAction();
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$a = new MockAction();
|
||||
$b = new MockAction();
|
||||
$c = new MockAction();
|
||||
$hook = new WP_Hook();
|
||||
$hook_name = __FUNCTION__;
|
||||
|
||||
$hook->add_filter( $tag, array( $a, 'action' ), 10, 1 );
|
||||
$hook->add_filter( $tag, array( $b, 'action' ), 5, 1 );
|
||||
$hook->add_filter( $tag, array( $c, 'action' ), 8, 1 );
|
||||
$hook->add_filter( $hook_name, array( $a, 'action' ), 10, 1 );
|
||||
$hook->add_filter( $hook_name, array( $b, 'action' ), 5, 1 );
|
||||
$hook->add_filter( $hook_name, array( $c, 'action' ), 8, 1 );
|
||||
|
||||
$this->assertSame( array( 5, 8, 10 ), array_keys( $hook->callbacks ) );
|
||||
}
|
||||
|
||||
public function test_remove_and_add() {
|
||||
$this->hook = new Wp_Hook();
|
||||
$this->hook = new WP_Hook();
|
||||
|
||||
$this->hook->add_filter( 'remove_and_add', '__return_empty_string', 10, 0 );
|
||||
|
||||
@ -143,7 +143,7 @@ class Tests_Hooks_AddFilter extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_remove_and_add_last_filter() {
|
||||
$this->hook = new Wp_Hook();
|
||||
$this->hook = new WP_Hook();
|
||||
|
||||
$this->hook->add_filter( 'remove_and_add', '__return_empty_string', 10, 0 );
|
||||
|
||||
@ -157,7 +157,7 @@ class Tests_Hooks_AddFilter extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_remove_and_recurse_and_add() {
|
||||
$this->hook = new Wp_Hook();
|
||||
$this->hook = new WP_Hook();
|
||||
|
||||
$this->hook->add_filter( 'remove_and_add', '__return_empty_string', 10, 0 );
|
||||
|
||||
@ -202,7 +202,7 @@ class Tests_Hooks_AddFilter extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_remove_and_add_action() {
|
||||
$this->hook = new Wp_Hook();
|
||||
$this->hook = new WP_Hook();
|
||||
$this->action_output = '';
|
||||
|
||||
$this->hook->add_filter( 'remove_and_add_action', '__return_empty_string', 10, 0 );
|
||||
@ -217,7 +217,7 @@ class Tests_Hooks_AddFilter extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_remove_and_add_last_action() {
|
||||
$this->hook = new Wp_Hook();
|
||||
$this->hook = new WP_Hook();
|
||||
$this->action_output = '';
|
||||
|
||||
$this->hook->add_filter( 'remove_and_add_action', '__return_empty_string', 10, 0 );
|
||||
@ -232,7 +232,7 @@ class Tests_Hooks_AddFilter extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_remove_and_recurse_and_add_action() {
|
||||
$this->hook = new Wp_Hook();
|
||||
$this->hook = new WP_Hook();
|
||||
$this->action_output = '';
|
||||
|
||||
$this->hook->add_filter( 'remove_and_add_action', '__return_empty_string', 10, 0 );
|
||||
|
||||
@ -12,12 +12,12 @@ class Tests_Hooks_ApplyFilters extends WP_UnitTestCase {
|
||||
$a = new MockAction();
|
||||
$callback = array( $a, 'filter' );
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
$arg = __FUNCTION__ . '_arg';
|
||||
|
||||
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
|
||||
|
||||
$returned = $hook->apply_filters( $arg, array( $arg ) );
|
||||
|
||||
@ -29,12 +29,12 @@ class Tests_Hooks_ApplyFilters extends WP_UnitTestCase {
|
||||
$a = new MockAction();
|
||||
$callback = array( $a, 'filter' );
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
$arg = __FUNCTION__ . '_arg';
|
||||
|
||||
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
|
||||
|
||||
$returned_one = $hook->apply_filters( $arg, array( $arg ) );
|
||||
$returned_two = $hook->apply_filters( $returned_one, array( $returned_one ) );
|
||||
|
||||
@ -20,12 +20,12 @@ class Tests_Hooks_DoAction extends WP_UnitTestCase {
|
||||
$a = new MockAction();
|
||||
$callback = array( $a, 'action' );
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
$arg = __FUNCTION__ . '_arg';
|
||||
|
||||
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
|
||||
$hook->do_action( array( $arg ) );
|
||||
|
||||
$this->assertSame( 1, $a->get_call_count() );
|
||||
@ -35,12 +35,12 @@ class Tests_Hooks_DoAction extends WP_UnitTestCase {
|
||||
$a = new MockAction();
|
||||
$callback = array( $a, 'filter' );
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
$arg = __FUNCTION__ . '_arg';
|
||||
|
||||
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
|
||||
$hook->do_action( array( $arg ) );
|
||||
$hook->do_action( array( $arg ) );
|
||||
|
||||
@ -53,13 +53,13 @@ class Tests_Hooks_DoAction extends WP_UnitTestCase {
|
||||
$callback_one = array( $a, 'filter' );
|
||||
$callback_two = array( $b, 'filter' );
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
$arg = __FUNCTION__ . '_arg';
|
||||
|
||||
$hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
|
||||
$hook->add_filter( $tag, $callback_two, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback_one, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback_two, $priority, $accepted_args );
|
||||
$hook->do_action( array( $arg ) );
|
||||
|
||||
$this->assertSame( 1, $a->get_call_count() );
|
||||
@ -72,13 +72,13 @@ class Tests_Hooks_DoAction extends WP_UnitTestCase {
|
||||
$callback_one = array( $a, 'filter' );
|
||||
$callback_two = array( $b, 'filter' );
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
$arg = __FUNCTION__ . '_arg';
|
||||
|
||||
$hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
|
||||
$hook->add_filter( $tag, $callback_two, $priority + 1, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback_one, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback_two, $priority + 1, $accepted_args );
|
||||
$hook->do_action( array( $arg ) );
|
||||
|
||||
$this->assertSame( 1, $a->get_call_count() );
|
||||
@ -88,12 +88,12 @@ class Tests_Hooks_DoAction extends WP_UnitTestCase {
|
||||
public function test_do_action_with_no_accepted_args() {
|
||||
$callback = array( $this, '_action_callback' );
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 0;
|
||||
$arg = __FUNCTION__ . '_arg';
|
||||
|
||||
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
|
||||
$hook->do_action( array( $arg ) );
|
||||
|
||||
$this->assertEmpty( $this->events[0]['args'] );
|
||||
@ -102,12 +102,12 @@ class Tests_Hooks_DoAction extends WP_UnitTestCase {
|
||||
public function test_do_action_with_one_accepted_arg() {
|
||||
$callback = array( $this, '_action_callback' );
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 1;
|
||||
$arg = __FUNCTION__ . '_arg';
|
||||
|
||||
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
|
||||
$hook->do_action( array( $arg ) );
|
||||
|
||||
$this->assertCount( 1, $this->events[0]['args'] );
|
||||
@ -116,12 +116,12 @@ class Tests_Hooks_DoAction extends WP_UnitTestCase {
|
||||
public function test_do_action_with_more_accepted_args() {
|
||||
$callback = array( $this, '_action_callback' );
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 100;
|
||||
$accepted_args = 1000;
|
||||
$arg = __FUNCTION__ . '_arg';
|
||||
|
||||
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
|
||||
$hook->do_action( array( $arg ) );
|
||||
|
||||
$this->assertCount( 1, $this->events[0]['args'] );
|
||||
|
||||
@ -12,12 +12,12 @@ class Tests_Hooks_DoAllHook extends WP_UnitTestCase {
|
||||
$a = new MockAction();
|
||||
$callback = array( $a, 'action' );
|
||||
$hook = new WP_Hook();
|
||||
$tag = 'all';
|
||||
$hook_name = 'all';
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
$arg = 'all_arg';
|
||||
|
||||
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
|
||||
$args = array( $arg );
|
||||
$hook->do_all_hook( $args );
|
||||
$hook->do_all_hook( $args );
|
||||
|
||||
@ -11,48 +11,48 @@ class Tests_Hooks_HasFilter extends WP_UnitTestCase {
|
||||
public function test_has_filter_with_function() {
|
||||
$callback = '__return_null';
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
|
||||
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
|
||||
|
||||
$this->assertSame( $priority, $hook->has_filter( $tag, $callback ) );
|
||||
$this->assertSame( $priority, $hook->has_filter( $hook_name, $callback ) );
|
||||
}
|
||||
|
||||
public function test_has_filter_with_object() {
|
||||
$a = new MockAction();
|
||||
$callback = array( $a, 'action' );
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
|
||||
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
|
||||
|
||||
$this->assertSame( $priority, $hook->has_filter( $tag, $callback ) );
|
||||
$this->assertSame( $priority, $hook->has_filter( $hook_name, $callback ) );
|
||||
}
|
||||
|
||||
public function test_has_filter_with_static_method() {
|
||||
$callback = array( 'MockAction', 'action' );
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
|
||||
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
|
||||
|
||||
$this->assertSame( $priority, $hook->has_filter( $tag, $callback ) );
|
||||
$this->assertSame( $priority, $hook->has_filter( $hook_name, $callback ) );
|
||||
}
|
||||
|
||||
public function test_has_filter_without_callback() {
|
||||
$callback = '__return_null';
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
|
||||
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
|
||||
|
||||
$this->assertTrue( $hook->has_filter() );
|
||||
}
|
||||
@ -63,22 +63,22 @@ class Tests_Hooks_HasFilter extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_not_has_filter_with_callback() {
|
||||
$callback = '__return_null';
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$callback = '__return_null';
|
||||
$hook = new WP_Hook();
|
||||
$hook_name = __FUNCTION__;
|
||||
|
||||
$this->assertFalse( $hook->has_filter( $tag, $callback ) );
|
||||
$this->assertFalse( $hook->has_filter( $hook_name, $callback ) );
|
||||
}
|
||||
|
||||
public function test_has_filter_with_wrong_callback() {
|
||||
$callback = '__return_null';
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
|
||||
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
|
||||
|
||||
$this->assertFalse( $hook->has_filter( $tag, '__return_false' ) );
|
||||
$this->assertFalse( $hook->has_filter( $hook_name, '__return_false' ) );
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,11 +11,11 @@ class Tests_Hooks_HasFilters extends WP_UnitTestCase {
|
||||
public function test_has_filters_with_callback() {
|
||||
$callback = '__return_null';
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
|
||||
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
|
||||
|
||||
$this->assertTrue( $hook->has_filters() );
|
||||
}
|
||||
@ -28,24 +28,24 @@ class Tests_Hooks_HasFilters extends WP_UnitTestCase {
|
||||
public function test_not_has_filters_with_removed_callback() {
|
||||
$callback = '__return_null';
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
|
||||
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
|
||||
$hook->remove_filter( $tag, $callback, $priority );
|
||||
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
|
||||
$hook->remove_filter( $hook_name, $callback, $priority );
|
||||
$this->assertFalse( $hook->has_filters() );
|
||||
}
|
||||
|
||||
public function test_not_has_filter_with_directly_removed_callback() {
|
||||
$callback = '__return_null';
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
|
||||
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
|
||||
$function_key = _wp_filter_build_unique_id( $tag, $callback, $priority );
|
||||
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
|
||||
$function_key = _wp_filter_build_unique_id( $hook_name, $callback, $priority );
|
||||
unset( $hook->callbacks[ $priority ][ $function_key ] );
|
||||
|
||||
$this->assertFalse( $hook->has_filters() );
|
||||
|
||||
@ -12,12 +12,12 @@ class Tests_Hooks_Iterator extends WP_UnitTestCase {
|
||||
$callback_one = '__return_null';
|
||||
$callback_two = '__return_false';
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
|
||||
$hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
|
||||
$hook->add_filter( $tag, $callback_two, $priority + 1, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback_one, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback_two, $priority + 1, $accepted_args );
|
||||
|
||||
$functions = array();
|
||||
$priorities = array();
|
||||
|
||||
@ -9,12 +9,12 @@
|
||||
class Tests_Hooks_PreinitHooks extends WP_UnitTestCase {
|
||||
|
||||
public function test_array_to_hooks() {
|
||||
$tag1 = __FUNCTION__ . '_1';
|
||||
$priority1 = 1;
|
||||
$tag2 = __FUNCTION__ . '_2';
|
||||
$priority2 = 2;
|
||||
$filters = array(
|
||||
$tag1 => array(
|
||||
$hook_name1 = __FUNCTION__ . '_1';
|
||||
$priority1 = 1;
|
||||
$hook_name2 = __FUNCTION__ . '_2';
|
||||
$priority2 = 2;
|
||||
$filters = array(
|
||||
$hook_name1 => array(
|
||||
$priority1 => array(
|
||||
'test1' => array(
|
||||
'function' => '__return_false',
|
||||
@ -22,7 +22,7 @@ class Tests_Hooks_PreinitHooks extends WP_UnitTestCase {
|
||||
),
|
||||
),
|
||||
),
|
||||
$tag2 => array(
|
||||
$hook_name2 => array(
|
||||
$priority2 => array(
|
||||
'test1' => array(
|
||||
'function' => '__return_null',
|
||||
@ -34,7 +34,7 @@ class Tests_Hooks_PreinitHooks extends WP_UnitTestCase {
|
||||
|
||||
$hooks = WP_Hook::build_preinitialized_hooks( $filters );
|
||||
|
||||
$this->assertSame( $priority1, $hooks[ $tag1 ]->has_filter( $tag1, '__return_false' ) );
|
||||
$this->assertSame( $priority2, $hooks[ $tag2 ]->has_filter( $tag2, '__return_null' ) );
|
||||
$this->assertSame( $priority1, $hooks[ $hook_name1 ]->has_filter( $hook_name1, '__return_false' ) );
|
||||
$this->assertSame( $priority2, $hooks[ $hook_name2 ]->has_filter( $hook_name2, '__return_null' ) );
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,11 +11,11 @@ class Tests_Hooks_RemoveAllFilters extends WP_UnitTestCase {
|
||||
public function test_remove_all_filters() {
|
||||
$callback = '__return_null';
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
|
||||
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
|
||||
|
||||
$hook->remove_all_filters();
|
||||
|
||||
@ -26,17 +26,17 @@ class Tests_Hooks_RemoveAllFilters extends WP_UnitTestCase {
|
||||
$callback_one = '__return_null';
|
||||
$callback_two = '__return_false';
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
|
||||
$hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
|
||||
$hook->add_filter( $tag, $callback_two, $priority + 1, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback_one, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback_two, $priority + 1, $accepted_args );
|
||||
|
||||
$hook->remove_all_filters( $priority );
|
||||
|
||||
$this->assertFalse( $hook->has_filter( $tag, $callback_one ) );
|
||||
$this->assertFalse( $hook->has_filter( $hook_name, $callback_one ) );
|
||||
$this->assertTrue( $hook->has_filters() );
|
||||
$this->assertSame( $priority + 1, $hook->has_filter( $tag, $callback_two ) );
|
||||
$this->assertSame( $priority + 1, $hook->has_filter( $hook_name, $callback_two ) );
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,12 +11,12 @@ class Tests_Hooks_RemoveFilter extends WP_UnitTestCase {
|
||||
public function test_remove_filter_with_function() {
|
||||
$callback = '__return_null';
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
|
||||
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
|
||||
$hook->remove_filter( $tag, $callback, $priority );
|
||||
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
|
||||
$hook->remove_filter( $hook_name, $callback, $priority );
|
||||
|
||||
$this->assertArrayNotHasKey( $priority, $hook->callbacks );
|
||||
}
|
||||
@ -25,12 +25,12 @@ class Tests_Hooks_RemoveFilter extends WP_UnitTestCase {
|
||||
$a = new MockAction();
|
||||
$callback = array( $a, 'action' );
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
|
||||
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
|
||||
$hook->remove_filter( $tag, $callback, $priority );
|
||||
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
|
||||
$hook->remove_filter( $hook_name, $callback, $priority );
|
||||
|
||||
$this->assertArrayNotHasKey( $priority, $hook->callbacks );
|
||||
}
|
||||
@ -38,12 +38,12 @@ class Tests_Hooks_RemoveFilter extends WP_UnitTestCase {
|
||||
public function test_remove_filter_with_static_method() {
|
||||
$callback = array( 'MockAction', 'action' );
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
|
||||
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
|
||||
$hook->remove_filter( $tag, $callback, $priority );
|
||||
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
|
||||
$hook->remove_filter( $hook_name, $callback, $priority );
|
||||
|
||||
$this->assertArrayNotHasKey( $priority, $hook->callbacks );
|
||||
}
|
||||
@ -52,14 +52,14 @@ class Tests_Hooks_RemoveFilter extends WP_UnitTestCase {
|
||||
$callback_one = '__return_null';
|
||||
$callback_two = '__return_false';
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
|
||||
$hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
|
||||
$hook->add_filter( $tag, $callback_two, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback_one, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback_two, $priority, $accepted_args );
|
||||
|
||||
$hook->remove_filter( $tag, $callback_one, $priority );
|
||||
$hook->remove_filter( $hook_name, $callback_one, $priority );
|
||||
|
||||
$this->assertCount( 1, $hook->callbacks[ $priority ] );
|
||||
}
|
||||
@ -68,14 +68,14 @@ class Tests_Hooks_RemoveFilter extends WP_UnitTestCase {
|
||||
$callback_one = '__return_null';
|
||||
$callback_two = '__return_false';
|
||||
$hook = new WP_Hook();
|
||||
$tag = __FUNCTION__;
|
||||
$hook_name = __FUNCTION__;
|
||||
$priority = 1;
|
||||
$accepted_args = 2;
|
||||
|
||||
$hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
|
||||
$hook->add_filter( $tag, $callback_two, $priority + 1, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback_one, $priority, $accepted_args );
|
||||
$hook->add_filter( $hook_name, $callback_two, $priority + 1, $accepted_args );
|
||||
|
||||
$hook->remove_filter( $tag, $callback_one, $priority );
|
||||
$hook->remove_filter( $hook_name, $callback_one, $priority );
|
||||
$this->assertArrayNotHasKey( $priority, $hook->callbacks );
|
||||
$this->assertCount( 1, $hook->callbacks[ $priority + 1 ] );
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user