[BUGFIX] Tests: Incomplete mock in ext:scheduler
[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-2013 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 /**
28 * Test case
29 *
30 * @author Andy Grunwald <andreas.grunwald@wmdb.de>
31 */
32 class SchedulerModuleControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
33
34 /**
35 * @var \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController
36 */
37 protected $testObject;
38
39 /**
40 * Sets up each test case.
41 *
42 * @return void
43 */
44 public function setUp() {
45 $this->testObject = $this->getMock('TYPO3\\CMS\\Scheduler\\Controller\\SchedulerModuleController', array('dummy'), array(), '', FALSE);
46 }
47
48 /**
49 * Data provider for checkDateWithStrtotimeValues
50 *
51 * @see checkDateWithStrtotimeValues
52 * @return array Testdata for "checkDateWithStrtotimeValues".
53 */
54 public function checkDateWithStrtotimeValuesDataProvider() {
55 return array(
56 'now' => array(
57 'now',
58 ),
59 '10 September 2000' => array(
60 '10 September 2000',
61 ),
62 '+1 day' => array(
63 '+1 day',
64 ),
65 '+1 week' => array(
66 '+1 week',
67 ),
68 '+1 week 2 days 4 hours 2 seconds' => array(
69 '+1 week 2 days 4 hours 2 seconds',
70 ),
71 'next Thursday' => array(
72 'next Thursday',
73 ),
74 'last Monday' => array(
75 'last Monday',
76 )
77 );
78 }
79
80 /**
81 * @dataProvider checkDateWithStrtotimeValuesDataProvider
82 * @test
83 * @see http://de.php.net/manual/de/function.strtotime.php
84 * @param string $strToTimeValue Test value which will be passed to $this->testObject->checkDate
85 * @param integer $expectedTimestamp Expected value to compare with result from operation
86 */
87 public function checkDateWithStrtotimeValues($strToTimeValue) {
88 $expectedTimestamp = strtotime($strToTimeValue);
89 $checkDateResult = $this->testObject->checkDate($strToTimeValue);
90 // We use assertLessThan here, because we test with relative values (eg. next Thursday, now, ..)
91 // If this tests runs over 1 seconds the test will fail if we use assertSame / assertEquals
92 // With assertLessThan the tests could run 0 till 3 seconds ($delta = 4)
93 $delta = 4;
94 $this->assertLessThan($delta, $checkDateResult - $expectedTimestamp, 'assertLessThan fails with value "' . $strToTimeValue . '"');
95 $this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_INT, $checkDateResult, 'assertType fails with value "' . $strToTimeValue . '"');
96 }
97
98 /**
99 * Provides dates in TYPO3 date field formats (non-US), i.e. H:i Y-m-d
100 *
101 * @see checkDateWithTypo3DateSyntax
102 * @return array Testdata for "checkDateWithTypo3DateSyntax".
103 */
104 public function checkDateWithTypo3DateSyntaxDataProvider() {
105 return array(
106 '00:00 2011-05-30' => array(
107 '00:00 2011-05-30',
108 mktime(0, 0, 0, 5, 30, 2011)
109 ),
110 '00:01 2011-05-30' => array(
111 '00:01 2011-05-30',
112 mktime(0, 1, 0, 5, 30, 2011)
113 ),
114 '23:59 2011-05-30' => array(
115 '23:59 2011-05-30',
116 mktime(23, 59, 0, 5, 30, 2011)
117 ),
118 '15:35 2000-12-24' => array(
119 '15:35 2000-12-24',
120 mktime(15, 35, 0, 12, 24, 2000)
121 ),
122 '00:01 1970-01-01' => array(
123 '00:01 1970-01-01',
124 mktime(0, 1, 0, 1, 1, 1970)
125 ),
126 '17:26 2020-03-15' => array(
127 '17:26 2020-03-15',
128 mktime(17, 26, 0, 3, 15, 2020)
129 ),
130 '1:5 2020-03-15' => array(
131 '1:5 2020-03-15',
132 mktime(1, 5, 0, 3, 15, 2020)
133 ),
134 '10:50 2020-3-5' => array(
135 '10:50 2020-3-5',
136 mktime(10, 50, 0, 3, 5, 2020)
137 ),
138 '01:01 1968-01-01' => array(
139 '01:01 1968-01-01',
140 mktime(1, 1, 0, 1, 1, 1968)
141 )
142 );
143 }
144
145 /**
146 * @dataProvider checkDateWithTypo3DateSyntaxDataProvider
147 * @test
148 * @param string $typo3DateValue Test value which will be passed to $this->testObject->checkDate
149 * @param integer $expectedTimestamp Expected value to compare with result from operation
150 */
151 public function checkDateWithTypo3DateSyntax($typo3DateValue, $expectedTimestamp) {
152 $this->assertSame($expectedTimestamp, $this->testObject->checkDate($typo3DateValue), 'Fails with value "' . $typo3DateValue . '"');
153 }
154
155 /**
156 * Provides some invalid dates
157 *
158 * @see checkDateWithInvalidDateValues
159 * @return array Test data for "checkDateWithInvalidDateValues".
160 */
161 public function checkDateWithInvalidDateValuesDataProvider() {
162 return array(
163 'Not Good' => array(
164 'Not Good'
165 ),
166 'HH:ii yyyy-mm-dd' => array(
167 'HH:ii yyyy-mm-dd'
168 )
169 );
170 }
171
172 /**
173 * This test must be raised an InvalidArgumentException
174 *
175 * @dataProvider checkDateWithInvalidDateValuesDataProvider
176 * @expectedException \InvalidArgumentException
177 * @test
178 * @param string $dateValue Test value which will be passed to $this->testObject->checkDate.
179 */
180 public function checkDateWithInvalidDateValues($dateValue) {
181 $this->testObject->checkDate($dateValue);
182 }
183
184 }