[BUGFIX] Fix ajax scripts in recycler
[Packages/TYPO3.CMS.git] / typo3 / sysext / scheduler / tests / Unit / Controller / SchedulerModuleControllerTest.php
1 <?php
2 namespace TYPO3\CMS\Scheduler\Tests\Unit\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2011 Andy Grunwald <andreas.grunwald@wmdb.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * Testcase for class "tx_scheduler_Module"
28 *
29 * @package TYPO3
30 * @subpackage tx_scheduler
31 * @author Andy Grunwald <andreas.grunwald@wmdb.de>
32 */
33 class SchedulerModuleControllerTest extends tx_phpunit_testcase {
34
35 /**
36 * Object to Test: tx_scheduler_Module
37 *
38 * @var \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController
39 */
40 protected $testObject;
41
42 /**
43 * Sets up each test case.
44 *
45 * @return void
46 */
47 public function setUp() {
48 $this->testObject = new \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController();
49 }
50
51 /**
52 * Cleans up each test case.
53 *
54 * @return void
55 */
56 public function tearDown() {
57 $this->testObject = NULL;
58 }
59
60 /**
61 * Provide dates in strtotime format
62 *
63 * @see checkDateWithStrtotimeValues
64 * @return array Testdata for "checkDateWithStrtotimeValues".
65 */
66 public function checkDateWithStrtotimeValuesDataProvider() {
67 return array(
68 'now' => array(
69 'now',
70 strtotime('now')
71 ),
72 '10 September 2000' => array(
73 '10 September 2000',
74 strtotime('10 September 2000')
75 ),
76 '+1 day' => array(
77 '+1 day',
78 strtotime('+1 day')
79 ),
80 '+1 week' => array(
81 '+1 week',
82 strtotime('+1 week')
83 ),
84 '+1 week 2 days 4 hours 2 seconds' => array(
85 '+1 week 2 days 4 hours 2 seconds',
86 strtotime('+1 week 2 days 4 hours 2 seconds')
87 ),
88 'next Thursday' => array(
89 'next Thursday',
90 strtotime('next Thursday')
91 ),
92 'last Monday' => array(
93 'last Monday',
94 strtotime('last Monday')
95 )
96 );
97 }
98
99 /**
100 * @dataProvider checkDateWithStrtotimeValuesDataProvider
101 * @test
102 * @see http://de.php.net/manual/de/function.strtotime.php
103 * @param string $strToTimeValue Test value which will be passed to $this->testObject->checkDate
104 * @param integer $expectedTimestamp Expected value to compare with result from operation
105 */
106 public function checkDateWithStrtotimeValues($strToTimeValue, $expectedTimestamp) {
107 $checkDateResult = $this->testObject->checkDate($strToTimeValue);
108 // We use assertLessThan here, because we test with relative values (eg. next Thursday, now, ..)
109 // If this tests runs over 1 seconds the test will fail if we use assertSame / assertEquals
110 // With assertLessThan the tests could run 0 till 3 seconds ($delta = 4)
111 $delta = 4;
112 $this->assertLessThan($delta, $checkDateResult - $expectedTimestamp, ('assertLessThan fails with value "' . $strToTimeValue) . '"');
113 $this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_INT, $checkDateResult, ('assertType fails with value "' . $strToTimeValue) . '"');
114 }
115
116 /**
117 * Provides dates in TYPO3 date field formats (non-US), i.e. H:i Y-m-d
118 *
119 * @see checkDateWithTypo3DateSyntax
120 * @return array Testdata for "checkDateWithTypo3DateSyntax".
121 */
122 public function checkDateWithTypo3DateSyntaxDataProvider() {
123 return array(
124 '00:00 2011-05-30' => array(
125 '00:00 2011-05-30',
126 mktime(0, 0, 0, 5, 30, 2011)
127 ),
128 '00:01 2011-05-30' => array(
129 '00:01 2011-05-30',
130 mktime(0, 1, 0, 5, 30, 2011)
131 ),
132 '23:59 2011-05-30' => array(
133 '23:59 2011-05-30',
134 mktime(23, 59, 0, 5, 30, 2011)
135 ),
136 '15:35 2000-12-24' => array(
137 '15:35 2000-12-24',
138 mktime(15, 35, 0, 12, 24, 2000)
139 ),
140 '00:01 1970-01-01' => array(
141 '00:01 1970-01-01',
142 mktime(0, 1, 0, 1, 1, 1970)
143 ),
144 '17:26 2020-03-15' => array(
145 '17:26 2020-03-15',
146 mktime(17, 26, 0, 3, 15, 2020)
147 ),
148 '1:5 2020-03-15' => array(
149 '1:5 2020-03-15',
150 mktime(1, 5, 0, 3, 15, 2020)
151 ),
152 '10:50 2020-3-5' => array(
153 '10:50 2020-3-5',
154 mktime(10, 50, 0, 3, 5, 2020)
155 ),
156 '01:01 1968-01-01' => array(
157 '01:01 1968-01-01',
158 mktime(1, 1, 0, 1, 1, 1968)
159 )
160 );
161 }
162
163 /**
164 * @dataProvider checkDateWithTypo3DateSyntaxDataProvider
165 * @test
166 * @param string $typo3DateValue Test value which will be passed to $this->testObject->checkDate
167 * @param integer $expectedTimestamp Expected value to compare with result from operation
168 */
169 public function checkDateWithTypo3DateSyntax($typo3DateValue, $expectedTimestamp) {
170 $this->assertSame($expectedTimestamp, $this->testObject->checkDate($typo3DateValue), ('Fails with value "' . $typo3DateValue) . '"');
171 }
172
173 /**
174 * Provides some invalid dates
175 *
176 * @see checkDateWithInvalidDateValues
177 * @return array Test data for "checkDateWithInvalidDateValues".
178 */
179 public function checkDateWithInvalidDateValuesDataProvider() {
180 return array(
181 'Not Good' => array(
182 'Not Good'
183 ),
184 'HH:ii yyyy-mm-dd' => array(
185 'HH:ii yyyy-mm-dd'
186 )
187 );
188 }
189
190 /**
191 * This test must be raised an InvalidArgumentException
192 *
193 * @dataProvider checkDateWithInvalidDateValuesDataProvider
194 * @expectedException InvalidArgumentException
195 * @test
196 * @param string $dateValue Test value which will be passed to $this->testObject->checkDate.
197 */
198 public function checkDateWithInvalidDateValues($dateValue) {
199 $this->testObject->checkDate($dateValue);
200 }
201
202 }
203
204
205 ?>