Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (9 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

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

    r40965 r42343  
    1010                parent::setUp();
    1111                // make sure the schedule is clear
    12                 _set_cron_array(array());
     12                _set_cron_array( array() );
    1313        }
    1414
    1515        function tearDown() {
    1616                // make sure the schedule is clear
    17                 _set_cron_array(array());
     17                _set_cron_array( array() );
    1818                parent::tearDown();
    1919        }
    … …  
    2222                // nothing scheduled
    2323                $hook = __FUNCTION__;
    24                 $this->assertFalse(wp_get_schedule($hook));
     24                $this->assertFalse( wp_get_schedule( $hook ) );
    2525        }
    2626
    2727        function test_schedule_event_single() {
    2828                // schedule an event and make sure it's returned by wp_next_scheduled
    29                 $hook = __FUNCTION__;
    30                 $timestamp = strtotime('+1 hour');
     29                $hook      = __FUNCTION__;
     30                $timestamp = strtotime( '+1 hour' );
    3131
    3232                wp_schedule_single_event( $timestamp, $hook );
    33                 $this->assertEquals( $timestamp, wp_next_scheduled($hook) );
     33                $this->assertEquals( $timestamp, wp_next_scheduled( $hook ) );
    3434
    3535                // it's a non recurring event
    36                 $this->assertEquals( '', wp_get_schedule($hook) );
     36                $this->assertEquals( '', wp_get_schedule( $hook ) );
    3737
    3838        }
    … …  
    4040        function test_schedule_event_single_args() {
    4141                // schedule an event with arguments and make sure it's returned by wp_next_scheduled
    42                 $hook = 'event';
    43                 $timestamp = strtotime('+1 hour');
    44                 $args = array('foo');
     42                $hook      = 'event';
     43                $timestamp = strtotime( '+1 hour' );
     44                $args      = array( 'foo' );
    4545
    4646                wp_schedule_single_event( $timestamp, $hook, $args );
    4747                // this returns the timestamp only if we provide matching args
    48                 $this->assertEquals( $timestamp, wp_next_scheduled($hook, $args) );
     48                $this->assertEquals( $timestamp, wp_next_scheduled( $hook, $args ) );
    4949                // these don't match so return nothing
    50                 $this->assertEquals( false, wp_next_scheduled($hook) );
    51                 $this->assertEquals( false, wp_next_scheduled($hook, array('bar')) );
     50                $this->assertEquals( false, wp_next_scheduled( $hook ) );
     51                $this->assertEquals( false, wp_next_scheduled( $hook, array( 'bar' ) ) );
    5252
    5353                // it's a non recurring event
    54                 $this->assertEquals( '', wp_get_schedule($hook, $args) );
     54                $this->assertEquals( '', wp_get_schedule( $hook, $args ) );
    5555        }
    5656
    5757        function test_schedule_event() {
    5858                // schedule an event and make sure it's returned by wp_next_scheduled
    59                 $hook = __FUNCTION__;
    60                 $recur = 'hourly';
    61                 $timestamp = strtotime('+1 hour');
     59                $hook      = __FUNCTION__;
     60                $recur     = 'hourly';
     61                $timestamp = strtotime( '+1 hour' );
    6262
    6363                wp_schedule_event( $timestamp, $recur, $hook );
    6464                // it's scheduled for the right time
    65                 $this->assertEquals( $timestamp, wp_next_scheduled($hook) );
     65                $this->assertEquals( $timestamp, wp_next_scheduled( $hook ) );
    6666                // it's a recurring event
    67                 $this->assertEquals( $recur, wp_get_schedule($hook) );
     67                $this->assertEquals( $recur, wp_get_schedule( $hook ) );
    6868        }
    6969
    7070        function test_schedule_event_args() {
    7171                // schedule an event and make sure it's returned by wp_next_scheduled
    72                 $hook = 'event';
    73                 $timestamp = strtotime('+1 hour');
    74                 $recur = 'hourly';
    75                 $args = array('foo');
     72                $hook      = 'event';
     73                $timestamp = strtotime( '+1 hour' );
     74                $recur     = 'hourly';
     75                $args      = array( 'foo' );
    7676
    7777                wp_schedule_event( $timestamp, 'hourly', $hook, $args );
    7878                // this returns the timestamp only if we provide matching args
    79                 $this->assertEquals( $timestamp, wp_next_scheduled($hook, $args) );
     79                $this->assertEquals( $timestamp, wp_next_scheduled( $hook, $args ) );
    8080                // these don't match so return nothing
    81                 $this->assertEquals( false, wp_next_scheduled($hook) );
    82                 $this->assertEquals( false, wp_next_scheduled($hook, array('bar')) );
    83 
    84                 $this->assertEquals( $recur, wp_get_schedule($hook, $args) );
     81                $this->assertEquals( false, wp_next_scheduled( $hook ) );
     82                $this->assertEquals( false, wp_next_scheduled( $hook, array( 'bar' ) ) );
     83
     84                $this->assertEquals( $recur, wp_get_schedule( $hook, $args ) );
    8585
    8686        }
    … …  
    8888        function test_unschedule_event() {
    8989                // schedule an event and make sure it's returned by wp_next_scheduled
    90                 $hook = __FUNCTION__;
    91                 $timestamp = strtotime('+1 hour');
     90                $hook      = __FUNCTION__;
     91                $timestamp = strtotime( '+1 hour' );
    9292
    9393                wp_schedule_single_event( $timestamp, $hook );
    94                 $this->assertEquals( $timestamp, wp_next_scheduled($hook) );
     94                $this->assertEquals( $timestamp, wp_next_scheduled( $hook ) );
    9595
    9696                // now unschedule it and make sure it's gone
    9797                wp_unschedule_event( $timestamp, $hook );
    98                 $this->assertEquals( false, wp_next_scheduled($hook) );
     98                $this->assertEquals( false, wp_next_scheduled( $hook ) );
    9999        }
    100100
    … …  
    104104
    105105                // schedule several events with and without arguments
    106                 wp_schedule_single_event( strtotime('+1 hour'), $hook );
    107                 wp_schedule_single_event( strtotime('+2 hour'), $hook );
    108                 wp_schedule_single_event( strtotime('+3 hour'), $hook, $args );
    109                 wp_schedule_single_event( strtotime('+4 hour'), $hook, $args );
     106                wp_schedule_single_event( strtotime( '+1 hour' ), $hook );
     107                wp_schedule_single_event( strtotime( '+2 hour' ), $hook );
     108                wp_schedule_single_event( strtotime( '+3 hour' ), $hook, $args );
     109                wp_schedule_single_event( strtotime( '+4 hour' ), $hook, $args );
    110110
    111111                // make sure they're returned by wp_next_scheduled()
    112                 $this->assertTrue( wp_next_scheduled($hook) > 0 );
    113                 $this->assertTrue( wp_next_scheduled($hook, $args) > 0 );
     112                $this->assertTrue( wp_next_scheduled( $hook ) > 0 );
     113                $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 );
    114114
    115115                // clear the schedule for the no args events and make sure it's gone
    116                 wp_clear_scheduled_hook($hook);
    117                 $this->assertFalse( wp_next_scheduled($hook) );
     116                wp_clear_scheduled_hook( $hook );
     117                $this->assertFalse( wp_next_scheduled( $hook ) );
    118118                // the args events should still be there
    119                 $this->assertTrue( wp_next_scheduled($hook, $args) > 0 );
     119                $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 );
    120120
    121121                // clear the schedule for the args events and make sure they're gone too
    122122                // note: wp_clear_scheduled_hook() expects args passed directly, rather than as an array
    123                 wp_clear_scheduled_hook($hook, $args);
    124                 $this->assertFalse( wp_next_scheduled($hook, $args) );
     123                wp_clear_scheduled_hook( $hook, $args );
     124                $this->assertFalse( wp_next_scheduled( $hook, $args ) );
    125125        }
    126126
    … …  
    130130
    131131                // schedule several events with and without arguments
    132                 wp_schedule_single_event( strtotime('+1 hour'), $hook );
    133                 wp_schedule_single_event( strtotime('+2 hour'), $hook );
    134                 wp_schedule_single_event( strtotime('+3 hour'), $hook, $args );
    135                 wp_schedule_single_event( strtotime('+4 hour'), $hook, $args );
     132                wp_schedule_single_event( strtotime( '+1 hour' ), $hook );
     133                wp_schedule_single_event( strtotime( '+2 hour' ), $hook );
     134                wp_schedule_single_event( strtotime( '+3 hour' ), $hook, $args );
     135                wp_schedule_single_event( strtotime( '+4 hour' ), $hook, $args );
    136136
    137137                // make sure they're returned by wp_next_scheduled()
    138                 $this->assertTrue( wp_next_scheduled($hook) > 0 );
    139                 $this->assertTrue( wp_next_scheduled($hook, $args) > 0 );
     138                $this->assertTrue( wp_next_scheduled( $hook ) > 0 );
     139                $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 );
    140140
    141141                // clear the schedule for the no args events and make sure it's gone
    142                 wp_clear_scheduled_hook($hook);
    143                 $this->assertFalse( wp_next_scheduled($hook) );
     142                wp_clear_scheduled_hook( $hook );
     143                $this->assertFalse( wp_next_scheduled( $hook ) );
    144144                // the args events should still be there
    145                 $this->assertTrue( wp_next_scheduled($hook, $args) > 0 );
     145                $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 );
    146146
    147147                // clear the schedule for the args events and make sure they're gone too
    148148                // note: wp_clear_scheduled_hook() used to expect args passed directly, rather than as an array pre WP 3.0
    149                 wp_clear_scheduled_hook($hook, $args);
    150                 $this->assertFalse( wp_next_scheduled($hook, $args) );
     149                wp_clear_scheduled_hook( $hook, $args );
     150                $this->assertFalse( wp_next_scheduled( $hook, $args ) );
    151151        }
    152152
    … …  
    155155         */
    156156        function test_clear_schedule_new_args() {
    157                 $hook = __FUNCTION__;
    158                 $args = array( 'arg1' );
     157                $hook       = __FUNCTION__;
     158                $args       = array( 'arg1' );
    159159                $multi_hook = __FUNCTION__ . '_multi';
    160160                $multi_args = array( 'arg2', 'arg3' );
    161161
    162162                // schedule several events with and without arguments
    163                 wp_schedule_single_event( strtotime('+1 hour'), $hook );
    164                 wp_schedule_single_event( strtotime('+2 hour'), $hook );
    165                 wp_schedule_single_event( strtotime('+3 hour'), $hook, $args );
    166                 wp_schedule_single_event( strtotime('+4 hour'), $hook, $args );
    167                 wp_schedule_single_event( strtotime('+5 hour'), $multi_hook, $multi_args );
    168                 wp_schedule_single_event( strtotime('+6 hour'), $multi_hook, $multi_args );
     163                wp_schedule_single_event( strtotime( '+1 hour' ), $hook );
     164                wp_schedule_single_event( strtotime( '+2 hour' ), $hook );
     165                wp_schedule_single_event( strtotime( '+3 hour' ), $hook, $args );
     166                wp_schedule_single_event( strtotime( '+4 hour' ), $hook, $args );
     167                wp_schedule_single_event( strtotime( '+5 hour' ), $multi_hook, $multi_args );
     168                wp_schedule_single_event( strtotime( '+6 hour' ), $multi_hook, $multi_args );
    169169
    170170                // make sure they're returned by wp_next_scheduled()
    171                 $this->assertTrue( wp_next_scheduled($hook) > 0 );
    172                 $this->assertTrue( wp_next_scheduled($hook, $args) > 0 );
     171                $this->assertTrue( wp_next_scheduled( $hook ) > 0 );
     172                $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 );
    173173
    174174                // clear the schedule for the no args events and make sure it's gone
    175                 wp_clear_scheduled_hook($hook);
    176                 $this->assertFalse( wp_next_scheduled($hook) );
     175                wp_clear_scheduled_hook( $hook );
     176                $this->assertFalse( wp_next_scheduled( $hook ) );
    177177                // the args events should still be there
    178                 $this->assertTrue( wp_next_scheduled($hook, $args) > 0 );
     178                $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 );
    179179
    180180                // clear the schedule for the args events and make sure they're gone too
    181181                // wp_clear_scheduled_hook() should take args as an array like the other functions.
    182                 wp_clear_scheduled_hook($hook, $args);
    183                 $this->assertFalse( wp_next_scheduled($hook, $args) );
     182                wp_clear_scheduled_hook( $hook, $args );
     183                $this->assertFalse( wp_next_scheduled( $hook, $args ) );
    184184
    185185                // clear the schedule for the args events and make sure they're gone too
    186186                // wp_clear_scheduled_hook() should take args as an array like the other functions and does from WP 3.0
    187                 wp_clear_scheduled_hook($multi_hook, $multi_args);
    188                 $this->assertFalse( wp_next_scheduled($multi_hook, $multi_args) );
     187                wp_clear_scheduled_hook( $multi_hook, $multi_args );
     188                $this->assertFalse( wp_next_scheduled( $multi_hook, $multi_args ) );
    189189        }
    190190
    … …  
    218218                $hook = __FUNCTION__;
    219219                $args = array( 'arg1' );
    220                 $ts1 = strtotime('+5 minutes');
    221                 $ts2 = strtotime('+3 minutes');
     220                $ts1  = strtotime( '+5 minutes' );
     221                $ts2  = strtotime( '+3 minutes' );
    222222
    223223                // first one works
    … …  
    227227
    228228                // the next event should be at +5 minutes, not +3
    229                 $this->assertEquals( $ts1, wp_next_scheduled($hook, $args) );
     229                $this->assertEquals( $ts1, wp_next_scheduled( $hook, $args ) );
    230230        }
    231231
    … …  
    237237                $hook = __FUNCTION__;
    238238                $args = array( 'arg1' );
    239                 $ts1 = strtotime( '+30 minutes' );
    240                 $ts2 = strtotime( '+3 minutes' );
     239                $ts1  = strtotime( '+30 minutes' );
     240                $ts2  = strtotime( '+3 minutes' );
    241241
    242242                // first one works
    … …  
    256256                $hook = __FUNCTION__;
    257257                $args = array( 'arg1' );
    258                 $ts1 = strtotime( '+3 minutes' );
    259                 $ts2 = strtotime( '+30 minutes' );
     258                $ts1  = strtotime( '+3 minutes' );
     259                $ts2  = strtotime( '+30 minutes' );
    260260
    261261                // first one works
Note: See TracChangeset for help on using the changeset viewer.