Changeset 56609 for trunk/tests/phpunit/tests/hooks/addFilter.php
- Timestamp:
- 09/18/2023 12:39:18 PM (18 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/hooks/addFilter.php
r55081 r56609 36 36 37 37 $hook->add_filter( $hook_name, $callback, $priority, $accepted_args ); 38 $this->check_priority_exists( $hook, $priority ); 38 39 39 40 $function_index = _wp_filter_build_unique_id( $hook_name, $callback, $priority ); … … 51 52 52 53 $hook->add_filter( $hook_name, $callback, $priority, $accepted_args ); 54 $this->check_priority_exists( $hook, $priority ); 53 55 54 56 $function_index = _wp_filter_build_unique_id( $hook_name, $callback, $priority ); … … 65 67 66 68 $hook->add_filter( $hook_name, $callback, $priority, $accepted_args ); 69 $this->check_priority_exists( $hook, $priority ); 67 70 68 71 $function_index = _wp_filter_build_unique_id( $hook_name, $callback, $priority ); … … 80 83 81 84 $hook->add_filter( $hook_name, $callback_one, $priority, $accepted_args ); 85 $this->check_priority_exists( $hook, $priority ); 82 86 $this->assertCount( 1, $hook->callbacks[ $priority ] ); 83 87 … … 95 99 96 100 $hook->add_filter( $hook_name, $callback_one, $priority, $accepted_args ); 101 $this->check_priority_exists( $hook, $priority ); 97 102 $this->assertCount( 1, $hook->callbacks[ $priority ] ); 98 103 99 104 $hook->add_filter( $hook_name, $callback_two, $priority + 1, $accepted_args ); 105 $this->check_priority_exists( $hook, $priority + 1 ); 100 106 $this->assertCount( 1, $hook->callbacks[ $priority ] ); 101 107 $this->assertCount( 1, $hook->callbacks[ $priority + 1 ] ); … … 110 116 111 117 $hook->add_filter( $hook_name, $callback, $priority, $accepted_args ); 118 $this->check_priority_exists( $hook, $priority ); 112 119 $this->assertCount( 1, $hook->callbacks[ $priority ] ); 113 120 … … 124 131 125 132 $hook->add_filter( $hook_name, $callback, $priority, $accepted_args ); 133 $this->check_priority_exists( $hook, $priority ); 126 134 $this->assertCount( 1, $hook->callbacks[ $priority ] ); 127 135 128 136 $hook->add_filter( $hook_name, $callback, $priority + 1, $accepted_args ); 137 $this->check_priority_exists( $hook, $priority + 1 ); 129 138 $this->assertCount( 1, $hook->callbacks[ $priority ] ); 130 139 $this->assertCount( 1, $hook->callbacks[ $priority + 1 ] ); … … 142 151 $hook->add_filter( $hook_name, array( $c, 'action' ), 8, 1 ); 143 152 144 $this->assertSame( array( 5, 8, 10 ), array_keys( $hook->callbacks) );153 $this->assertSame( array( 5, 8, 10 ), $this->get_priorities( $hook ) ); 145 154 } 146 155 … … 149 158 150 159 $this->hook->add_filter( 'remove_and_add', '__return_empty_string', 10, 0 ); 151 160 $this->check_priority_exists( $this->hook, 10 ); 152 161 $this->hook->add_filter( 'remove_and_add', array( $this, '_filter_remove_and_add2' ), 11, 1 ); 153 162 $this->check_priority_exists( $this->hook, 11 ); 154 163 $this->hook->add_filter( 'remove_and_add', array( $this, '_filter_remove_and_add4' ), 12, 1 ); 155 164 $this->check_priority_exists( $this->hook, 12 ); 156 165 $value = $this->hook->apply_filters( '', array() ); 157 166 167 $this->assertSameSets( array( 10, 11, 12 ), $this->get_priorities( $this->hook ), 'The priorities should match this array' ); 168 158 169 $this->assertSame( '24', $value ); 159 170 } … … 163 174 164 175 $this->hook->add_filter( 'remove_and_add', '__return_empty_string', 10, 0 ); 165 176 $this->check_priority_exists( $this->hook, 10 ); 166 177 $this->hook->add_filter( 'remove_and_add', array( $this, '_filter_remove_and_add1' ), 11, 1 ); 167 178 $this->check_priority_exists( $this->hook, 11 ); 168 179 $this->hook->add_filter( 'remove_and_add', array( $this, '_filter_remove_and_add2' ), 12, 1 ); 169 180 $this->check_priority_exists( $this->hook, 12 ); 170 181 $value = $this->hook->apply_filters( '', array() ); 182 183 $this->assertSameSets( array( 10, 11, 12 ), $this->get_priorities( $this->hook ), 'The priorities should match this array' ); 171 184 172 185 $this->assertSame( '12', $value ); … … 184 197 $this->hook->add_filter( 'remove_and_add', array( $this, '_filter_remove_and_add4' ), 12, 1 ); 185 198 199 $this->assertSameSets( array( 10, 11, 12 ), $this->get_priorities( $this->hook ), 'The priorities should match this array' ); 200 186 201 $value = $this->hook->apply_filters( '', array() ); 187 202 … … 196 211 $this->hook->remove_filter( 'remove_and_add', array( $this, '_filter_remove_and_add2' ), 11 ); 197 212 $this->hook->add_filter( 'remove_and_add', array( $this, '_filter_remove_and_add2' ), 11, 1 ); 198 213 $this->check_priority_exists( $this->hook, 11 ); 199 214 return $value . '2'; 200 215 } … … 206 221 207 222 $this->hook->add_filter( 'remove_and_add', array( $this, '_filter_remove_and_recurse_and_add2' ), 11, 1 ); 208 223 $this->check_priority_exists( $this->hook, 11 ); 209 224 return $value . '2'; 210 225 } … … 292 307 $this->action_output .= '4'; 293 308 } 309 310 protected function check_priority_exists( $hook, $priority ) { 311 $priorities = $this->get_priorities( $hook ); 312 313 $this->assertContains( $priority, $priorities ); 314 } 315 316 protected function get_priorities( $hook ) { 317 $reflection = new ReflectionClass( $hook ); 318 $reflection_property = $reflection->getProperty( 'priorities' ); 319 $reflection_property->setAccessible( true ); 320 321 return $reflection_property->getValue( $hook ); 322 } 294 323 }
Note: See TracChangeset
for help on using the changeset viewer.