08e1c8cc3ec4acd67b378ebf8b49cb004d6e7afb
[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 = NULL;
41
42 public function setUp() {
43 $this->testObject = new tx_scheduler_Module();
44 }
45
46 public function tearDown() {
47 $this->testObject = NULL;
48 }
49
50 /**
51 * Provide dates in strtotime format
52 *
53 * @see checkDateWithStrtotimeValues
54 * @return array Testdata for "checkDateWithStrtotimeValues".
55 * Structure: array(
56 * 'Value description' => array(
57 * 'value to pass to $this->testObject->checkDate',
58 * 'expected results which will be compared'
59 * )
60 * )
61 */
62 public function checkDateWithStrtotimeValuesDataProvider() {
63 return array(
64 'now' => array(
65 'now',
66 strtotime('now')
67 ),
68 '10 September 2000' => array(
69 '10 September 2000',
70 strtotime('10 September 2000')
71 ),
72 '+1 day' => array(
73 '+1 day',
74 strtotime('+1 day')
75 ),
76 '+1 week' => array(
77 '+1 week',
78 strtotime('+1 week')
79 ),
80 '+1 week 2 days 4 hours 2 seconds' => array(
81 '+1 week 2 days 4 hours 2 seconds',
82 strtotime('+1 week 2 days 4 hours 2 seconds')
83 ),
84 'next Thursday' => array(
85 'next Thursday',
86 strtotime('next Thursday')
87 ),
88 'last Monday' => array(
89 'last Monday',
90 strtotime('last Monday')
91 ),
92 );
93 }
94
95 /**
96 * @dataProvider checkDateWithStrtotimeValuesDataProvider
97 * @test
98 * @see http://de.php.net/manual/de/function.strtotime.php
99 * @param $strToTimeValue Testvalue which will be passed to $this->testObject->checkDate
100 * @param $expectedTimestamp Expected value to compare with result from operation
101 * @return void
102 */
103 public function checkDateWithStrtotimeValues($strToTimeValue, $expectedTimestamp) {
104 $checkDateResult = $this->testObject->checkDate($strToTimeValue);
105
106 // We use assertLessThan here, because we test with relatve values (eg. next Thursday, now, ..)
107 // If this tests runs over 1 seconds the test will fail if we use assertSame / assertEquals
108 // With assertLessThan the tests could run 0 till 3 seconds ($delta = 4)
109 $delta = 4;
110 $this->assertLessThan($delta, ($checkDateResult - $expectedTimestamp), 'AssertLessThan fails with value \'' . $strToTimeValue . '\'');
111 $this->assertType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $checkDateResult, 'assertType fails with value \'' . $strToTimeValue . '\'');
112 }
113
114 /**
115 * Provides dates in TYPO3 date field formats (non-US), i.e. H:i Y-m-d
116 *
117 * @see checkDateWithTypo3DateSyntax
118 * @return array Testdata for "checkDateWithTypo3DateSyntax".
119 * Structure: array(
120 * 'Value description' => array(
121 * 'value to pass to $this->testObject->checkDate',
122 * 'expected results which will be compared'
123 * )
124 * )
125 */
126 public function checkDateWithTypo3DateSyntaxDataProvider() {
127 return array(
128 '00:00 2011-05-30' => array(
129 '00:00 2011-05-30',
130 mktime(0, 0, 0, 5, 30, 2011)
131 ),
132 '00:01 2011-05-30' => array(
133 '00:01 2011-05-30',
134 mktime(0, 1, 0, 5, 30, 2011)
135 ),
136 '23:59 2011-05-30' => array(
137 '23:59 2011-05-30',
138 mktime(23, 59, 0, 5, 30, 2011)
139 ),
140 '15:35 2000-12-24' => array(
141 '15:35 2000-12-24',
142 mktime(15, 35, 0, 12, 24, 2000)
143 ),
144 '00:01 1970-01-01' => array(
145 '00:01 1970-01-01',
146 mktime(0, 1, 0, 1, 1, 1970)
147 ),
148 '17:26 2020-03-15' => array(
149 '17:26 2020-03-15',
150 mktime(17, 26, 0, 3, 15, 2020)
151 ),
152 '1:5 2020-03-15' => array(
153 '1:5 2020-03-15',
154 mktime(1, 5, 0, 3, 15, 2020)
155 ),
156 '10:50 2020-3-5' => array(
157 '10:50 2020-3-5',
158 mktime(10, 50, 0, 3, 5, 2020)
159 ),
160 '01:01 1968-01-01' => array(
161 '01:01 1968-01-01',
162 mktime(01, 01, 0, 1, 1, 1968)
163 ),
164 );
165 }
166
167 /**
168 * @dataProvider checkDateWithTypo3DateSyntaxDataProvider
169 * @test
170 * @param $typo3DateValue Testvalue which will be passed to $this->testObject->checkDate
171 * @param $expectedTimestamp Expected value to compare with result from operation
172 * @return void
173 */
174 public function checkDateWithTypo3DateSyntax($typo3DateValue, $expectedTimestamp) {
175 $this->assertSame($expectedTimestamp, $this->testObject->checkDate($typo3DateValue), 'Fails with value \'' . $typo3DateValue . '\'');
176 }
177
178 /**
179 * Provides some invalid dates
180 * @see checkDateWithInvalidDateValues
181 * @return array Testdata for "checkDateWithInvalidDateValues".
182 * Structure: array(
183 * 'Value description' => array(
184 * 'value to pass to $this->testObject->checkDate'
185 * )
186 * )
187 */
188 public function checkDateWithInvalidDateValuesDataProvider() {
189 return array(
190 'Not Good' => array(
191 'Not Good'
192 ),
193 'HH:ii yyyy-mm-dd' => array(
194 'HH:ii yyyy-mm-dd'
195 ),
196 );
197 }
198
199 /**
200 * This test must be raised an InvalidArgumentException
201 *
202 * @dataProvider checkDateWithInvalidDateValuesDataProvider
203 * @test
204 * @param $dateValue Testvalue which will be passed to $this->testObject->checkDate.
205 * @return void
206 */
207 public function checkDateWithInvalidDateValues($dateValue) {
208 $result = '';
209
210 try {
211 $result = $this->testObject->checkDate($dateValue);
212 }catch (InvalidArgumentException $expected) {
213 return;
214 }
215
216 $this->fail('Fails with value \'' . $dateValue . '\'. Returned \'' . $result . '\'.');
217 }
218 }
219 ?>