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/filters.php

    r46689 r47122  
    1616        $this->assertEquals( $val, apply_filters( $tag, $val ) );
    1717
    18         // only one event occurred for the hook, with empty args
    19         $this->assertEquals( 1, $a->get_call_count() );
    20         // only our hook was called
     18        // Only one event occurred for the hook, with empty args.
     19        $this->assertEquals( 1, $a->get_call_count() );
     20        // Only our hook was called.
    2121        $this->assertEquals( array( $tag ), $a->get_tags() );
    2222
     
    3434        $this->assertEquals( $val, apply_filters( $tag, $val ) );
    3535
    36         // make sure our hook was called correctly
    37         $this->assertEquals( 1, $a->get_call_count() );
    38         $this->assertEquals( array( $tag ), $a->get_tags() );
    39 
    40         // now remove the filter, do it again, and make sure it's not called this time
     36        // Make sure our hook was called correctly.
     37        $this->assertEquals( 1, $a->get_call_count() );
     38        $this->assertEquals( array( $tag ), $a->get_tags() );
     39
     40        // Now remove the filter, do it again, and make sure it's not called this time.
    4141        remove_filter( $tag, array( $a, 'filter' ) );
    4242        $this->assertEquals( $val, apply_filters( $tag, $val ) );
     
    6060    }
    6161
    62     // one tag with multiple filters
     62    // One tag with multiple filters.
    6363    function test_multiple_filters() {
    6464        $a1  = new MockAction();
     
    6767        $val = __FUNCTION__ . '_val';
    6868
    69         // add both filters to the hook
     69        // Add both filters to the hook.
    7070        add_filter( $tag, array( $a1, 'filter' ) );
    7171        add_filter( $tag, array( $a2, 'filter' ) );
     
    7373        $this->assertEquals( $val, apply_filters( $tag, $val ) );
    7474
    75         // both filters called once each
     75        // Both filters called once each.
    7676        $this->assertEquals( 1, $a1->get_call_count() );
    7777        $this->assertEquals( 1, $a2->get_call_count() );
     
    8585
    8686        add_filter( $tag, array( $a, 'filter' ), 10, 2 );
    87         // call the filter with a single argument
     87        // Call the filter with a single argument.
    8888        $this->assertEquals( $val, apply_filters( $tag, $val, $arg1 ) );
    8989
     
    101101        $arg2 = __FUNCTION__ . '_arg2';
    102102
    103         // a1 accepts two arguments, a2 doesn't
     103        // $a1 accepts two arguments, $a2 doesn't.
    104104        add_filter( $tag, array( $a1, 'filter' ), 10, 3 );
    105105        add_filter( $tag, array( $a2, 'filter' ) );
    106         // call the filter with two arguments
     106        // Call the filter with two arguments.
    107107        $this->assertEquals( $val, apply_filters( $tag, $val, $arg1, $arg2 ) );
    108108
    109         // a1 should be called with both args
     109        // $a1 should be called with both args.
    110110        $this->assertEquals( 1, $a1->get_call_count() );
    111111        $argsvar1 = $a1->get_args();
    112112        $this->assertEquals( array( $val, $arg1, $arg2 ), array_pop( $argsvar1 ) );
    113113
    114         // a2 should be called with one only
     114        // $a2 should be called with one only.
    115115        $this->assertEquals( 1, $a2->get_call_count() );
    116116        $argsvar2 = $a2->get_args();
     
    123123        $val = __FUNCTION__ . '_val';
    124124
    125         // make two filters with different priorities
     125        // Make two filters with different priorities.
    126126        add_filter( $tag, array( $a, 'filter' ), 10 );
    127127        add_filter( $tag, array( $a, 'filter2' ), 9 );
    128128        $this->assertEquals( $val, apply_filters( $tag, $val ) );
    129129
    130         // there should be two events, one per filter
     130        // There should be two events, one per filter.
    131131        $this->assertEquals( 2, $a->get_call_count() );
    132132
    133133        $expected = array(
    134             // filter2 is called first because it has priority 9
     134            // 'filter2' is called first because it has priority 9.
    135135            array(
    136136                'filter' => 'filter2',
     
    138138                'args'   => array( $val ),
    139139            ),
    140             // filter 1 is called second
     140            // 'filter' is called second.
    141141            array(
    142142                'filter' => 'filter',
     
    155155        $val  = __FUNCTION__ . '_val';
    156156
    157         // add an 'all' filter
     157        // Add an 'all' filter.
    158158        add_filter( 'all', array( $a, 'filterall' ) );
    159         // do some filters
     159        // Apply some filters.
    160160        $this->assertEquals( $val, apply_filters( $tag1, $val ) );
    161161        $this->assertEquals( $val, apply_filters( $tag2, $val ) );
     
    163163        $this->assertEquals( $val, apply_filters( $tag1, $val ) );
    164164
    165         // our filter should have been called once for each apply_filters call
     165        // Our filter should have been called once for each apply_filters call.
    166166        $this->assertEquals( 4, $a->get_call_count() );
    167         // the right hooks should have been called in order
     167        // The right hooks should have been called in order.
    168168        $this->assertEquals( array( $tag1, $tag2, $tag1, $tag1 ), $a->get_tags() );
    169169
     
    183183        $this->assertEquals( $val, apply_filters( $tag, $val ) );
    184184
    185         // make sure our hook was called correctly
    186         $this->assertEquals( 1, $a->get_call_count() );
    187         $this->assertEquals( array( $tag ), $a->get_tags() );
    188 
    189         // now remove the filter, do it again, and make sure it's not called this time
     185        // Make sure our hook was called correctly.
     186        $this->assertEquals( 1, $a->get_call_count() );
     187        $this->assertEquals( array( $tag ), $a->get_tags() );
     188
     189        // Now remove the filter, do it again, and make sure it's not called this time.
    190190        remove_filter( 'all', array( $a, 'filterall' ) );
    191191        $this->assertFalse( has_filter( 'all', array( $a, 'filterall' ) ) );
    192192        $this->assertFalse( has_filter( 'all' ) );
    193193        $this->assertEquals( $val, apply_filters( $tag, $val ) );
    194         // call cound should remain at 1
     194        // Call cound should remain at 1.
    195195        $this->assertEquals( 1, $a->get_call_count() );
    196196        $this->assertEquals( array( $tag ), $a->get_tags() );
     
    230230        $args = $a->get_args();
    231231        $this->assertSame( $args[0][0], $obj );
    232         // just in case we don't trust assertSame
     232        // Just in case we don't trust assertSame().
    233233        $obj->foo = true;
    234234        $this->assertFalse( empty( $args[0][0]->foo ) );
     
    253253        $args = $a->get_args();
    254254        $this->assertSame( $args[0][1], $obj );
    255         // just in case we don't trust assertSame
     255        // Just in case we don't trust assertSame().
    256256        $obj->foo = true;
    257257        $this->assertFalse( empty( $args[0][1]->foo ) );
     
    259259        $args = $b->get_args();
    260260        $this->assertSame( $args[0][1], $obj );
    261         // just in case we don't trust assertSame
     261        // Just in case we don't trust assertSame().
    262262        $obj->foo = true;
    263263        $this->assertFalse( empty( $args[0][1]->foo ) );
     
    278278        $val = __FUNCTION__ . '_val';
    279279
    280         // No priority
     280        // No priority.
    281281        add_filter( $tag, array( $a, 'filter' ), 11 );
    282282        add_filter( $tag, array( $a, 'filter' ), 12 );
     
    286286        $this->assertFalse( has_filter( $tag ) );
    287287
    288         // Remove priorities one at a time
     288        // Remove priorities one at a time.
    289289        add_filter( $tag, array( $a, 'filter' ), 11 );
    290290        add_filter( $tag, array( $a, 'filter' ), 12 );
Note: See TracChangeset for help on using the changeset viewer.