WordPress.org

Make WordPress Core

Ticket #21169: next-to-each-unit.patch

File next-to-each-unit.patch, 1.1 KB (added by devesine, 7 years ago)
  • tests/test_filters.php

     
    236236                $this->assertFalse( empty($args[0][1]->foo) );
    237237
    238238        }
     239
     240        function _self_removal($tag) {
     241                remove_action( $tag, array(&$this, '_self_removal'), 10, 1 );
     242                return $tag;
     243        }
     244
     245        function test_filter_removal_during_filter() {
     246                $tag = rand_str();
     247                $a = new MockAction();
     248                $b = new MockAction();
     249
     250                add_action( $tag, array(&$a, 'filter_append'), 11, 1 );
     251                add_action( $tag, array(&$b, 'filter_append'), 12, 1 );
     252                add_action( $tag, array(&$this, '_self_removal'), 10, 1 );
     253
     254                $result = apply_filters($tag, $tag);
     255                $this->assertEquals( 1, $a->get_call_count(), 'priority 11 filters should run after priority 10 empties itself' );
     256                $this->assertEquals( 1, $b->get_call_count(), 'priority 12 filters should run after priority 10 empties itself and priority 11 runs' );
     257                $this->assertEquals( $result, $tag . '_append_append', 'priority 11 and 12 filters should run after priority 10 empties itself' );
     258        }
    239259}