mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +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:
@@ -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 ] );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user