Make WordPress Core

Changeset 53804


Ignore:
Timestamp:
07/31/2022 03:03:46 PM (23 months ago)
Author:
SergeyBiryukov
Message:

Tests: Update the terminology used for action or filter names in hook tests.

This replaces the $tag variables with $hook_name, to match the core function signatures.

Follow-up to [24/tests], [62/tests], [866/tests], [1294/tests], [38571], [50807].

See #55652.

Location:
trunk/tests/phpunit/tests
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/actions.php

    r52389 r53804  
    1212     */
    1313    public function test_simple_action() {
    14         $a   = new MockAction();
    15         $tag = __FUNCTION__;
    16 
    17         add_action( $tag, array( &$a, 'action' ) );
    18         do_action( $tag );
     14        $a         = new MockAction();
     15        $hook_name = __FUNCTION__;
     16
     17        add_action( $hook_name, array( &$a, 'action' ) );
     18        do_action( $hook_name );
    1919
    2020        // Only one event occurred for the hook, with empty args.
    2121        $this->assertSame( 1, $a->get_call_count() );
    2222        // Only our hook was called.
    23         $this->assertSame( array( $tag ), $a->get_tags() );
     23        $this->assertSame( array( $hook_name ), $a->get_tags() );
    2424
    2525        $argsvar = $a->get_args();
     
    3232     */
    3333    public function test_remove_action() {
    34         $a   = new MockAction();
    35         $tag = __FUNCTION__;
    36 
    37         add_action( $tag, array( &$a, 'action' ) );
    38         do_action( $tag );
     34        $a         = new MockAction();
     35        $hook_name = __FUNCTION__;
     36
     37        add_action( $hook_name, array( &$a, 'action' ) );
     38        do_action( $hook_name );
    3939
    4040        // Make sure our hook was called correctly.
    4141        $this->assertSame( 1, $a->get_call_count() );
    42         $this->assertSame( array( $tag ), $a->get_tags() );
     42        $this->assertSame( array( $hook_name ), $a->get_tags() );
    4343
    4444        // Now remove the action, do it again, and make sure it's not called this time.
    45         remove_action( $tag, array( &$a, 'action' ) );
    46         do_action( $tag );
     45        remove_action( $hook_name, array( &$a, 'action' ) );
     46        do_action( $hook_name );
    4747        $this->assertSame( 1, $a->get_call_count() );
    48         $this->assertSame( array( $tag ), $a->get_tags() );
     48        $this->assertSame( array( $hook_name ), $a->get_tags() );
    4949
    5050    }
     
    5454     */
    5555    public function test_has_action() {
    56         $tag  = __FUNCTION__;
    57         $func = __FUNCTION__ . '_func';
    58 
    59         $this->assertFalse( has_action( $tag, $func ) );
    60         $this->assertFalse( has_action( $tag ) );
    61         add_action( $tag, $func );
    62         $this->assertSame( 10, has_action( $tag, $func ) );
    63         $this->assertTrue( has_action( $tag ) );
    64         remove_action( $tag, $func );
    65         $this->assertFalse( has_action( $tag, $func ) );
    66         $this->assertFalse( has_action( $tag ) );
     56        $hook_name = __FUNCTION__;
     57        $callback  = __FUNCTION__ . '_func';
     58
     59        $this->assertFalse( has_action( $hook_name, $callback ) );
     60        $this->assertFalse( has_action( $hook_name ) );
     61
     62        add_action( $hook_name, $callback );
     63        $this->assertSame( 10, has_action( $hook_name, $callback ) );
     64        $this->assertTrue( has_action( $hook_name ) );
     65
     66        remove_action( $hook_name, $callback );
     67        $this->assertFalse( has_action( $hook_name, $callback ) );
     68        $this->assertFalse( has_action( $hook_name ) );
    6769    }
    6870
     
    7375     */
    7476    public function test_multiple_actions() {
    75         $a1  = new MockAction();
    76         $a2  = new MockAction();
    77         $tag = __FUNCTION__;
     77        $a1        = new MockAction();
     78        $a2        = new MockAction();
     79        $hook_name = __FUNCTION__;
    7880
    7981        // Add both actions to the hook.
    80         add_action( $tag, array( &$a1, 'action' ) );
    81         add_action( $tag, array( &$a2, 'action' ) );
    82 
    83         do_action( $tag );
     82        add_action( $hook_name, array( &$a1, 'action' ) );
     83        add_action( $hook_name, array( &$a2, 'action' ) );
     84
     85        do_action( $hook_name );
    8486
    8587        // Both actions called once each.
     
    9496     */
    9597    public function test_action_args_1() {
    96         $a   = new MockAction();
    97         $tag = __FUNCTION__;
    98         $val = __FUNCTION__ . '_val';
    99 
    100         add_action( $tag, array( &$a, 'action' ) );
     98        $a         = new MockAction();
     99        $hook_name = __FUNCTION__;
     100        $val       = __FUNCTION__ . '_val';
     101
     102        add_action( $hook_name, array( &$a, 'action' ) );
    101103        // Call the action with a single argument.
    102         do_action( $tag, $val );
     104        do_action( $hook_name, $val );
    103105
    104106        $call_count = $a->get_call_count();
     
    114116     */
    115117    public function test_action_args_2() {
    116         $a1   = new MockAction();
    117         $a2   = new MockAction();
    118         $tag = __FUNCTION__;
    119         $val1 = __FUNCTION__ . '_val1';
    120         $val2 = __FUNCTION__ . '_val2';
     118        $a1        = new MockAction();
     119        $a2        = new MockAction();
     120        $hook_name = __FUNCTION__;
     121        $val1      = __FUNCTION__ . '_val1';
     122        $val2      = __FUNCTION__ . '_val2';
    121123
    122124        // $a1 accepts two arguments, $a2 doesn't.
    123         add_action( $tag, array( &$a1, 'action' ), 10, 2 );
    124         add_action( $tag, array( &$a2, 'action' ) );
     125        add_action( $hook_name, array( &$a1, 'action' ), 10, 2 );
     126        add_action( $hook_name, array( &$a2, 'action' ) );
    125127        // Call the action with two arguments.
    126         do_action( $tag, $val1, $val2 );
     128        do_action( $hook_name, $val1, $val2 );
    127129
    128130        $call_count = $a1->get_call_count();
     
    148150     */
    149151    public function test_action_args_3() {
    150         $a1   = new MockAction();
    151         $a2   = new MockAction();
    152         $a3   = new MockAction();
    153         $tag = __FUNCTION__;
    154         $val1 = __FUNCTION__ . '_val1';
    155         $val2 = __FUNCTION__ . '_val2';
     152        $a1        = new MockAction();
     153        $a2        = new MockAction();
     154        $a3        = new MockAction();
     155        $hook_name = __FUNCTION__;
     156        $val1      = __FUNCTION__ . '_val1';
     157        $val2      = __FUNCTION__ . '_val2';
    156158
    157159        // $a1 accepts two arguments, $a2 doesn't, $a3 accepts two arguments.
    158         add_action( $tag, array( &$a1, 'action' ), 10, 2 );
    159         add_action( $tag, array( &$a2, 'action' ) );
    160         add_action( $tag, array( &$a3, 'action' ), 10, 2 );
     160        add_action( $hook_name, array( &$a1, 'action' ), 10, 2 );
     161        add_action( $hook_name, array( &$a2, 'action' ) );
     162        add_action( $hook_name, array( &$a3, 'action' ), 10, 2 );
    161163        // Call the action with two arguments.
    162         do_action( $tag, $val1, $val2 );
     164        do_action( $hook_name, $val1, $val2 );
    163165
    164166        $call_count = $a1->get_call_count();
     
    187189     */
    188190    public function test_action_args_with_php4_syntax() {
    189         $a   = new MockAction();
    190         $tag = __FUNCTION__;
    191         $val = new stdClass();
    192 
    193         add_action( $tag, array( &$a, 'action' ) );
     191        $a         = new MockAction();
     192        $hook_name = __FUNCTION__;
     193        $val       = new stdClass();
     194
     195        add_action( $hook_name, array( &$a, 'action' ) );
    194196        // Call the action with PHP 4 notation for passing object by reference.
    195         do_action( $tag, array( &$val ) );
     197        do_action( $hook_name, array( &$val ) );
    196198
    197199        $call_count = $a->get_call_count();
     
    201203
    202204    public function test_action_priority() {
    203         $a   = new MockAction();
    204         $tag = __FUNCTION__;
    205 
    206         add_action( $tag, array( &$a, 'action' ), 10 );
    207         add_action( $tag, array( &$a, 'action2' ), 9 );
    208         do_action( $tag );
     205        $a         = new MockAction();
     206        $hook_name = __FUNCTION__;
     207
     208        add_action( $hook_name, array( &$a, 'action' ), 10 );
     209        add_action( $hook_name, array( &$a, 'action2' ), 9 );
     210        do_action( $hook_name );
    209211
    210212        // Two events, one per action.
     
    215217            array(
    216218                'action' => 'action2',
    217                 'tag'    => $tag,
     219                'tag'    => $hook_name,
    218220                'args'   => array( '' ),
    219221            ),
     
    221223            array(
    222224                'action' => 'action',
    223                 'tag'    => $tag,
     225                'tag'    => $hook_name,
    224226                'args'   => array( '' ),
    225227            ),
     
    233235     */
    234236    public function test_did_action() {
    235         $tag1 = 'action1';
    236         $tag2 = 'action2';
    237 
    238         // Do action $tag1 but not $tag2.
    239         do_action( $tag1 );
    240         $this->assertSame( 1, did_action( $tag1 ) );
    241         $this->assertSame( 0, did_action( $tag2 ) );
    242 
    243         // Do action $tag2 10 times.
     237        $hook_name1 = 'action1';
     238        $hook_name2 = 'action2';
     239
     240        // Do action $hook_name1 but not $hook_name2.
     241        do_action( $hook_name1 );
     242        $this->assertSame( 1, did_action( $hook_name1 ) );
     243        $this->assertSame( 0, did_action( $hook_name2 ) );
     244
     245        // Do action $hook_name2 10 times.
    244246        $count = 10;
    245247        for ( $i = 0; $i < $count; $i++ ) {
    246             do_action( $tag2 );
     248            do_action( $hook_name2 );
    247249        }
    248250
    249         // $tag1's count hasn't changed, $tag2 should be correct.
    250         $this->assertSame( 1, did_action( $tag1 ) );
    251         $this->assertSame( $count, did_action( $tag2 ) );
     251        // $hook_name1's count hasn't changed, $hook_name2 should be correct.
     252        $this->assertSame( 1, did_action( $hook_name1 ) );
     253        $this->assertSame( $count, did_action( $hook_name2 ) );
    252254
    253255    }
     
    257259     */
    258260    public function test_all_action() {
    259         $a    = new MockAction();
    260         $tag1 = __FUNCTION__ . '_1';
    261         $tag2 = __FUNCTION__ . '_2';
     261        $a          = new MockAction();
     262        $hook_name1 = __FUNCTION__ . '_1';
     263        $hook_name2 = __FUNCTION__ . '_2';
    262264
    263265        // Add an 'all' action.
     
    265267        $this->assertSame( 10, has_filter( 'all', array( &$a, 'action' ) ) );
    266268        // Do some actions.
    267         do_action( $tag1 );
    268         do_action( $tag2 );
    269         do_action( $tag1 );
    270         do_action( $tag1 );
     269        do_action( $hook_name1 );
     270        do_action( $hook_name2 );
     271        do_action( $hook_name1 );
     272        do_action( $hook_name1 );
    271273
    272274        // Our action should have been called once for each tag.
    273275        $this->assertSame( 4, $a->get_call_count() );
    274276        // Only our hook was called.
    275         $this->assertSame( array( $tag1, $tag2, $tag1, $tag1 ), $a->get_tags() );
     277        $this->assertSame( array( $hook_name1, $hook_name2, $hook_name1, $hook_name1 ), $a->get_tags() );
    276278
    277279        remove_action( 'all', array( &$a, 'action' ) );
     
    284286     */
    285287    public function test_remove_all_action() {
    286         $a   = new MockAction();
    287         $tag = __FUNCTION__;
     288        $a         = new MockAction();
     289        $hook_name = __FUNCTION__;
    288290
    289291        add_action( 'all', array( &$a, 'action' ) );
    290292        $this->assertSame( 10, has_filter( 'all', array( &$a, 'action' ) ) );
    291         do_action( $tag );
     293        do_action( $hook_name );
    292294
    293295        // Make sure our hook was called correctly.
    294296        $this->assertSame( 1, $a->get_call_count() );
    295         $this->assertSame( array( $tag ), $a->get_tags() );
     297        $this->assertSame( array( $hook_name ), $a->get_tags() );
    296298
    297299        // Now remove the action, do it again, and make sure it's not called this time.
    298300        remove_action( 'all', array( &$a, 'action' ) );
    299301        $this->assertFalse( has_filter( 'all', array( &$a, 'action' ) ) );
    300         do_action( $tag );
     302        do_action( $hook_name );
    301303        $this->assertSame( 1, $a->get_call_count() );
    302         $this->assertSame( array( $tag ), $a->get_tags() );
     304        $this->assertSame( array( $hook_name ), $a->get_tags() );
    303305    }
    304306
     
    307309     */
    308310    public function test_action_ref_array() {
    309         $obj = new stdClass();
    310         $a   = new MockAction();
    311         $tag = __FUNCTION__;
    312 
    313         add_action( $tag, array( &$a, 'action' ) );
    314 
    315         do_action_ref_array( $tag, array( &$obj ) );
     311        $obj       = new stdClass();
     312        $a         = new MockAction();
     313        $hook_name = __FUNCTION__;
     314
     315        add_action( $hook_name, array( &$a, 'action' ) );
     316
     317        do_action_ref_array( $hook_name, array( &$obj ) );
    316318
    317319        $args = $a->get_args();
     
    330332        $a = new MockAction();
    331333
    332         $tag = __FUNCTION__;
    333 
    334         add_action( $tag, array( &$a, 'action' ) );
     334        $hook_name = __FUNCTION__;
     335
     336        add_action( $hook_name, array( &$a, 'action' ) );
    335337
    336338        $context = array( 'key1' => 'val1' );
    337         do_action( $tag, $context );
     339        do_action( $hook_name, $context );
    338340
    339341        $args = $a->get_args();
     
    344346            'key3' => 'val3',
    345347        );
    346         do_action( $tag, $context2 );
     348        do_action( $hook_name, $context2 );
    347349
    348350        $args = $a->get_args();
     
    370372     */
    371373    public function test_action_recursion() {
    372         $tag = __FUNCTION__;
    373         $a   = new MockAction();
    374         $b   = new MockAction();
    375 
    376         add_action( $tag, array( $a, 'action' ), 11, 1 );
    377         add_action( $tag, array( $b, 'action' ), 13, 1 );
    378         add_action( $tag, array( $this, 'action_that_causes_recursion' ), 12, 1 );
    379         do_action( $tag, $tag );
     374        $hook_name = __FUNCTION__;
     375        $a         = new MockAction();
     376        $b         = new MockAction();
     377
     378        add_action( $hook_name, array( $a, 'action' ), 11, 1 );
     379        add_action( $hook_name, array( $b, 'action' ), 13, 1 );
     380        add_action( $hook_name, array( $this, 'action_that_causes_recursion' ), 12, 1 );
     381        do_action( $hook_name, $hook_name );
    380382
    381383        $this->assertSame( 2, $a->get_call_count(), 'recursive actions should call all callbacks with earlier priority' );
     
    386388     * @covers ::do_action
    387389     */
    388     public function action_that_causes_recursion( $tag ) {
     390    public function action_that_causes_recursion( $hook_name ) {
    389391        static $recursing = false;
    390392        if ( ! $recursing ) {
    391393            $recursing = true;
    392             do_action( $tag, $tag );
     394            do_action( $hook_name, $hook_name );
    393395        }
    394396        $recursing = false;
     
    403405     */
    404406    public function test_action_callback_manipulation_while_running() {
    405         $tag = __FUNCTION__;
    406         $a   = new MockAction();
    407         $b   = new MockAction();
    408         $c   = new MockAction();
    409         $d   = new MockAction();
    410         $e   = new MockAction();
    411 
    412         add_action( $tag, array( $a, 'action' ), 11, 2 );
    413         add_action( $tag, array( $this, 'action_that_manipulates_a_running_hook' ), 12, 2 );
    414         add_action( $tag, array( $b, 'action' ), 12, 2 );
    415 
    416         do_action( $tag, $tag, array( $a, $b, $c, $d, $e ) );
    417         do_action( $tag, $tag, array( $a, $b, $c, $d, $e ) );
     407        $hook_name = __FUNCTION__;
     408        $a         = new MockAction();
     409        $b         = new MockAction();
     410        $c         = new MockAction();
     411        $d         = new MockAction();
     412        $e         = new MockAction();
     413
     414        add_action( $hook_name, array( $a, 'action' ), 11, 2 );
     415        add_action( $hook_name, array( $this, 'action_that_manipulates_a_running_hook' ), 12, 2 );
     416        add_action( $hook_name, array( $b, 'action' ), 12, 2 );
     417
     418        do_action( $hook_name, $hook_name, array( $a, $b, $c, $d, $e ) );
     419        do_action( $hook_name, $hook_name, array( $a, $b, $c, $d, $e ) );
    418420
    419421        $this->assertSame( 2, $a->get_call_count(), 'callbacks should run unless otherwise instructed' );
     
    424426    }
    425427
    426     public function action_that_manipulates_a_running_hook( $tag, $mocks ) {
    427         remove_action( $tag, array( $mocks[1], 'action' ), 12, 2 );
    428         add_action( $tag, array( $mocks[2], 'action' ), 12, 2 );
    429         add_action( $tag, array( $mocks[3], 'action' ), 13, 2 );
    430         add_action( $tag, array( $mocks[4], 'action' ), 10, 2 );
     428    public function action_that_manipulates_a_running_hook( $hook_name, $mocks ) {
     429        remove_action( $hook_name, array( $mocks[1], 'action' ), 12, 2 );
     430        add_action( $hook_name, array( $mocks[2], 'action' ), 12, 2 );
     431        add_action( $hook_name, array( $mocks[3], 'action' ), 13, 2 );
     432        add_action( $hook_name, array( $mocks[4], 'action' ), 10, 2 );
    431433    }
    432434
     
    440442     */
    441443    public function test_remove_anonymous_callback() {
    442         $tag = __FUNCTION__;
    443         $a   = new MockAction();
    444         add_action( $tag, array( $a, 'action' ), 12, 1 );
    445         $this->assertTrue( has_action( $tag ) );
    446 
    447         $hook = $GLOBALS['wp_filter'][ $tag ];
     444        $hook_name = __FUNCTION__;
     445        $a         = new MockAction();
     446        add_action( $hook_name, array( $a, 'action' ), 12, 1 );
     447        $this->assertTrue( has_action( $hook_name ) );
     448
     449        $hook = $GLOBALS['wp_filter'][ $hook_name ];
    448450
    449451        // From http://wordpress.stackexchange.com/a/57088/6445
     
    455457                ) {
    456458                    remove_filter(
    457                         $tag,
     459                        $hook_name,
    458460                        array( $function['function'][0], 'action' ),
    459461                        $priority
     
    463465        }
    464466
    465         $this->assertFalse( has_action( $tag ) );
     467        $this->assertFalse( has_action( $hook_name ) );
    466468    }
    467469
     
    478480    public function test_array_access_of_wp_filter_global() {
    479481        global $wp_filter;
    480         $tag = __FUNCTION__;
    481 
    482         add_action( $tag, '__return_null', 11, 1 );
    483 
    484         $this->assertArrayHasKey( 11, $wp_filter[ $tag ] );
    485         $this->assertArrayHasKey( '__return_null', $wp_filter[ $tag ][11] );
    486 
    487         unset( $wp_filter[ $tag ][11] );
    488         $this->assertFalse( has_action( $tag, '__return_null' ) );
    489 
    490         $wp_filter[ $tag ][11] = array(
     482
     483        $hook_name = __FUNCTION__;
     484
     485        add_action( $hook_name, '__return_null', 11, 1 );
     486
     487        $this->assertArrayHasKey( 11, $wp_filter[ $hook_name ] );
     488        $this->assertArrayHasKey( '__return_null', $wp_filter[ $hook_name ][11] );
     489
     490        unset( $wp_filter[ $hook_name ][11] );
     491        $this->assertFalse( has_action( $hook_name, '__return_null' ) );
     492
     493        $wp_filter[ $hook_name ][11] = array(
    491494            '__return_null' => array(
    492495                'function'      => '__return_null',
     
    494497            ),
    495498        );
    496         $this->assertSame( 11, has_action( $tag, '__return_null' ) );
     499        $this->assertSame( 11, has_action( $hook_name, '__return_null' ) );
    497500    }
    498501
     
    506509    public function test_current_action() {
    507510        global $wp_current_filter;
     511
    508512        $wp_current_filter[] = 'first';
    509513        $wp_current_filter[] = 'second'; // Let's say a second action was invoked.
     
    519523    public function test_doing_filter() {
    520524        global $wp_current_filter;
     525
    521526        $wp_current_filter = array(); // Set to an empty array first.
    522527
     
    540545    public function test_doing_action() {
    541546        global $wp_current_filter;
     547
    542548        $wp_current_filter = array(); // Set to an empty array first.
    543549
  • trunk/tests/phpunit/tests/actions/callbacks.php

    r52010 r53804  
    1212     */
    1313    public function test_callback_representations() {
    14         $tag = __FUNCTION__;
     14        $hook_name = __FUNCTION__;
    1515
    16         $this->assertFalse( has_action( $tag ) );
     16        $this->assertFalse( has_action( $hook_name ) );
    1717
    18         add_action( $tag, array( 'Class', 'method' ) );
     18        add_action( $hook_name, array( 'Class', 'method' ) );
    1919
    20         $this->assertSame( 10, has_action( $tag, array( 'Class', 'method' ) ) );
     20        $this->assertSame( 10, has_action( $hook_name, array( 'Class', 'method' ) ) );
    2121
    22         $this->assertSame( 10, has_action( $tag, 'Class::method' ) );
     22        $this->assertSame( 10, has_action( $hook_name, 'Class::method' ) );
    2323    }
    2424}
  • trunk/tests/phpunit/tests/actions/closures.php

    r52010 r53804  
    1616     */
    1717    public function test_action_closure() {
    18         $tag    = 'test_action_closure';
    19         $closure = static function( $a, $b ) {
     18        $hook_name = 'test_action_closure';
     19        $closure   = static function( $a, $b ) {
    2020            $GLOBALS[ $a ] = $b;
    2121        };
    22         add_action( $tag, $closure, 10, 2 );
     22        add_action( $hook_name, $closure, 10, 2 );
    2323
    24         $this->assertSame( 10, has_action( $tag, $closure ) );
     24        $this->assertSame( 10, has_action( $hook_name, $closure ) );
    2525
    2626        $context = array( 'val1', 'val2' );
    27         do_action( $tag, $context[0], $context[1] );
     27        do_action( $hook_name, $context[0], $context[1] );
    2828
    2929        $this->assertSame( $GLOBALS[ $context[0] ], $context[1] );
    3030
    31         $tag2    = 'test_action_closure_2';
    32         $closure2 = static function() {
     31        $hook_name2 = 'test_action_closure_2';
     32        $closure2   = static function() {
    3333            $GLOBALS['closure_no_args'] = true;
    3434        };
    35         add_action( $tag2, $closure2 );
     35        add_action( $hook_name2, $closure2 );
    3636
    37         $this->assertSame( 10, has_action( $tag2, $closure2 ) );
     37        $this->assertSame( 10, has_action( $hook_name2, $closure2 ) );
    3838
    39         do_action( $tag2 );
     39        do_action( $hook_name2 );
    4040
    4141        $this->assertTrue( $GLOBALS['closure_no_args'] );
    4242
    43         remove_action( $tag, $closure );
    44         remove_action( $tag2, $closure2 );
     43        remove_action( $hook_name, $closure );
     44        remove_action( $hook_name2, $closure2 );
    4545    }
    4646}
  • trunk/tests/phpunit/tests/filters.php

    r53803 r53804  
    99
    1010    public function test_simple_filter() {
    11         $a   = new MockAction();
    12         $tag = __FUNCTION__;
    13         $val = __FUNCTION__ . '_val';
    14 
    15         add_filter( $tag, array( $a, 'filter' ) );
    16         $this->assertSame( $val, apply_filters( $tag, $val ) );
     11        $a         = new MockAction();
     12        $hook_name = __FUNCTION__;
     13        $val       = __FUNCTION__ . '_val';
     14
     15        add_filter( $hook_name, array( $a, 'filter' ) );
     16        $this->assertSame( $val, apply_filters( $hook_name, $val ) );
    1717
    1818        // Only one event occurred for the hook, with empty args.
    1919        $this->assertSame( 1, $a->get_call_count() );
    2020        // Only our hook was called.
    21         $this->assertSame( array( $tag ), $a->get_tags() );
     21        $this->assertSame( array( $hook_name ), $a->get_tags() );
    2222
    2323        $argsvar = $a->get_args();
     
    2727
    2828    public function test_remove_filter() {
    29         $a   = new MockAction();
    30         $tag = __FUNCTION__;
    31         $val = __FUNCTION__ . '_val';
    32 
    33         add_filter( $tag, array( $a, 'filter' ) );
    34         $this->assertSame( $val, apply_filters( $tag, $val ) );
     29        $a         = new MockAction();
     30        $hook_name = __FUNCTION__;
     31        $val       = __FUNCTION__ . '_val';
     32
     33        add_filter( $hook_name, array( $a, 'filter' ) );
     34        $this->assertSame( $val, apply_filters( $hook_name, $val ) );
    3535
    3636        // Make sure our hook was called correctly.
    3737        $this->assertSame( 1, $a->get_call_count() );
    38         $this->assertSame( array( $tag ), $a->get_tags() );
     38        $this->assertSame( array( $hook_name ), $a->get_tags() );
    3939
    4040        // Now remove the filter, do it again, and make sure it's not called this time.
    41         remove_filter( $tag, array( $a, 'filter' ) );
    42         $this->assertSame( $val, apply_filters( $tag, $val ) );
    43         $this->assertSame( 1, $a->get_call_count() );
    44         $this->assertSame( array( $tag ), $a->get_tags() );
     41        remove_filter( $hook_name, array( $a, 'filter' ) );
     42        $this->assertSame( $val, apply_filters( $hook_name, $val ) );
     43        $this->assertSame( 1, $a->get_call_count() );
     44        $this->assertSame( array( $hook_name ), $a->get_tags() );
    4545
    4646    }
    4747
    4848    public function test_has_filter() {
    49         $tag = __FUNCTION__;
    50         $func = __FUNCTION__ . '_func';
    51 
    52         $this->assertFalse( has_filter( $tag, $func ) );
    53         $this->assertFalse( has_filter( $tag ) );
    54 
    55         add_filter( $tag, $func );
    56         $this->assertSame( 10, has_filter( $tag, $func ) );
    57         $this->assertTrue( has_filter( $tag ) );
    58 
    59         remove_filter( $tag, $func );
    60         $this->assertFalse( has_filter( $tag, $func ) );
    61         $this->assertFalse( has_filter( $tag ) );
     49        $hook_name = __FUNCTION__;
     50        $callback = __FUNCTION__ . '_func';
     51
     52        $this->assertFalse( has_filter( $hook_name, $callback ) );
     53        $this->assertFalse( has_filter( $hook_name ) );
     54
     55        add_filter( $hook_name, $callback );
     56        $this->assertSame( 10, has_filter( $hook_name, $callback ) );
     57        $this->assertTrue( has_filter( $hook_name ) );
     58
     59        remove_filter( $hook_name, $callback );
     60        $this->assertFalse( has_filter( $hook_name, $callback ) );
     61        $this->assertFalse( has_filter( $hook_name ) );
    6262    }
    6363
    6464    // One tag with multiple filters.
    6565    public function test_multiple_filters() {
    66         $a1  = new MockAction();
    67         $a2  = new MockAction();
    68         $tag = __FUNCTION__;
    69         $val = __FUNCTION__ . '_val';
     66        $a1        = new MockAction();
     67        $a2        = new MockAction();
     68        $hook_name = __FUNCTION__;
     69        $val       = __FUNCTION__ . '_val';
    7070
    7171        // Add both filters to the hook.
    72         add_filter( $tag, array( $a1, 'filter' ) );
    73         add_filter( $tag, array( $a2, 'filter' ) );
    74 
    75         $this->assertSame( $val, apply_filters( $tag, $val ) );
     72        add_filter( $hook_name, array( $a1, 'filter' ) );
     73        add_filter( $hook_name, array( $a2, 'filter' ) );
     74
     75        $this->assertSame( $val, apply_filters( $hook_name, $val ) );
    7676
    7777        // Both filters called once each.
     
    8181
    8282    public function test_filter_args_1() {
    83         $a    = new MockAction();
    84         $tag = __FUNCTION__;
    85         $val  = __FUNCTION__ . '_val';
    86         $arg1 = __FUNCTION__ . '_arg1';
    87 
    88         add_filter( $tag, array( $a, 'filter' ), 10, 2 );
     83        $a         = new MockAction();
     84        $hook_name = __FUNCTION__;
     85        $val       = __FUNCTION__ . '_val';
     86        $arg1      = __FUNCTION__ . '_arg1';
     87
     88        add_filter( $hook_name, array( $a, 'filter' ), 10, 2 );
    8989        // Call the filter with a single argument.
    90         $this->assertSame( $val, apply_filters( $tag, $val, $arg1 ) );
     90        $this->assertSame( $val, apply_filters( $hook_name, $val, $arg1 ) );
    9191
    9292        $this->assertSame( 1, $a->get_call_count() );
     
    9696
    9797    public function test_filter_args_2() {
    98         $a1   = new MockAction();
    99         $a2   = new MockAction();
    100         $tag = __FUNCTION__;
    101         $val  = __FUNCTION__ . '_val';
    102         $arg1 = __FUNCTION__ . '_arg1';
    103         $arg2 = __FUNCTION__ . '_arg2';
     98        $a1        = new MockAction();
     99        $a2        = new MockAction();
     100        $hook_name = __FUNCTION__;
     101        $val       = __FUNCTION__ . '_val';
     102        $arg1      = __FUNCTION__ . '_arg1';
     103        $arg2      = __FUNCTION__ . '_arg2';
    104104
    105105        // $a1 accepts two arguments, $a2 doesn't.
    106         add_filter( $tag, array( $a1, 'filter' ), 10, 3 );
    107         add_filter( $tag, array( $a2, 'filter' ) );
     106        add_filter( $hook_name, array( $a1, 'filter' ), 10, 3 );
     107        add_filter( $hook_name, array( $a2, 'filter' ) );
    108108        // Call the filter with two arguments.
    109         $this->assertSame( $val, apply_filters( $tag, $val, $arg1, $arg2 ) );
     109        $this->assertSame( $val, apply_filters( $hook_name, $val, $arg1, $arg2 ) );
    110110
    111111        // $a1 should be called with both args.
     
    121121
    122122    public function test_filter_priority() {
    123         $a   = new MockAction();
    124         $tag = __FUNCTION__;
    125         $val = __FUNCTION__ . '_val';
     123        $a         = new MockAction();
     124        $hook_name = __FUNCTION__;
     125        $val       = __FUNCTION__ . '_val';
    126126
    127127        // Make two filters with different priorities.
    128         add_filter( $tag, array( $a, 'filter' ), 10 );
    129         add_filter( $tag, array( $a, 'filter2' ), 9 );
    130         $this->assertSame( $val, apply_filters( $tag, $val ) );
     128        add_filter( $hook_name, array( $a, 'filter' ), 10 );
     129        add_filter( $hook_name, array( $a, 'filter2' ), 9 );
     130        $this->assertSame( $val, apply_filters( $hook_name, $val ) );
    131131
    132132        // There should be two events, one per filter.
     
    137137            array(
    138138                'filter' => 'filter2',
    139                 'tag'    => $tag,
     139                'tag'    => $hook_name,
    140140                'args'   => array( $val ),
    141141            ),
     
    143143            array(
    144144                'filter' => 'filter',
    145                 'tag'    => $tag,
     145                'tag'    => $hook_name,
    146146                'args'   => array( $val ),
    147147            ),
     
    155155     */
    156156    public function test_did_filter() {
    157         $tag1 = 'filter1';
    158         $tag2 = 'filter2';
    159         $val  = __FUNCTION__ . '_val';
    160 
    161         // Apply filter $tag1 but not $tag2.
    162         apply_filters( $tag1, $val );
    163         $this->assertSame( 1, did_filter( $tag1 ) );
    164         $this->assertSame( 0, did_filter( $tag2 ) );
    165 
    166         // Apply filter $tag2 10 times.
     157        $hook_name1 = 'filter1';
     158        $hook_name2 = 'filter2';
     159        $val        = __FUNCTION__ . '_val';
     160
     161        // Apply filter $hook_name1 but not $hook_name2.
     162        apply_filters( $hook_name1, $val );
     163        $this->assertSame( 1, did_filter( $hook_name1 ) );
     164        $this->assertSame( 0, did_filter( $hook_name2 ) );
     165
     166        // Apply filter $hook_name2 10 times.
    167167        $count = 10;
    168168        for ( $i = 0; $i < $count; $i++ ) {
    169             apply_filters( $tag2, $val );
     169            apply_filters( $hook_name2, $val );
    170170        }
    171171
    172         // $tag1's count hasn't changed, $tag2 should be correct.
    173         $this->assertSame( 1, did_filter( $tag1 ) );
    174         $this->assertSame( $count, did_filter( $tag2 ) );
     172        // $hook_name1's count hasn't changed, $hook_name2 should be correct.
     173        $this->assertSame( 1, did_filter( $hook_name1 ) );
     174        $this->assertSame( $count, did_filter( $hook_name2 ) );
    175175
    176176    }
    177177
    178178    public function test_all_filter() {
    179         $a    = new MockAction();
    180         $tag1 = __FUNCTION__ . '_1';
    181         $tag2 = __FUNCTION__ . '_2';
    182         $val  = __FUNCTION__ . '_val';
     179        $a          = new MockAction();
     180        $hook_name1 = __FUNCTION__ . '_1';
     181        $hook_name2 = __FUNCTION__ . '_2';
     182        $val        = __FUNCTION__ . '_val';
    183183
    184184        // Add an 'all' filter.
    185185        add_filter( 'all', array( $a, 'filterall' ) );
    186186        // Apply some filters.
    187         $this->assertSame( $val, apply_filters( $tag1, $val ) );
    188         $this->assertSame( $val, apply_filters( $tag2, $val ) );
    189         $this->assertSame( $val, apply_filters( $tag1, $val ) );
    190         $this->assertSame( $val, apply_filters( $tag1, $val ) );
     187        $this->assertSame( $val, apply_filters( $hook_name1, $val ) );
     188        $this->assertSame( $val, apply_filters( $hook_name2, $val ) );
     189        $this->assertSame( $val, apply_filters( $hook_name1, $val ) );
     190        $this->assertSame( $val, apply_filters( $hook_name1, $val ) );
    191191
    192192        // Our filter should have been called once for each apply_filters call.
    193193        $this->assertSame( 4, $a->get_call_count() );
    194194        // The right hooks should have been called in order.
    195         $this->assertSame( array( $tag1, $tag2, $tag1, $tag1 ), $a->get_tags() );
     195        $this->assertSame( array( $hook_name1, $hook_name2, $hook_name1, $hook_name1 ), $a->get_tags() );
    196196
    197197        remove_filter( 'all', array( $a, 'filterall' ) );
     
    201201
    202202    public function test_remove_all_filter() {
    203         $a   = new MockAction();
    204         $tag = __FUNCTION__;
    205         $val = __FUNCTION__ . '_val';
     203        $a         = new MockAction();
     204        $hook_name = __FUNCTION__;
     205        $val       = __FUNCTION__ . '_val';
    206206
    207207        add_filter( 'all', array( $a, 'filterall' ) );
    208208        $this->assertTrue( has_filter( 'all' ) );
    209209        $this->assertSame( 10, has_filter( 'all', array( $a, 'filterall' ) ) );
    210         $this->assertSame( $val, apply_filters( $tag, $val ) );
     210        $this->assertSame( $val, apply_filters( $hook_name, $val ) );
    211211
    212212        // Make sure our hook was called correctly.
    213213        $this->assertSame( 1, $a->get_call_count() );
    214         $this->assertSame( array( $tag ), $a->get_tags() );
     214        $this->assertSame( array( $hook_name ), $a->get_tags() );
    215215
    216216        // Now remove the filter, do it again, and make sure it's not called this time.
     
    218218        $this->assertFalse( has_filter( 'all', array( $a, 'filterall' ) ) );
    219219        $this->assertFalse( has_filter( 'all' ) );
    220         $this->assertSame( $val, apply_filters( $tag, $val ) );
     220        $this->assertSame( $val, apply_filters( $hook_name, $val ) );
    221221        // Call cound should remain at 1.
    222222        $this->assertSame( 1, $a->get_call_count() );
    223         $this->assertSame( array( $tag ), $a->get_tags() );
     223        $this->assertSame( array( $hook_name ), $a->get_tags() );
    224224    }
    225225
     
    228228     */
    229229    public function test_remove_all_filters_should_respect_the_priority_argument() {
    230         $a   = new MockAction();
    231         $tag = __FUNCTION__;
    232 
    233         add_filter( $tag, array( $a, 'filter' ), 12 );
    234         $this->assertTrue( has_filter( $tag ) );
     230        $a         = new MockAction();
     231        $hook_name = __FUNCTION__;
     232
     233        add_filter( $hook_name, array( $a, 'filter' ), 12 );
     234        $this->assertTrue( has_filter( $hook_name ) );
    235235
    236236        // Should not be removed.
    237         remove_all_filters( $tag, 11 );
    238         $this->assertTrue( has_filter( $tag ) );
    239 
    240         remove_all_filters( $tag, 12 );
    241         $this->assertFalse( has_filter( $tag ) );
     237        remove_all_filters( $hook_name, 11 );
     238        $this->assertTrue( has_filter( $hook_name ) );
     239
     240        remove_all_filters( $hook_name, 12 );
     241        $this->assertFalse( has_filter( $hook_name ) );
    242242    }
    243243
     
    246246     */
    247247    public function test_filter_with_ref_value() {
    248         $obj = new stdClass();
    249         $ref = &$obj;
    250         $a   = new MockAction();
    251         $tag = __FUNCTION__;
    252 
    253         add_action( $tag, array( $a, 'filter' ) );
    254 
    255         $filtered = apply_filters( $tag, $ref );
     248        $obj       = new stdClass();
     249        $ref       = &$obj;
     250        $a         = new MockAction();
     251        $hook_name = __FUNCTION__;
     252
     253        add_action( $hook_name, array( $a, 'filter' ) );
     254
     255        $filtered = apply_filters( $hook_name, $ref );
    256256
    257257        $args = $a->get_args();
     
    268268     */
    269269    public function test_filter_with_ref_argument() {
    270         $obj = new stdClass();
    271         $ref = &$obj;
    272         $a   = new MockAction();
    273         $tag = __FUNCTION__;
    274         $val = 'Hello';
    275 
    276         add_action( $tag, array( $a, 'filter' ), 10, 2 );
    277 
    278         apply_filters( $tag, $val, $ref );
     270        $obj       = new stdClass();
     271        $ref       = &$obj;
     272        $a         = new MockAction();
     273        $hook_name = __FUNCTION__;
     274        $val       = 'Hello';
     275
     276        add_action( $hook_name, array( $a, 'filter' ), 10, 2 );
     277
     278        apply_filters( $hook_name, $val, $ref );
    279279
    280280        $args = $a->get_args();
     
    289289     */
    290290    public function test_filter_ref_array() {
    291         $obj = new stdClass();
    292         $a   = new MockAction();
    293         $tag = __FUNCTION__;
    294 
    295         add_action( $tag, array( $a, 'filter' ) );
    296 
    297         apply_filters_ref_array( $tag, array( &$obj ) );
     291        $obj       = new stdClass();
     292        $a         = new MockAction();
     293        $hook_name = __FUNCTION__;
     294
     295        add_action( $hook_name, array( $a, 'filter' ) );
     296
     297        apply_filters_ref_array( $hook_name, array( &$obj ) );
    298298
    299299        $args = $a->get_args();
     
    308308     */
    309309    public function test_filter_ref_array_result() {
    310         $obj = new stdClass();
    311         $a   = new MockAction();
    312         $b   = new MockAction();
    313         $tag = __FUNCTION__;
    314 
    315         add_action( $tag, array( $a, 'filter_append' ), 10, 2 );
    316         add_action( $tag, array( $b, 'filter_append' ), 10, 2 );
    317 
    318         $result = apply_filters_ref_array( $tag, array( 'string', &$obj ) );
     310        $obj       = new stdClass();
     311        $a         = new MockAction();
     312        $b         = new MockAction();
     313        $hook_name = __FUNCTION__;
     314
     315        add_action( $hook_name, array( $a, 'filter_append' ), 10, 2 );
     316        add_action( $hook_name, array( $b, 'filter_append' ), 10, 2 );
     317
     318        $result = apply_filters_ref_array( $hook_name, array( 'string', &$obj ) );
    319319
    320320        $this->assertSame( $result, 'string_append_append' );
     
    338338     */
    339339    public function test_has_filter_after_remove_all_filters() {
    340         $a   = new MockAction();
    341         $tag = __FUNCTION__;
     340        $a         = new MockAction();
     341        $hook_name = __FUNCTION__;
    342342
    343343        // No priority.
    344         add_filter( $tag, array( $a, 'filter' ), 11 );
    345         add_filter( $tag, array( $a, 'filter' ), 12 );
    346         $this->assertTrue( has_filter( $tag ) );
    347 
    348         remove_all_filters( $tag );
    349         $this->assertFalse( has_filter( $tag ) );
     344        add_filter( $hook_name, array( $a, 'filter' ), 11 );
     345        add_filter( $hook_name, array( $a, 'filter' ), 12 );
     346        $this->assertTrue( has_filter( $hook_name ) );
     347
     348        remove_all_filters( $hook_name );
     349        $this->assertFalse( has_filter( $hook_name ) );
    350350
    351351        // Remove priorities one at a time.
    352         add_filter( $tag, array( $a, 'filter' ), 11 );
    353         add_filter( $tag, array( $a, 'filter' ), 12 );
    354         $this->assertTrue( has_filter( $tag ) );
    355 
    356         remove_all_filters( $tag, 11 );
    357         remove_all_filters( $tag, 12 );
    358         $this->assertFalse( has_filter( $tag ) );
     352        add_filter( $hook_name, array( $a, 'filter' ), 11 );
     353        add_filter( $hook_name, array( $a, 'filter' ), 12 );
     354        $this->assertTrue( has_filter( $hook_name ) );
     355
     356        remove_all_filters( $hook_name, 11 );
     357        remove_all_filters( $hook_name, 12 );
     358        $this->assertFalse( has_filter( $hook_name ) );
    359359    }
    360360
     
    413413
    414414    private $current_priority;
     415
    415416    /**
    416417     * @ticket 39007
     
    426427    public function current_priority_action() {
    427428        global $wp_filter;
     429
    428430        $this->current_priority = $wp_filter[ current_filter() ]->current_priority();
    429431    }
  • trunk/tests/phpunit/tests/hooks/addFilter.php

    r52389 r53804  
    1515        $callback      = '__return_null';
    1616        $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 );
    2424        $this->assertSame( $callback, $hook->callbacks[ $priority ][ $function_index ]['function'] );
    2525        $this->assertSame( $accepted_args, $hook->callbacks[ $priority ][ $function_index ]['accepted_args'] );
     
    3030        $callback      = array( $a, 'action' );
    3131        $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 );
    3939        $this->assertSame( $callback, $hook->callbacks[ $priority ][ $function_index ]['function'] );
    4040        $this->assertSame( $accepted_args, $hook->callbacks[ $priority ][ $function_index ]['accepted_args'] );
     
    4444        $callback      = array( 'MockAction', 'action' );
    4545        $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 );
    5353        $this->assertSame( $callback, $hook->callbacks[ $priority ][ $function_index ]['function'] );
    5454        $this->assertSame( $accepted_args, $hook->callbacks[ $priority ][ $function_index ]['accepted_args'] );
     
    5959        $callback_two  = '__return_false';
    6060        $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 );
    6969        $this->assertCount( 2, $hook->callbacks[ $priority ] );
    7070    }
     
    7474        $callback_two  = '__return_false';
    7575        $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 );
    8484        $this->assertCount( 1, $hook->callbacks[ $priority ] );
    8585        $this->assertCount( 1, $hook->callbacks[ $priority + 1 ] );
     
    8989        $callback      = '__return_null';
    9090        $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 );
    9999        $this->assertCount( 1, $hook->callbacks[ $priority ] );
    100100    }
     
    103103        $callback      = '__return_null';
    104104        $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 );
    113113        $this->assertCount( 1, $hook->callbacks[ $priority ] );
    114114        $this->assertCount( 1, $hook->callbacks[ $priority + 1 ] );
     
    116116
    117117    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 );
    127127
    128128        $this->assertSame( array( 5, 8, 10 ), array_keys( $hook->callbacks ) );
     
    130130
    131131    public function test_remove_and_add() {
    132         $this->hook = new Wp_Hook();
     132        $this->hook = new WP_Hook();
    133133
    134134        $this->hook->add_filter( 'remove_and_add', '__return_empty_string', 10, 0 );
     
    144144
    145145    public function test_remove_and_add_last_filter() {
    146         $this->hook = new Wp_Hook();
     146        $this->hook = new WP_Hook();
    147147
    148148        $this->hook->add_filter( 'remove_and_add', '__return_empty_string', 10, 0 );
     
    158158
    159159    public function test_remove_and_recurse_and_add() {
    160         $this->hook = new Wp_Hook();
     160        $this->hook = new WP_Hook();
    161161
    162162        $this->hook->add_filter( 'remove_and_add', '__return_empty_string', 10, 0 );
     
    203203
    204204    public function test_remove_and_add_action() {
    205         $this->hook          = new Wp_Hook();
     205        $this->hook          = new WP_Hook();
    206206        $this->action_output = '';
    207207
     
    218218
    219219    public function test_remove_and_add_last_action() {
    220         $this->hook          = new Wp_Hook();
     220        $this->hook          = new WP_Hook();
    221221        $this->action_output = '';
    222222
     
    233233
    234234    public function test_remove_and_recurse_and_add_action() {
    235         $this->hook          = new Wp_Hook();
     235        $this->hook          = new WP_Hook();
    236236        $this->action_output = '';
    237237
  • trunk/tests/phpunit/tests/hooks/applyFilters.php

    r52389 r53804  
    1313        $callback      = array( $a, 'filter' );
    1414        $hook          = new WP_Hook();
    15         $tag           = __FUNCTION__;
     15        $hook_name     = __FUNCTION__;
    1616        $priority      = 1;
    1717        $accepted_args = 2;
    1818        $arg           = __FUNCTION__ . '_arg';
    1919
    20         $hook->add_filter( $tag, $callback, $priority, $accepted_args );
     20        $hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
    2121
    2222        $returned = $hook->apply_filters( $arg, array( $arg ) );
     
    3030        $callback      = array( $a, 'filter' );
    3131        $hook          = new WP_Hook();
    32         $tag           = __FUNCTION__;
     32        $hook_name     = __FUNCTION__;
    3333        $priority      = 1;
    3434        $accepted_args = 2;
    3535        $arg           = __FUNCTION__ . '_arg';
    3636
    37         $hook->add_filter( $tag, $callback, $priority, $accepted_args );
     37        $hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
    3838
    3939        $returned_one = $hook->apply_filters( $arg, array( $arg ) );
  • trunk/tests/phpunit/tests/hooks/doAction.php

    r52389 r53804  
    2121        $callback      = array( $a, 'action' );
    2222        $hook          = new WP_Hook();
    23         $tag           = __FUNCTION__;
     23        $hook_name     = __FUNCTION__;
    2424        $priority      = 1;
    2525        $accepted_args = 2;
    2626        $arg           = __FUNCTION__ . '_arg';
    2727
    28         $hook->add_filter( $tag, $callback, $priority, $accepted_args );
     28        $hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
    2929        $hook->do_action( array( $arg ) );
    3030
     
    3636        $callback      = array( $a, 'filter' );
    3737        $hook          = new WP_Hook();
    38         $tag           = __FUNCTION__;
     38        $hook_name     = __FUNCTION__;
    3939        $priority      = 1;
    4040        $accepted_args = 2;
    4141        $arg           = __FUNCTION__ . '_arg';
    4242
    43         $hook->add_filter( $tag, $callback, $priority, $accepted_args );
     43        $hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
    4444        $hook->do_action( array( $arg ) );
    4545        $hook->do_action( array( $arg ) );
     
    5454        $callback_two  = array( $b, 'filter' );
    5555        $hook          = new WP_Hook();
    56         $tag           = __FUNCTION__;
     56        $hook_name     = __FUNCTION__;
    5757        $priority      = 1;
    5858        $accepted_args = 2;
    5959        $arg           = __FUNCTION__ . '_arg';
    6060
    61         $hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
    62         $hook->add_filter( $tag, $callback_two, $priority, $accepted_args );
     61        $hook->add_filter( $hook_name, $callback_one, $priority, $accepted_args );
     62        $hook->add_filter( $hook_name, $callback_two, $priority, $accepted_args );
    6363        $hook->do_action( array( $arg ) );
    6464
     
    7373        $callback_two  = array( $b, 'filter' );
    7474        $hook          = new WP_Hook();
    75         $tag           = __FUNCTION__;
     75        $hook_name     = __FUNCTION__;
    7676        $priority      = 1;
    7777        $accepted_args = 2;
    7878        $arg           = __FUNCTION__ . '_arg';
    7979
    80         $hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
    81         $hook->add_filter( $tag, $callback_two, $priority + 1, $accepted_args );
     80        $hook->add_filter( $hook_name, $callback_one, $priority, $accepted_args );
     81        $hook->add_filter( $hook_name, $callback_two, $priority + 1, $accepted_args );
    8282        $hook->do_action( array( $arg ) );
    8383
     
    8989        $callback      = array( $this, '_action_callback' );
    9090        $hook          = new WP_Hook();
    91         $tag           = __FUNCTION__;
     91        $hook_name     = __FUNCTION__;
    9292        $priority      = 1;
    9393        $accepted_args = 0;
    9494        $arg           = __FUNCTION__ . '_arg';
    9595
    96         $hook->add_filter( $tag, $callback, $priority, $accepted_args );
     96        $hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
    9797        $hook->do_action( array( $arg ) );
    9898
     
    103103        $callback      = array( $this, '_action_callback' );
    104104        $hook          = new WP_Hook();
    105         $tag           = __FUNCTION__;
     105        $hook_name     = __FUNCTION__;
    106106        $priority      = 1;
    107107        $accepted_args = 1;
    108108        $arg           = __FUNCTION__ . '_arg';
    109109
    110         $hook->add_filter( $tag, $callback, $priority, $accepted_args );
     110        $hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
    111111        $hook->do_action( array( $arg ) );
    112112
     
    117117        $callback      = array( $this, '_action_callback' );
    118118        $hook          = new WP_Hook();
    119         $tag           = __FUNCTION__;
     119        $hook_name     = __FUNCTION__;
    120120        $priority      = 100;
    121121        $accepted_args = 1000;
    122122        $arg           = __FUNCTION__ . '_arg';
    123123
    124         $hook->add_filter( $tag, $callback, $priority, $accepted_args );
     124        $hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
    125125        $hook->do_action( array( $arg ) );
    126126
  • trunk/tests/phpunit/tests/hooks/doAllHook.php

    r52389 r53804  
    1313        $callback      = array( $a, 'action' );
    1414        $hook          = new WP_Hook();
    15         $tag           = 'all';
     15        $hook_name     = 'all';
    1616        $priority      = 1;
    1717        $accepted_args = 2;
    1818        $arg           = 'all_arg';
    1919
    20         $hook->add_filter( $tag, $callback, $priority, $accepted_args );
     20        $hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
    2121        $args = array( $arg );
    2222        $hook->do_all_hook( $args );
  • trunk/tests/phpunit/tests/hooks/hasFilter.php

    r52389 r53804  
    1212        $callback      = '__return_null';
    1313        $hook          = new WP_Hook();
    14         $tag           = __FUNCTION__;
     14        $hook_name     = __FUNCTION__;
    1515        $priority      = 1;
    1616        $accepted_args = 2;
    1717
    18         $hook->add_filter( $tag, $callback, $priority, $accepted_args );
     18        $hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
    1919
    20         $this->assertSame( $priority, $hook->has_filter( $tag, $callback ) );
     20        $this->assertSame( $priority, $hook->has_filter( $hook_name, $callback ) );
    2121    }
    2222
     
    2525        $callback      = array( $a, 'action' );
    2626        $hook          = new WP_Hook();
    27         $tag           = __FUNCTION__;
     27        $hook_name     = __FUNCTION__;
    2828        $priority      = 1;
    2929        $accepted_args = 2;
    3030
    31         $hook->add_filter( $tag, $callback, $priority, $accepted_args );
     31        $hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
    3232
    33         $this->assertSame( $priority, $hook->has_filter( $tag, $callback ) );
     33        $this->assertSame( $priority, $hook->has_filter( $hook_name, $callback ) );
    3434    }
    3535
     
    3737        $callback      = array( 'MockAction', 'action' );
    3838        $hook          = new WP_Hook();
    39         $tag           = __FUNCTION__;
     39        $hook_name     = __FUNCTION__;
    4040        $priority      = 1;
    4141        $accepted_args = 2;
    4242
    43         $hook->add_filter( $tag, $callback, $priority, $accepted_args );
     43        $hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
    4444
    45         $this->assertSame( $priority, $hook->has_filter( $tag, $callback ) );
     45        $this->assertSame( $priority, $hook->has_filter( $hook_name, $callback ) );
    4646    }
    4747
     
    4949        $callback      = '__return_null';
    5050        $hook          = new WP_Hook();
    51         $tag           = __FUNCTION__;
     51        $hook_name     = __FUNCTION__;
    5252        $priority      = 1;
    5353        $accepted_args = 2;
    5454
    55         $hook->add_filter( $tag, $callback, $priority, $accepted_args );
     55        $hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
    5656
    5757        $this->assertTrue( $hook->has_filter() );
     
    6464
    6565    public function test_not_has_filter_with_callback() {
    66         $callback = '__return_null';
    67         $hook     = new WP_Hook();
    68         $tag      = __FUNCTION__;
     66        $callback  = '__return_null';
     67        $hook      = new WP_Hook();
     68        $hook_name = __FUNCTION__;
    6969
    70         $this->assertFalse( $hook->has_filter( $tag, $callback ) );
     70        $this->assertFalse( $hook->has_filter( $hook_name, $callback ) );
    7171    }
    7272
     
    7474        $callback      = '__return_null';
    7575        $hook          = new WP_Hook();
    76         $tag           = __FUNCTION__;
     76        $hook_name     = __FUNCTION__;
    7777        $priority      = 1;
    7878        $accepted_args = 2;
    7979
    80         $hook->add_filter( $tag, $callback, $priority, $accepted_args );
     80        $hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
    8181
    82         $this->assertFalse( $hook->has_filter( $tag, '__return_false' ) );
     82        $this->assertFalse( $hook->has_filter( $hook_name, '__return_false' ) );
    8383    }
    8484}
  • trunk/tests/phpunit/tests/hooks/hasFilters.php

    r52389 r53804  
    1212        $callback      = '__return_null';
    1313        $hook          = new WP_Hook();
    14         $tag           = __FUNCTION__;
     14        $hook_name     = __FUNCTION__;
    1515        $priority      = 1;
    1616        $accepted_args = 2;
    1717
    18         $hook->add_filter( $tag, $callback, $priority, $accepted_args );
     18        $hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
    1919
    2020        $this->assertTrue( $hook->has_filters() );
     
    2929        $callback      = '__return_null';
    3030        $hook          = new WP_Hook();
    31         $tag           = __FUNCTION__;
     31        $hook_name     = __FUNCTION__;
    3232        $priority      = 1;
    3333        $accepted_args = 2;
    3434
    35         $hook->add_filter( $tag, $callback, $priority, $accepted_args );
    36         $hook->remove_filter( $tag, $callback, $priority );
     35        $hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
     36        $hook->remove_filter( $hook_name, $callback, $priority );
    3737        $this->assertFalse( $hook->has_filters() );
    3838    }
     
    4141        $callback      = '__return_null';
    4242        $hook          = new WP_Hook();
    43         $tag           = __FUNCTION__;
     43        $hook_name     = __FUNCTION__;
    4444        $priority      = 1;
    4545        $accepted_args = 2;
    4646
    47         $hook->add_filter( $tag, $callback, $priority, $accepted_args );
    48         $function_key = _wp_filter_build_unique_id( $tag, $callback, $priority );
     47        $hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
     48        $function_key = _wp_filter_build_unique_id( $hook_name, $callback, $priority );
    4949        unset( $hook->callbacks[ $priority ][ $function_key ] );
    5050
  • trunk/tests/phpunit/tests/hooks/iterator.php

    r52389 r53804  
    1313        $callback_two  = '__return_false';
    1414        $hook          = new WP_Hook();
    15         $tag           = __FUNCTION__;
     15        $hook_name     = __FUNCTION__;
    1616        $priority      = 1;
    1717        $accepted_args = 2;
    1818
    19         $hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
    20         $hook->add_filter( $tag, $callback_two, $priority + 1, $accepted_args );
     19        $hook->add_filter( $hook_name, $callback_one, $priority, $accepted_args );
     20        $hook->add_filter( $hook_name, $callback_two, $priority + 1, $accepted_args );
    2121
    2222        $functions  = array();
  • trunk/tests/phpunit/tests/hooks/preinitHooks.php

    r52389 r53804  
    1010
    1111    public function test_array_to_hooks() {
    12         $tag1      = __FUNCTION__ . '_1';
    13         $priority1 = 1;
    14         $tag2      = __FUNCTION__ . '_2';
    15         $priority2 = 2;
    16         $filters   = array(
    17             $tag1 => array(
     12        $hook_name1 = __FUNCTION__ . '_1';
     13        $priority1  = 1;
     14        $hook_name2 = __FUNCTION__ . '_2';
     15        $priority2  = 2;
     16        $filters    = array(
     17            $hook_name1 => array(
    1818                $priority1 => array(
    1919                    'test1' => array(
     
    2323                ),
    2424            ),
    25             $tag2 => array(
     25            $hook_name2 => array(
    2626                $priority2 => array(
    2727                    'test1' => array(
     
    3535        $hooks = WP_Hook::build_preinitialized_hooks( $filters );
    3636
    37         $this->assertSame( $priority1, $hooks[ $tag1 ]->has_filter( $tag1, '__return_false' ) );
    38         $this->assertSame( $priority2, $hooks[ $tag2 ]->has_filter( $tag2, '__return_null' ) );
     37        $this->assertSame( $priority1, $hooks[ $hook_name1 ]->has_filter( $hook_name1, '__return_false' ) );
     38        $this->assertSame( $priority2, $hooks[ $hook_name2 ]->has_filter( $hook_name2, '__return_null' ) );
    3939    }
    4040}
  • trunk/tests/phpunit/tests/hooks/removeAllFilters.php

    r52389 r53804  
    1212        $callback      = '__return_null';
    1313        $hook          = new WP_Hook();
    14         $tag           = __FUNCTION__;
     14        $hook_name     = __FUNCTION__;
    1515        $priority      = 1;
    1616        $accepted_args = 2;
    1717
    18         $hook->add_filter( $tag, $callback, $priority, $accepted_args );
     18        $hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
    1919
    2020        $hook->remove_all_filters();
     
    2727        $callback_two  = '__return_false';
    2828        $hook          = new WP_Hook();
    29         $tag           = __FUNCTION__;
     29        $hook_name     = __FUNCTION__;
    3030        $priority      = 1;
    3131        $accepted_args = 2;
    3232
    33         $hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
    34         $hook->add_filter( $tag, $callback_two, $priority + 1, $accepted_args );
     33        $hook->add_filter( $hook_name, $callback_one, $priority, $accepted_args );
     34        $hook->add_filter( $hook_name, $callback_two, $priority + 1, $accepted_args );
    3535
    3636        $hook->remove_all_filters( $priority );
    3737
    38         $this->assertFalse( $hook->has_filter( $tag, $callback_one ) );
     38        $this->assertFalse( $hook->has_filter( $hook_name, $callback_one ) );
    3939        $this->assertTrue( $hook->has_filters() );
    40         $this->assertSame( $priority + 1, $hook->has_filter( $tag, $callback_two ) );
     40        $this->assertSame( $priority + 1, $hook->has_filter( $hook_name, $callback_two ) );
    4141    }
    4242}
  • trunk/tests/phpunit/tests/hooks/removeFilter.php

    r52389 r53804  
    1212        $callback      = '__return_null';
    1313        $hook          = new WP_Hook();
    14         $tag           = __FUNCTION__;
     14        $hook_name     = __FUNCTION__;
    1515        $priority      = 1;
    1616        $accepted_args = 2;
    1717
    18         $hook->add_filter( $tag, $callback, $priority, $accepted_args );
    19         $hook->remove_filter( $tag, $callback, $priority );
     18        $hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
     19        $hook->remove_filter( $hook_name, $callback, $priority );
    2020
    2121        $this->assertArrayNotHasKey( $priority, $hook->callbacks );
     
    2626        $callback      = array( $a, 'action' );
    2727        $hook          = new WP_Hook();
    28         $tag           = __FUNCTION__;
     28        $hook_name     = __FUNCTION__;
    2929        $priority      = 1;
    3030        $accepted_args = 2;
    3131
    32         $hook->add_filter( $tag, $callback, $priority, $accepted_args );
    33         $hook->remove_filter( $tag, $callback, $priority );
     32        $hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
     33        $hook->remove_filter( $hook_name, $callback, $priority );
    3434
    3535        $this->assertArrayNotHasKey( $priority, $hook->callbacks );
     
    3939        $callback      = array( 'MockAction', 'action' );
    4040        $hook          = new WP_Hook();
    41         $tag           = __FUNCTION__;
     41        $hook_name     = __FUNCTION__;
    4242        $priority      = 1;
    4343        $accepted_args = 2;
    4444
    45         $hook->add_filter( $tag, $callback, $priority, $accepted_args );
    46         $hook->remove_filter( $tag, $callback, $priority );
     45        $hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
     46        $hook->remove_filter( $hook_name, $callback, $priority );
    4747
    4848        $this->assertArrayNotHasKey( $priority, $hook->callbacks );
     
    5353        $callback_two  = '__return_false';
    5454        $hook          = new WP_Hook();
    55         $tag           = __FUNCTION__;
     55        $hook_name     = __FUNCTION__;
    5656        $priority      = 1;
    5757        $accepted_args = 2;
    5858
    59         $hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
    60         $hook->add_filter( $tag, $callback_two, $priority, $accepted_args );
     59        $hook->add_filter( $hook_name, $callback_one, $priority, $accepted_args );
     60        $hook->add_filter( $hook_name, $callback_two, $priority, $accepted_args );
    6161
    62         $hook->remove_filter( $tag, $callback_one, $priority );
     62        $hook->remove_filter( $hook_name, $callback_one, $priority );
    6363
    6464        $this->assertCount( 1, $hook->callbacks[ $priority ] );
     
    6969        $callback_two  = '__return_false';
    7070        $hook          = new WP_Hook();
    71         $tag           = __FUNCTION__;
     71        $hook_name     = __FUNCTION__;
    7272        $priority      = 1;
    7373        $accepted_args = 2;
    7474
    75         $hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
    76         $hook->add_filter( $tag, $callback_two, $priority + 1, $accepted_args );
     75        $hook->add_filter( $hook_name, $callback_one, $priority, $accepted_args );
     76        $hook->add_filter( $hook_name, $callback_two, $priority + 1, $accepted_args );
    7777
    78         $hook->remove_filter( $tag, $callback_one, $priority );
     78        $hook->remove_filter( $hook_name, $callback_one, $priority );
    7979        $this->assertArrayNotHasKey( $priority, $hook->callbacks );
    8080        $this->assertCount( 1, $hook->callbacks[ $priority + 1 ] );
Note: See TracChangeset for help on using the changeset viewer.