WordPress.org

Make WordPress Core

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

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

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