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