[TASK] Stabilize scheduler tests and activate in travis
authorChristian Kuhn <lolli@schwarzbu.ch>
Wed, 12 Sep 2012 12:37:34 +0000 (14:37 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Wed, 12 Sep 2012 13:44:09 +0000 (15:44 +0200)
Next try to add the scheduler tests to the test suites.

The patch applies several changes:

* For some weird reasons PHP does not recognize 'September' as valid
month keyword if the timezone is not Europe/Berlin. The test is removed
since only three letter abbreviations are allowed anyway.

* Make the cron command test system timezone agnostic.
CronCommandTest now explicitly sets the timezone to UTC (GMT) in setUp
and has a backup for tearDown. This is needed because the tests use hard
coded timestamps and the system under test is sensitive for timezones.
This was the main reason for the travis runs to fail in the first place.

* The dataProvider in CronCommandTest do not execute strtotime anymore.
The reason for that is, that the data provider data in phpunit is
executed before setUp and won't get the timezone setting then. The main
data provider is now splitted into two, separating the strtotime()
calculation off from the rest.

Change-Id: Ifb8de929b8e6edb31b24cbf02a9ddaa9dda9ab43
Resolves: #40515
Releases: 6.0
Reviewed-on: http://review.typo3.org/14549
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/core/Build/UnitTests.xml
typo3/sysext/scheduler/Tests/Unit/CronCommand/CronCommandTest.php
typo3/sysext/scheduler/Tests/Unit/CronCommand/NormalizeCommandTest.php

index ad5cd00..1768712 100644 (file)
@@ -37,6 +37,9 @@
                <testsuite name="EXT:fluid tests">
                        <directory>../../../../typo3/sysext/fluid/Tests/Unit/</directory>
                </testsuite>
+               <testsuite name="EXT:scheduler tests">
+                       <directory>../../../../typo3/sysext/scheduler/Tests/Unit/</directory>
+               </testsuite>
                <testsuite name="Suite integrity tests">
                        <directory>../../../../typo3/sysext/core/Tests/Integrity/</directory>
                </testsuite>
index f38a9ff..f24e6b9 100644 (file)
@@ -33,15 +33,36 @@ namespace TYPO3\CMS\Scheduler\Tests\Unit\CronCommand;
 class CronCommandTest extends \tx_phpunit_testcase {
 
        /**
-        * @const       integer timestamp of 1.1.2010 0:00 (Friday)
+        * @const integer timestamp of 1.1.2010 0:00 (Friday), timezone UTC/GMT
         */
-       const TIMESTAMP = 1262300400;
+       const TIMESTAMP = 1262304000;
+
+       /**
+        * @var string Selected timezone backup
+        */
+       protected $timezoneBackup = '';
+
+       /**
+        * We're fiddling with hard timestamps in the tests, but time methods in
+        * the system under test do use timezone settings. Therefore we backup the
+        * current timezone setting, set it to UTC explicitly and reconstitute it
+        * again in tearDown()
+        */
+       public function setUp() {
+               $this->timezoneBackup = date_default_timezone_get();
+               date_default_timezone_set('UTC');
+       }
+
+       public function tearDown() {
+               date_default_timezone_set($this->timezoneBackup);
+       }
+
        /**
         * @test
         */
        public function constructorSetsNormalizedCronCommandSections() {
                $instance = new \TYPO3\CMS\Scheduler\CronCommand\CronCommand('2-3 * * * *');
-               $this->assertSame($instance->getCronCommandSections(), array('2,3', '*', '*', '*', '*'));
+               $this->assertSame(array('2,3', '*', '*', '*', '*'), $instance->getCronCommandSections());
        }
 
        /**
@@ -67,7 +88,7 @@ class CronCommandTest extends \tx_phpunit_testcase {
         */
        public function constructorSetsTimestampToGivenTimestampPlusSixtySeconds() {
                $instance = new \TYPO3\CMS\Scheduler\CronCommand\CronCommand('* * * * *', self::TIMESTAMP);
-               $this->assertSame($instance->getTimestamp(), self::TIMESTAMP + 60);
+               $this->assertSame(self::TIMESTAMP + 60, $instance->getTimestamp());
        }
 
        /**
@@ -75,7 +96,7 @@ class CronCommandTest extends \tx_phpunit_testcase {
         */
        public function constructorSetsTimestampToGiveTimestampRoundedDownToSixtySeconds() {
                $instance = new \TYPO3\CMS\Scheduler\CronCommand\CronCommand('* * * * *', self::TIMESTAMP + 1);
-               $this->assertSame($instance->getTimestamp(), self::TIMESTAMP + 60);
+               $this->assertSame(self::TIMESTAMP + 60, $instance->getTimestamp());
        }
 
        /**
@@ -113,12 +134,6 @@ class CronCommandTest extends \tx_phpunit_testcase {
                                self::TIMESTAMP + (60 * 60) * 24,
                                self::TIMESTAMP + ((60 * 60) * 24) * 2
                        ),
-                       'every first day of month' => array(
-                               '0 0 1 * *',
-                               self::TIMESTAMP,
-                               strtotime('01-02-2010'),
-                               strtotime('01-03-2010')
-                       ),
                        'once a month' => array(
                                '0 0 4 * *',
                                self::TIMESTAMP,
@@ -137,24 +152,6 @@ class CronCommandTest extends \tx_phpunit_testcase {
                                self::TIMESTAMP + ((60 * 60) * 24) * 31,
                                (self::TIMESTAMP + ((60 * 60) * 24) * 31) + (60 * 60) * 24
                        ),
-                       'once every February' => array(
-                               '0 0 1 feb *',
-                               self::TIMESTAMP,
-                               self::TIMESTAMP + ((60 * 60) * 24) * 31,
-                               strtotime('01-02-2011')
-                       ),
-                       'once every Friday February' => array(
-                               '0 0 * feb fri',
-                               self::TIMESTAMP,
-                               strtotime('05-02-2010'),
-                               strtotime('12-02-2010')
-                       ),
-                       'first day in February and every Friday' => array(
-                               '0 0 1 feb fri',
-                               self::TIMESTAMP,
-                               strtotime('01-02-2010'),
-                               strtotime('05-02-2010')
-                       ),
                        'day of week and day of month restricted, next match in day of month field' => array(
                                '0 0 2 * sun',
                                self::TIMESTAMP,
@@ -167,12 +164,6 @@ class CronCommandTest extends \tx_phpunit_testcase {
                                self::TIMESTAMP + (60 * 60) * 24,
                                (self::TIMESTAMP + (60 * 60) * 24) + (60 * 60) * 24
                        ),
-                       '29th February leap year' => array(
-                               '0 0 29 feb *',
-                               self::TIMESTAMP,
-                               strtotime('29-02-2012'),
-                               strtotime('29-02-2016')
-                       ),
                        'list of minutes' => array(
                                '2,4 * * * *',
                                self::TIMESTAMP,
@@ -185,23 +176,61 @@ class CronCommandTest extends \tx_phpunit_testcase {
                                self::TIMESTAMP + (60 * 60) * 2,
                                self::TIMESTAMP + (60 * 60) * 4
                        ),
+               );
+       }
+
+       /**
+        * @return array
+        */
+       static public function expectedCalculatedTimestampDataProvider() {
+               return array(
+                       'every first day of month' => array(
+                               '0 0 1 * *',
+                               self::TIMESTAMP,
+                               '01-02-2010',
+                               '01-03-2010',
+                       ),
+                       'once every February' => array(
+                               '0 0 1 feb *',
+                               self::TIMESTAMP,
+                               '01-02-2010',
+                               '01-02-2011',
+                       ),
+                       'once every Friday February' => array(
+                               '0 0 * feb fri',
+                               self::TIMESTAMP,
+                               '05-02-2010',
+                               '12-02-2010',
+                       ),
+                       'first day in February and every Friday' => array(
+                               '0 0 1 feb fri',
+                               self::TIMESTAMP,
+                               '01-02-2010',
+                               '05-02-2010',
+                       ),
+                       '29th February leap year' => array(
+                               '0 0 29 feb *',
+                               self::TIMESTAMP,
+                               '29-02-2012',
+                               '29-02-2016',
+                       ),
                        'list of days in month' => array(
                                '0 0 2,4 * *',
                                self::TIMESTAMP,
-                               strtotime('02-01-2010'),
-                               strtotime('04-01-2010')
+                               '02-01-2010',
+                               '04-01-2010',
                        ),
                        'list of month' => array(
                                '0 0 1 2,3 *',
                                self::TIMESTAMP,
-                               strtotime('01-02-2010'),
-                               strtotime('01-03-2010')
+                               '01-02-2010',
+                               '01-03-2010',
                        ),
                        'list of days of weeks' => array(
                                '0 0 * * 2,4',
                                self::TIMESTAMP,
-                               strtotime('05-01-2010'),
-                               strtotime('07-01-2010')
+                               '05-01-2010',
+                               '07-01-2010',
                        )
                );
        }
@@ -216,21 +245,48 @@ class CronCommandTest extends \tx_phpunit_testcase {
        public function calculateNextValueDeterminesCorrectNextTimestamp($cronCommand, $startTimestamp, $expectedTimestamp) {
                $instance = new \TYPO3\CMS\Scheduler\CronCommand\CronCommand($cronCommand, $startTimestamp);
                $instance->calculateNextValue();
-               $this->assertSame($instance->getTimestamp(), $expectedTimestamp);
+               $this->assertSame($expectedTimestamp, $instance->getTimestamp());
        }
 
        /**
         * @test
-        * @dataProvider expectedTimestampDataProvider
+        * @dataProvider expectedCalculatedTimestampDataProvider
         * @param string $cronCommand Cron command
         * @param integer $startTimestamp Timestamp for start of calculation
+        * @param string $expectedTimestamp Expected result (next time of execution), to be feeded to strtotime
+        */
+       public function calculateNextValueDeterminesCorrectNextCalculatedTimestamp($cronCommand, $startTimestamp, $expectedTimestamp) {
+               $instance = new \TYPO3\CMS\Scheduler\CronCommand\CronCommand($cronCommand, $startTimestamp);
+               $instance->calculateNextValue();
+               $this->assertSame(strtotime($expectedTimestamp), $instance->getTimestamp());
+       }
+
+       /**
+        * @test
+        * @dataProvider expectedTimestampDataProvider
+        * @param string $cronCommand Cron command
+        * @param integer $startTimestamp [unused] Timestamp for start of calculation
         * @param integer $firstTimestamp Timestamp of the next execution
         * @param integer $secondTimestamp Timestamp of the further execution
         */
        public function calculateNextValueDeterminesCorrectNextTimestampOnConsecutiveCall($cronCommand, $startTimestamp, $firstTimestamp, $secondTimestamp) {
                $instance = new \TYPO3\CMS\Scheduler\CronCommand\CronCommand($cronCommand, $firstTimestamp);
                $instance->calculateNextValue();
-               $this->assertSame($instance->getTimestamp(), $secondTimestamp);
+               $this->assertSame($secondTimestamp, $instance->getTimestamp());
+       }
+
+       /**
+        * @test
+        * @dataProvider expectedCalculatedTimestampDataProvider
+        * @param string $cronCommand Cron command
+        * @param integer $startTimestamp [unused] Timestamp for start of calculation
+        * @param string $firstTimestamp Timestamp of the next execution, to be feeded to strtotime
+        * @param string $secondTimestamp Timestamp of the further execution, to be feeded to strtotime
+        */
+       public function calculateNextValueDeterminesCorrectNextCalculatedTimestampOnConsecutiveCall($cronCommand, $startTimestamp, $firstTimestamp, $secondTimestamp) {
+               $instance = new \TYPO3\CMS\Scheduler\CronCommand\CronCommand($cronCommand, strtotime($firstTimestamp));
+               $instance->calculateNextValue();
+               $this->assertSame(strtotime($secondTimestamp), $instance->getTimestamp());
        }
 
        /**
@@ -242,7 +298,7 @@ class CronCommandTest extends \tx_phpunit_testcase {
                $instance = new \TYPO3\CMS\Scheduler\CronCommand\CronCommand('* 3 28 mar *', self::TIMESTAMP);
                $instance->calculateNextValue();
                date_default_timezone_set($backupTimezone);
-               $this->assertSame($instance->getTimestamp(), 1269741600);
+               $this->assertSame(1269741600, $instance->getTimestamp());
        }
 
        /**
index 7d027b8..8e74dc1 100644 (file)
@@ -501,7 +501,6 @@ class NormalizeCommandTest extends \tx_phpunit_testcase {
                        'jul' => array('jul', 7),
                        'aug' => array('aug', 8),
                        'sep' => array('sep', 9),
-                       'September' => array('September', 9),
                        'oct' => array('oct', 10),
                        'nov' => array('nov', 11),
                        'dec' => array('dec', 12),