Make WordPress Core


Ignore:
Timestamp:
01/29/2020 12:43:23 AM (6 years ago)
Author:
SergeyBiryukov
Message:

Docs: Improve inline comments per the documentation standards.

Includes minor code layout fixes for better readability.

See #48303.

File:
1 edited

Legend:

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

    r46707 r47122  
    1515        do_action( $tag );
    1616
    17         // only one event occurred for the hook, with empty args
     17        // Only one event occurred for the hook, with empty args.
    1818        $this->assertEquals( 1, $a->get_call_count() );
    19         // only our hook was called
     19        // Only our hook was called.
    2020        $this->assertEquals( array( $tag ), $a->get_tags() );
    2121
     
    3232        do_action( $tag );
    3333
    34         // make sure our hook was called correctly
     34        // Make sure our hook was called correctly.
    3535        $this->assertEquals( 1, $a->get_call_count() );
    3636        $this->assertEquals( array( $tag ), $a->get_tags() );
    3737
    38         // now remove the action, do it again, and make sure it's not called this time
     38        // Now remove the action, do it again, and make sure it's not called this time.
    3939        remove_action( $tag, array( &$a, 'action' ) );
    4040        do_action( $tag );
     
    5858    }
    5959
    60     // one tag with multiple actions
     60    // One tag with multiple actions.
    6161    function test_multiple_actions() {
    6262        $a1  = new MockAction();
     
    6464        $tag = __FUNCTION__;
    6565
    66         // add both actions to the hook
     66        // Add both actions to the hook.
    6767        add_action( $tag, array( &$a1, 'action' ) );
    6868        add_action( $tag, array( &$a2, 'action' ) );
     
    7070        do_action( $tag );
    7171
    72         // both actions called once each
     72        // Both actions called once each.
    7373        $this->assertEquals( 1, $a1->get_call_count() );
    7474        $this->assertEquals( 1, $a2->get_call_count() );
     
    8181
    8282        add_action( $tag, array( &$a, 'action' ) );
    83         // call the action with a single argument
     83        // Call the action with a single argument.
    8484        do_action( $tag, $val );
    8585
     
    9797        $val2 = __FUNCTION__ . '_val2';
    9898
    99         // a1 accepts two arguments, a2 doesn't
     99        // $a1 accepts two arguments, $a2 doesn't.
    100100        add_action( $tag, array( &$a1, 'action' ), 10, 2 );
    101101        add_action( $tag, array( &$a2, 'action' ) );
    102         // call the action with two arguments
     102        // Call the action with two arguments.
    103103        do_action( $tag, $val1, $val2 );
    104104
    105105        $call_count = $a1->get_call_count();
    106         // a1 should be called with both args
     106        // $a1 should be called with both args.
    107107        $this->assertEquals( 1, $call_count );
    108108        $argsvar1 = $a1->get_args();
    109109        $this->assertEquals( array( $val1, $val2 ), array_pop( $argsvar1 ) );
    110110
    111         // a2 should be called with one only
     111        // $a2 should be called with one only.
    112112        $this->assertEquals( 1, $a2->get_call_count() );
    113113        $argsvar2 = $a2->get_args();
     
    130130        $val2 = __FUNCTION__ . '_val2';
    131131
    132         // a1 accepts two arguments, a2 doesn't, a3 accepts two arguments
     132        // $a1 accepts two arguments, $a2 doesn't, $a3 accepts two arguments.
    133133        add_action( $tag, array( &$a1, 'action' ), 10, 2 );
    134134        add_action( $tag, array( &$a2, 'action' ) );
    135135        add_action( $tag, array( &$a3, 'action' ), 10, 2 );
    136         // call the action with two arguments
     136        // Call the action with two arguments.
    137137        do_action( $tag, $val1, $val2 );
    138138
    139139        $call_count = $a1->get_call_count();
    140         // a1 should be called with both args
     140        // $a1 should be called with both args.
    141141        $this->assertEquals( 1, $call_count );
    142142        $argsvar1 = $a1->get_args();
    143143        $this->assertEquals( array( $val1, $val2 ), array_pop( $argsvar1 ) );
    144144
    145         // a2 should be called with one only
     145        // $a2 should be called with one only.
    146146        $this->assertEquals( 1, $a2->get_call_count() );
    147147        $argsvar2 = $a2->get_args();
    148148        $this->assertEquals( array( $val1 ), array_pop( $argsvar2 ) );
    149149
    150         // a3 should be called with both args
     150        // $a3 should be called with both args.
    151151        $this->assertEquals( 1, $a3->get_call_count() );
    152152        $argsvar3 = $a3->get_args();
     
    181181        do_action( $tag );
    182182
    183         // two events, one per action
     183        // Two events, one per action.
    184184        $this->assertEquals( 2, $a->get_call_count() );
    185185
    186186        $expected = array(
    187             // action2 is called first because it has priority 9
     187            // 'action2' is called first because it has priority 9.
    188188            array(
    189189                'action' => 'action2',
     
    191191                'args'   => array( '' ),
    192192            ),
    193             // action 1 is called second
     193            // 'action' is called second.
    194194            array(
    195195                'action' => 'action',
     
    206206        $tag2 = 'action2';
    207207
    208         // do action tag1 but not tag2
     208        // Do action $tag1 but not $tag2.
    209209        do_action( $tag1 );
    210210        $this->assertEquals( 1, did_action( $tag1 ) );
    211211        $this->assertEquals( 0, did_action( $tag2 ) );
    212212
    213         // do action tag2 a random number of times
     213        // Do action $tag2 a random number of times.
    214214        $count = rand( 0, 10 );
    215215        for ( $i = 0; $i < $count; $i++ ) {
     
    217217        }
    218218
    219         // tag1's count hasn't changed, tag2 should be correct
     219        // $tag1's count hasn't changed, $tag2 should be correct.
    220220        $this->assertEquals( 1, did_action( $tag1 ) );
    221221        $this->assertEquals( $count, did_action( $tag2 ) );
     
    228228        $tag2 = __FUNCTION__ . '_2';
    229229
    230         // add an 'all' action
     230        // Add an 'all' action.
    231231        add_action( 'all', array( &$a, 'action' ) );
    232232        $this->assertEquals( 10, has_filter( 'all', array( &$a, 'action' ) ) );
    233         // do some actions
     233        // Do some actions.
    234234        do_action( $tag1 );
    235235        do_action( $tag2 );
     
    237237        do_action( $tag1 );
    238238
    239         // our action should have been called once for each tag
     239        // Our action should have been called once for each tag.
    240240        $this->assertEquals( 4, $a->get_call_count() );
    241         // only our hook was called
     241        // Only our hook was called.
    242242        $this->assertEquals( array( $tag1, $tag2, $tag1, $tag1 ), $a->get_tags() );
    243243
     
    255255        do_action( $tag );
    256256
    257         // make sure our hook was called correctly
     257        // Make sure our hook was called correctly.
    258258        $this->assertEquals( 1, $a->get_call_count() );
    259259        $this->assertEquals( array( $tag ), $a->get_tags() );
    260260
    261         // now remove the action, do it again, and make sure it's not called this time
     261        // Now remove the action, do it again, and make sure it's not called this time.
    262262        remove_action( 'all', array( &$a, 'action' ) );
    263263        $this->assertFalse( has_filter( 'all', array( &$a, 'action' ) ) );
     
    278278        $args = $a->get_args();
    279279        $this->assertSame( $args[0][0], $obj );
    280         // just in case we don't trust assertSame
     280        // Just in case we don't trust assertSame().
    281281        $obj->foo = true;
    282282        $this->assertFalse( empty( $args[0][0]->foo ) );
     
    457457    function test_doing_filter() {
    458458        global $wp_current_filter;
    459         $wp_current_filter = array(); // Set to an empty array first
    460 
    461         $this->assertFalse( doing_filter() ); // No filter is passed in, and no filter is being processed
    462         $this->assertFalse( doing_filter( 'testing' ) ); // Filter is passed in but not being processed
     459        $wp_current_filter = array(); // Set to an empty array first.
     460
     461        $this->assertFalse( doing_filter() );            // No filter is passed in, and no filter is being processed.
     462        $this->assertFalse( doing_filter( 'testing' ) ); // Filter is passed in but not being processed.
    463463
    464464        $wp_current_filter[] = 'testing';
    465465
    466         $this->assertTrue( doing_filter() ); // No action is passed in, and a filter is being processed
    467         $this->assertTrue( doing_filter( 'testing' ) ); // Filter is passed in and is being processed
    468         $this->assertFalse( doing_filter( 'something_else' ) ); // Filter is passed in but not being processed
     466        $this->assertTrue( doing_filter() );                    // No action is passed in, and a filter is being processed.
     467        $this->assertTrue( doing_filter( 'testing' ) );         // Filter is passed in and is being processed.
     468        $this->assertFalse( doing_filter( 'something_else' ) ); // Filter is passed in but not being processed.
    469469
    470470        $wp_current_filter = array();
     
    476476    function test_doing_action() {
    477477        global $wp_current_filter;
    478         $wp_current_filter = array(); // Set to an empty array first
    479 
    480         $this->assertFalse( doing_action() ); // No action is passed in, and no filter is being processed
    481         $this->assertFalse( doing_action( 'testing' ) ); // Action is passed in but not being processed
     478        $wp_current_filter = array(); // Set to an empty array first.
     479
     480        $this->assertFalse( doing_action() );            // No action is passed in, and no filter is being processed.
     481        $this->assertFalse( doing_action( 'testing' ) ); // Action is passed in but not being processed.
    482482
    483483        $wp_current_filter[] = 'testing';
    484484
    485         $this->assertTrue( doing_action() ); // No action is passed in, and a filter is being processed
    486         $this->assertTrue( doing_action( 'testing' ) ); // Action is passed in and is being processed
    487         $this->assertFalse( doing_action( 'something_else' ) ); // Action is passed in but not being processed
     485        $this->assertTrue( doing_action() );                    // No action is passed in, and a filter is being processed.
     486        $this->assertTrue( doing_action( 'testing' ) );         // Action is passed in and is being processed.
     487        $this->assertFalse( doing_action( 'something_else' ) ); // Action is passed in but not being processed.
    488488
    489489        $wp_current_filter = array();
     
    494494     */
    495495    function test_doing_filter_real() {
    496         $this->assertFalse( doing_filter() ); // No filter is passed in, and no filter is being processed
    497         $this->assertFalse( doing_filter( 'testing' ) ); // Filter is passed in but not being processed
     496        $this->assertFalse( doing_filter() );            // No filter is passed in, and no filter is being processed.
     497        $this->assertFalse( doing_filter( 'testing' ) ); // Filter is passed in but not being processed.
    498498
    499499        add_filter( 'testing', array( $this, 'apply_testing_filter' ) );
     
    506506        $this->assertTrue( $this->apply_testing_filter );
    507507
    508         $this->assertFalse( doing_filter() ); // No longer doing any filters
    509         $this->assertFalse( doing_filter( 'testing' ) ); // No longer doing this filter
     508        $this->assertFalse( doing_filter() );            // No longer doing any filters.
     509        $this->assertFalse( doing_filter( 'testing' ) ); // No longer doing this filter.
    510510    }
    511511
Note: See TracChangeset for help on using the changeset viewer.