Ticket #40906: 40906.patch
File 40906.patch, 3.6 KB (added by , 8 years ago) |
---|
-
src/wp-includes/class-wp-hook.php
182 182 $exists = isset( $this->callbacks[ $priority ][ $function_key ] ); 183 183 if ( $exists ) { 184 184 unset( $this->callbacks[ $priority ][ $function_key ] ); 185 if ( ! $this->callbacks[ $priority ] ) { 186 unset( $this->callbacks[ $priority ] ); 187 if ( $this->nesting_level > 0 ) { 188 $this->resort_active_iterations(); 189 } 185 186 if ( $this->nesting_level > 0 ) { 187 $this->resort_active_iterations(); 190 188 } 191 189 } 192 190 return $exists; -
tests/phpunit/tests/hooks/do_action.php
169 169 $args = func_get_args(); 170 170 $this->events[] = array('action' => __FUNCTION__, 'args'=>$args); 171 171 } 172 173 public function test_do_action_with_handler_that_removes_itself() { 174 $a = new MockAction(); 175 $b = new MockAction(); 176 177 $this->hook = new WP_Hook(); 178 179 $this->hook->add_filter( 'handler_that_removes_itself', '__return_null', 10, 1 ); 180 $this->hook->add_filter( 'handler_that_removes_itself', array( $this, '_handler_that_removes_itself' ), 20, 1 ); 181 $this->hook->add_filter( 'handler_that_removes_itself', array( $a, 'action' ), 20 + 1, 1 ); 182 $this->hook->add_filter( 'handler_that_removes_itself', array( $b, 'action' ), 20 + 2, 1 ); 183 184 $this->hook->do_action( array( null ) ); 185 186 $this->assertEquals( 1, $a->get_call_count(), 'One of the callbacks was never executed.' ); 187 $this->assertEquals( 1, $b->get_call_count() ); 188 } 189 190 public function _handler_that_removes_itself() { 191 $success = $this->hook->remove_filter( 'handler_that_removes_itself', array( $this, '_handler_that_removes_itself' ), 20 ); 192 $this->assertTrue( $success ); 193 } 172 194 } -
tests/phpunit/tests/hooks/remove_filter.php
17 17 $hook->add_filter( $tag, $callback, $priority, $accepted_args ); 18 18 $hook->remove_filter( $tag, $callback, $priority ); 19 19 20 $this->assert False( isset( $hook->callbacks[ $priority ] ) );20 $this->assertEquals( 0, count( $hook->callbacks[ $priority ] ) ); 21 21 } 22 22 23 23 public function test_remove_filter_with_object() { … … 31 31 $hook->add_filter( $tag, $callback, $priority, $accepted_args ); 32 32 $hook->remove_filter( $tag, $callback, $priority ); 33 33 34 $this->assert False( isset( $hook->callbacks[ $priority ] ) );34 $this->assertEquals( 0, count( $hook->callbacks[ $priority ] ) ); 35 35 } 36 36 37 37 public function test_remove_filter_with_static_method() { … … 44 44 $hook->add_filter( $tag, $callback, $priority, $accepted_args ); 45 45 $hook->remove_filter( $tag, $callback, $priority ); 46 46 47 $this->assert False( isset( $hook->callbacks[ $priority ] ) );47 $this->assertEquals( 0, count( $hook->callbacks[ $priority ] ) ); 48 48 } 49 49 50 50 public function test_remove_filters_with_another_at_same_priority() { … … 75 75 $hook->add_filter( $tag, $callback_two, $priority + 1, $accepted_args ); 76 76 77 77 $hook->remove_filter( $tag, $callback_one, $priority ); 78 $this->assert False( isset( $hook->callbacks[ $priority ] ) );78 $this->assertEquals( 0, count( $hook->callbacks[ $priority ] ) ); 79 79 $this->assertCount( 1, $hook->callbacks[ $priority + 1 ] ); 80 80 } 81 81 }