Changeset 53804 for trunk/tests/phpunit/tests/hooks/addFilter.php
- Timestamp:
- 07/31/2022 03:03:46 PM (4 years ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/hooks/addFilter.php (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/hooks/addFilter.php
r52389 r53804 15 15 $callback = '__return_null'; 16 16 $hook = new WP_Hook(); 17 $ tag= __FUNCTION__;18 $priority = 1; 19 $accepted_args = 2; 20 21 $hook->add_filter( $ tag, $callback, $priority, $accepted_args );22 23 $function_index = _wp_filter_build_unique_id( $ tag, $callback, $priority );17 $hook_name = __FUNCTION__; 18 $priority = 1; 19 $accepted_args = 2; 20 21 $hook->add_filter( $hook_name, $callback, $priority, $accepted_args ); 22 23 $function_index = _wp_filter_build_unique_id( $hook_name, $callback, $priority ); 24 24 $this->assertSame( $callback, $hook->callbacks[ $priority ][ $function_index ]['function'] ); 25 25 $this->assertSame( $accepted_args, $hook->callbacks[ $priority ][ $function_index ]['accepted_args'] ); … … 30 30 $callback = array( $a, 'action' ); 31 31 $hook = new WP_Hook(); 32 $ tag= __FUNCTION__;33 $priority = 1; 34 $accepted_args = 2; 35 36 $hook->add_filter( $ tag, $callback, $priority, $accepted_args );37 38 $function_index = _wp_filter_build_unique_id( $ tag, $callback, $priority );32 $hook_name = __FUNCTION__; 33 $priority = 1; 34 $accepted_args = 2; 35 36 $hook->add_filter( $hook_name, $callback, $priority, $accepted_args ); 37 38 $function_index = _wp_filter_build_unique_id( $hook_name, $callback, $priority ); 39 39 $this->assertSame( $callback, $hook->callbacks[ $priority ][ $function_index ]['function'] ); 40 40 $this->assertSame( $accepted_args, $hook->callbacks[ $priority ][ $function_index ]['accepted_args'] ); … … 44 44 $callback = array( 'MockAction', 'action' ); 45 45 $hook = new WP_Hook(); 46 $ tag= __FUNCTION__;47 $priority = 1; 48 $accepted_args = 2; 49 50 $hook->add_filter( $ tag, $callback, $priority, $accepted_args );51 52 $function_index = _wp_filter_build_unique_id( $ tag, $callback, $priority );46 $hook_name = __FUNCTION__; 47 $priority = 1; 48 $accepted_args = 2; 49 50 $hook->add_filter( $hook_name, $callback, $priority, $accepted_args ); 51 52 $function_index = _wp_filter_build_unique_id( $hook_name, $callback, $priority ); 53 53 $this->assertSame( $callback, $hook->callbacks[ $priority ][ $function_index ]['function'] ); 54 54 $this->assertSame( $accepted_args, $hook->callbacks[ $priority ][ $function_index ]['accepted_args'] ); … … 59 59 $callback_two = '__return_false'; 60 60 $hook = new WP_Hook(); 61 $ tag= __FUNCTION__;62 $priority = 1; 63 $accepted_args = 2; 64 65 $hook->add_filter( $ tag, $callback_one, $priority, $accepted_args );66 $this->assertCount( 1, $hook->callbacks[ $priority ] ); 67 68 $hook->add_filter( $ tag, $callback_two, $priority, $accepted_args );61 $hook_name = __FUNCTION__; 62 $priority = 1; 63 $accepted_args = 2; 64 65 $hook->add_filter( $hook_name, $callback_one, $priority, $accepted_args ); 66 $this->assertCount( 1, $hook->callbacks[ $priority ] ); 67 68 $hook->add_filter( $hook_name, $callback_two, $priority, $accepted_args ); 69 69 $this->assertCount( 2, $hook->callbacks[ $priority ] ); 70 70 } … … 74 74 $callback_two = '__return_false'; 75 75 $hook = new WP_Hook(); 76 $ tag= __FUNCTION__;77 $priority = 1; 78 $accepted_args = 2; 79 80 $hook->add_filter( $ tag, $callback_one, $priority, $accepted_args );81 $this->assertCount( 1, $hook->callbacks[ $priority ] ); 82 83 $hook->add_filter( $ tag, $callback_two, $priority + 1, $accepted_args );76 $hook_name = __FUNCTION__; 77 $priority = 1; 78 $accepted_args = 2; 79 80 $hook->add_filter( $hook_name, $callback_one, $priority, $accepted_args ); 81 $this->assertCount( 1, $hook->callbacks[ $priority ] ); 82 83 $hook->add_filter( $hook_name, $callback_two, $priority + 1, $accepted_args ); 84 84 $this->assertCount( 1, $hook->callbacks[ $priority ] ); 85 85 $this->assertCount( 1, $hook->callbacks[ $priority + 1 ] ); … … 89 89 $callback = '__return_null'; 90 90 $hook = new WP_Hook(); 91 $ tag= __FUNCTION__;92 $priority = 1; 93 $accepted_args = 2; 94 95 $hook->add_filter( $ tag, $callback, $priority, $accepted_args );96 $this->assertCount( 1, $hook->callbacks[ $priority ] ); 97 98 $hook->add_filter( $ tag, $callback, $priority, $accepted_args );91 $hook_name = __FUNCTION__; 92 $priority = 1; 93 $accepted_args = 2; 94 95 $hook->add_filter( $hook_name, $callback, $priority, $accepted_args ); 96 $this->assertCount( 1, $hook->callbacks[ $priority ] ); 97 98 $hook->add_filter( $hook_name, $callback, $priority, $accepted_args ); 99 99 $this->assertCount( 1, $hook->callbacks[ $priority ] ); 100 100 } … … 103 103 $callback = '__return_null'; 104 104 $hook = new WP_Hook(); 105 $ tag= __FUNCTION__;106 $priority = 1; 107 $accepted_args = 2; 108 109 $hook->add_filter( $ tag, $callback, $priority, $accepted_args );110 $this->assertCount( 1, $hook->callbacks[ $priority ] ); 111 112 $hook->add_filter( $ tag, $callback, $priority + 1, $accepted_args );105 $hook_name = __FUNCTION__; 106 $priority = 1; 107 $accepted_args = 2; 108 109 $hook->add_filter( $hook_name, $callback, $priority, $accepted_args ); 110 $this->assertCount( 1, $hook->callbacks[ $priority ] ); 111 112 $hook->add_filter( $hook_name, $callback, $priority + 1, $accepted_args ); 113 113 $this->assertCount( 1, $hook->callbacks[ $priority ] ); 114 114 $this->assertCount( 1, $hook->callbacks[ $priority + 1 ] ); … … 116 116 117 117 public function test_sort_after_add_filter() { 118 $a = new MockAction();119 $b = new MockAction();120 $c = new MockAction();121 $hook = new WP_Hook();122 $ tag= __FUNCTION__;123 124 $hook->add_filter( $ tag, array( $a, 'action' ), 10, 1 );125 $hook->add_filter( $ tag, array( $b, 'action' ), 5, 1 );126 $hook->add_filter( $ tag, array( $c, 'action' ), 8, 1 );118 $a = new MockAction(); 119 $b = new MockAction(); 120 $c = new MockAction(); 121 $hook = new WP_Hook(); 122 $hook_name = __FUNCTION__; 123 124 $hook->add_filter( $hook_name, array( $a, 'action' ), 10, 1 ); 125 $hook->add_filter( $hook_name, array( $b, 'action' ), 5, 1 ); 126 $hook->add_filter( $hook_name, array( $c, 'action' ), 8, 1 ); 127 127 128 128 $this->assertSame( array( 5, 8, 10 ), array_keys( $hook->callbacks ) ); … … 130 130 131 131 public function test_remove_and_add() { 132 $this->hook = new W p_Hook();132 $this->hook = new WP_Hook(); 133 133 134 134 $this->hook->add_filter( 'remove_and_add', '__return_empty_string', 10, 0 ); … … 144 144 145 145 public function test_remove_and_add_last_filter() { 146 $this->hook = new W p_Hook();146 $this->hook = new WP_Hook(); 147 147 148 148 $this->hook->add_filter( 'remove_and_add', '__return_empty_string', 10, 0 ); … … 158 158 159 159 public function test_remove_and_recurse_and_add() { 160 $this->hook = new W p_Hook();160 $this->hook = new WP_Hook(); 161 161 162 162 $this->hook->add_filter( 'remove_and_add', '__return_empty_string', 10, 0 ); … … 203 203 204 204 public function test_remove_and_add_action() { 205 $this->hook = new W p_Hook();205 $this->hook = new WP_Hook(); 206 206 $this->action_output = ''; 207 207 … … 218 218 219 219 public function test_remove_and_add_last_action() { 220 $this->hook = new W p_Hook();220 $this->hook = new WP_Hook(); 221 221 $this->action_output = ''; 222 222 … … 233 233 234 234 public function test_remove_and_recurse_and_add_action() { 235 $this->hook = new W p_Hook();235 $this->hook = new WP_Hook(); 236 236 $this->action_output = ''; 237 237
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)