Make WordPress Core

Changeset 272 in tests


Ignore:
Timestamp:
11/22/2009 10:50:39 PM (17 years ago)
Author:
westi
Message:

Split the cron tests into two sections - one for the scheduling and one for the running.
Reinstate the tests involving the scheduling code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_cron.php

    r217 r272  
    11<?php
    2 /*
    3  * Disable the WP Cron test for the moment as it kills the whole test suite.
    4  * TODO - Fix it to work with the new cron implementation in trunk
    5  *
    62// test the cron scheduling functions
    73
    8 class WPTestCron extends _WPEmptyBlog {
     4class WPTestCronScheduling extends _WPEmptyBlog {
    95        function setUp() {
    106                parent::setUp();
    … …  
    124120                $this->assertFalse( wp_next_scheduled($hook, $args) );
    125121        }
    126        
    127         function _do_cron() {
    128                 // FIXME: wp-cron.php is difficult to test, could be wrapped in a function
    129                 $_GET['check'] = wp_hash('187425');
    130                 require(ABSPATH.'/wp-cron.php');
    131         }
    132 
    133         function test_run_schedule_single() {
    134                 // schedule an event, run it, and make sure the hook is called
    135                 $hook = rand_str();
    136                 $args = array(rand_str());
    137                 $timestamp = strtotime('-1 second');
    138 
    139                 // register a test action
    140                 $a = new MockAction();
    141                 add_action($hook, array(&$a, 'action'));
    142 
    143                 // schedule an event for 1 second ago
    144                 wp_schedule_single_event( $timestamp, $hook, $args );
    145                 $this->assertEquals( $timestamp, wp_next_scheduled($hook, $args) );
    146 
    147                 // run cron jobs
    148                 $this->_do_cron();
    149 
    150                 // our action should have been called once with the correct args
    151                 $this->assertEquals( 1, $a->get_call_count() );
    152                 $this->assertEquals( array($args), $a->get_args() );
    153                
    154                 // it shouldn't appear in the schedule anymore
    155                 $this->assertFalse( wp_next_scheduled($hook, $args) );
    156 
    157         }
    158        
    159         function test_run_schedule_recurring() {
    160                 // schedule a recurring event, run it, and make sure the hook is called
    161                 $hook = rand_str();
    162                 $args = array(rand_str());
    163                 $timestamp = strtotime('-1 second');
    164                 $recur = 'hourly';
    165 
    166                 // register a test action
    167                 $a = new MockAction();
    168                 add_action($hook, array(&$a, 'action'));
    169 
    170                 // schedule an event for 1 second ago
    171                 wp_schedule_event( $timestamp, $recur, $hook, $args );
    172                 $this->assertEquals( $timestamp, wp_next_scheduled($hook, $args) );
    173                 $this->assertEquals( $recur, wp_get_schedule($hook, $args) );
    174 
    175                 // run cron jobs
    176                 $this->_do_cron();
    177 
    178                 // our action should have been called once with the correct args
    179                 $this->assertEquals( 1, $a->get_call_count() );
    180                 $this->assertEquals( array($args), $a->get_args() );
    181                
    182                 // it should appear in the schedule to run again in an hour's time
    183                 $this->assertEquals( $timestamp + 3600, wp_next_scheduled($hook, $args) );
    184 
    185         }
    186        
     122
    187123        function test_duplicate_event() {
    188124                $this->knownWPBug(6966);
    … …  
    221157                $this->assertEquals( $ts1, wp_next_scheduled($hook, $args) );
    222158        }
    223 
     159}
     160
     161/*
     162 * Disable the WP Cron running test for the moment as it kills the whole test suite.
     163 * TODO - Fix it to work with the new cron implementation in trunk
     164 *
     165class WPTestCronRunning extends _WPEmptyBlog {
     166        function setUp() {
     167                parent::setUp();
     168                // make sure the schedule is clear
     169                _set_cron_array(array());
     170        }
     171
     172        function tearDown() {
     173                parent::tearDown();
     174                // make sure the schedule is clear
     175                _set_cron_array(array());
     176        }
     177        function _do_cron() {
     178                // FIXME: wp-cron.php is difficult to test, could be wrapped in a function
     179                $_GET['check'] = wp_hash('187425');
     180                require(ABSPATH.'/wp-cron.php');
     181        }
     182
     183        function test_run_schedule_single() {
     184                // schedule an event, run it, and make sure the hook is called
     185                $hook = rand_str();
     186                $args = array(rand_str());
     187                $timestamp = strtotime('-1 second');
     188
     189                // register a test action
     190                $a = new MockAction();
     191                add_action($hook, array(&$a, 'action'));
     192
     193                // schedule an event for 1 second ago
     194                wp_schedule_single_event( $timestamp, $hook, $args );
     195                $this->assertEquals( $timestamp, wp_next_scheduled($hook, $args) );
     196
     197                // run cron jobs
     198                $this->_do_cron();
     199
     200                // our action should have been called once with the correct args
     201                $this->assertEquals( 1, $a->get_call_count() );
     202                $this->assertEquals( array($args), $a->get_args() );
     203               
     204                // it shouldn't appear in the schedule anymore
     205                $this->assertFalse( wp_next_scheduled($hook, $args) );
     206
     207        }
     208       
     209        function test_run_schedule_recurring() {
     210                // schedule a recurring event, run it, and make sure the hook is called
     211                $hook = rand_str();
     212                $args = array(rand_str());
     213                $timestamp = strtotime('-1 second');
     214                $recur = 'hourly';
     215
     216                // register a test action
     217                $a = new MockAction();
     218                add_action($hook, array(&$a, 'action'));
     219
     220                // schedule an event for 1 second ago
     221                wp_schedule_event( $timestamp, $recur, $hook, $args );
     222                $this->assertEquals( $timestamp, wp_next_scheduled($hook, $args) );
     223                $this->assertEquals( $recur, wp_get_schedule($hook, $args) );
     224
     225                // run cron jobs
     226                $this->_do_cron();
     227
     228                // our action should have been called once with the correct args
     229                $this->assertEquals( 1, $a->get_call_count() );
     230                $this->assertEquals( array($args), $a->get_args() );
     231               
     232                // it should appear in the schedule to run again in an hour's time
     233                $this->assertEquals( $timestamp + 3600, wp_next_scheduled($hook, $args) );
     234
     235        }
    224236}
    225237*/
Note: See TracChangeset for help on using the changeset viewer.