Make WordPress Core

Changeset 58109


Ignore:
Timestamp:
05/06/2024 06:47:42 PM (8 months ago)
Author:
johnbillion
Message:

Cron API: Add tests for associative and indexed array arguments when rescheduling a cron event.

Props johnbillion, peterwilsoncc

See #57271

File:
1 edited

Legend:

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

    r57987 r58109  
    489489
    490490        // Reschedule event with preflight filter in place.
    491         wp_reschedule_event( $ts1, 'daily', $hook );
     491        $rescheduled = wp_reschedule_event( $ts1, 'daily', $hook );
     492
     493        // Check return value.
     494        $this->assertTrue( $rescheduled );
    492495
    493496        // Check cron option is unchanged.
     
    10241027
    10251028    /**
     1029     * @ticket 57271
     1030     *
     1031     * @dataProvider data_wp_reschedule_event_works_with_args
     1032     *
     1033     * @covers ::wp_reschedule_event
     1034     */
     1035    public function test_wp_reschedule_event_works_with_args( array $args ) {
     1036        $time = time();
     1037
     1038        // Schedule events with the `$wp_error` parameter:
     1039        $event             = wp_schedule_event( $time, 'daily', 'hook', $args, true );
     1040        $rescheduled_event = wp_reschedule_event( $time, 'daily', 'hook', $args, true );
     1041        $unscheduled_event = wp_unschedule_event( $time, 'hook', $args, true );
     1042        $next_timestamp    = wp_next_scheduled( 'hook', $args );
     1043
     1044        // Ensure the events were added and updated correctly:
     1045        $this->assertNotWPError( $event );
     1046        $this->assertNotWPError( $rescheduled_event );
     1047        $this->assertNotWPError( $unscheduled_event );
     1048        $this->assertSame( $time + DAY_IN_SECONDS, $next_timestamp );
     1049    }
     1050
     1051    /**
     1052     * Data provider for test_wp_reschedule_event_works_with_args().
     1053     *
     1054     * @return array[]
     1055     */
     1056    public function data_wp_reschedule_event_works_with_args() {
     1057        return array(
     1058            'indexed'     => array(
     1059                array(
     1060                    1,
     1061                    2,
     1062                    3,
     1063                ),
     1064            ),
     1065            'associative' => array(
     1066                array(
     1067                    'one'   => 1,
     1068                    'two'   => 2,
     1069                    'three' => 3,
     1070                ),
     1071            ),
     1072        );
     1073    }
     1074
     1075    /**
    10261076     * @ticket 49961
    10271077     * @expectedDeprecated wp_clear_scheduled_hook
Note: See TracChangeset for help on using the changeset viewer.