f916eab0f657af4b0e0fdcbefebad8a1e52696bf
[Packages/TYPO3.CMS.git] / typo3 / sysext / scheduler / Tests / Unit / CronCommand / NormalizeCommandTest.php
1 <?php
2 namespace TYPO3\CMS\Scheduler\Tests\Unit\CronCommand;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Test case
19 *
20 * @author Christian Kuhn <lolli@schwarzbu.ch>
21 */
22 class NormalizeCommandTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
23
24 /**
25 * Create a subclass with protected methods made public
26 *
27 * @return string Name of the accessible proxy class
28 */
29 protected function getAccessibleProxy() {
30 $className = $this->getUniqueId('NormalizeCommand');
31 $fullClassName = __NAMESPACE__ . '\\' . $className;
32 if (!class_exists($className, FALSE)) {
33 eval(
34 'namespace ' . __NAMESPACE__ . ';' .
35 'class ' . $className . ' extends \\TYPO3\\CMS\\Scheduler\\CronCommand\\NormalizeCommand {' .
36 ' public static function convertKeywordsToCronCommand($cronCommand) {' .
37 ' return parent::convertKeywordsToCronCommand($cronCommand);' .
38 ' }' .
39 ' public static function normalizeFields($cronCommand) {' .
40 ' return parent::normalizeFields($cronCommand);' .
41 ' }' .
42 ' public static function normalizeMonthAndWeekdayField($expression, $isMonthField = TRUE) {' .
43 ' return parent::normalizeMonthAndWeekdayField($expression, $isMonthField);' .
44 ' }' .
45 ' public static function normalizeIntegerField($expression, $lowerBound = 0, $upperBound = 59) {' .
46 ' return parent::normalizeIntegerField($expression, $lowerBound, $upperBound);' .
47 ' }' .
48 ' public static function splitFields($cronCommand) {' .
49 ' return parent::splitFields($cronCommand);' .
50 ' }' .
51 ' public static function convertRangeToListOfValues($range) {' .
52 ' return parent::convertRangeToListOfValues($range);' .
53 ' }' .
54 ' public static function reduceListOfValuesByStepValue($stepExpression) {' .
55 ' return parent::reduceListOfValuesByStepValue($stepExpression);' .
56 ' }' .
57 ' public static function normalizeMonthAndWeekday($expression, $isMonth = TRUE) {' .
58 ' return parent::normalizeMonthAndWeekday($expression, $isMonth);' .
59 ' }' .
60 ' public static function normalizeMonth($month) {' .
61 ' return parent::normalizeMonth($month);' .
62 ' }' .
63 ' public static function normalizeWeekday($weekday) {' .
64 ' return parent::normalizeWeekday($weekday);' .
65 ' }' .
66 '}'
67 );
68 }
69 return $fullClassName;
70 }
71
72 /**
73 * @return array
74 */
75 static public function normalizeValidDataProvider() {
76 return array(
77 '@weekly' => array('@weekly', '0 0 * * 7'),
78 ' @weekly ' => array(' @weekly ', '0 0 * * 7'),
79 '* * * * *' => array('* * * * *', '* * * * *'),
80 '30 4 1,15 * 5' => array('30 4 1,15 * 5', '30 4 1,15 * 5'),
81 '5 0 * * *' => array('5 0 * * *', '5 0 * * *'),
82 '15 14 1 * *' => array('15 14 1 * *', '15 14 1 * *'),
83 '0 22 * * 1-5' => array('0 22 * * 1-5', '0 22 * * 1,2,3,4,5'),
84 '23 0-23/2 * * *' => array('23 0-23/2 * * *', '23 0,2,4,6,8,10,12,14,16,18,20,22 * * *'),
85 '5 4 * * sun' => array('5 4 * * sun', '5 4 * * 7'),
86 '0-3/2,7 0,4 20-22, feb,mar-jun/2,7 1-3,sun' => array('0-3/2,7 0,4 20-22 feb,mar-jun/2,7 1-3,sun', '0,2,7 0,4 20,21,22 2,3,5,7 1,2,3,7'),
87 '0-20/10 * * * *' => array('0-20/10 * * * *', '0,10,20 * * * *'),
88 '* * 2 * *' => array('* * 2 * *', '* * 2 * *'),
89 '* * 2,7 * *' => array('* * 2,7 * *', '* * 2,7 * *'),
90 '* * 2-4,10 * *' => array('* * 2-4,10 * *', '* * 2,3,4,10 * *'),
91 '* * */14 * *' => array('* * */14 * *', '* * 1,15,29 * *'),
92 '* * 2,4-6/2,*/14 * *' => array('* * 2,4-6/2,*/14 * *', '* * 1,2,4,6,15,29 * *'),
93 '* * * * 1' => array('* * * * 1', '* * * * 1'),
94 '0 0 * * 0' => array('0 0 * * 0', '0 0 * * 7'),
95 '0 0 * * 7' => array('0 0 * * 7', '0 0 * * 7'),
96 '* * 1,2 * 1' => array('* * 1,2 * 1', '* * 1,2 * 1')
97 );
98 }
99
100 /**
101 * @test
102 * @dataProvider normalizeValidDataProvider
103 * @param string $expression Cron command to test
104 * @param string $expected Expected result (normalized cron command syntax)
105 */
106 public function normalizeConvertsCronCommand($expression, $expected) {
107 $result = \TYPO3\CMS\Scheduler\CronCommand\NormalizeCommand::normalize($expression);
108 $this->assertEquals($expected, $result);
109 }
110
111 /**
112 * @return array
113 */
114 static public function validSpecialKeywordsDataProvider() {
115 return array(
116 '@yearly' => array('@yearly', '0 0 1 1 *'),
117 '@annually' => array('@annually', '0 0 1 1 *'),
118 '@monthly' => array('@monthly', '0 0 1 * *'),
119 '@weekly' => array('@weekly', '0 0 * * 0'),
120 '@daily' => array('@daily', '0 0 * * *'),
121 '@midnight' => array('@midnight', '0 0 * * *'),
122 '@hourly' => array('@hourly', '0 * * * *')
123 );
124 }
125
126 /**
127 * @test
128 * @dataProvider validSpecialKeywordsDataProvider
129 * @param string $keyword Cron command keyword
130 * @param string $expectedCronCommand Expected result (normalized cron command syntax)
131 */
132 public function convertKeywordsToCronCommandConvertsValidKeywords($keyword, $expectedCronCommand) {
133 $accessibleProxyClassName = $this->getAccessibleProxy();
134 $result = $accessibleProxyClassName::convertKeywordsToCronCommand($keyword);
135 $this->assertEquals($expectedCronCommand, $result);
136 }
137
138 /**
139 * @test
140 */
141 public function convertKeywordsToCronCommandReturnsUnchangedCommandIfKeywordWasNotFound() {
142 $invalidKeyword = 'foo';
143 $accessibleProxyClassName = $this->getAccessibleProxy();
144 $result = $accessibleProxyClassName::convertKeywordsToCronCommand($invalidKeyword);
145 $this->assertEquals($invalidKeyword, $result);
146 }
147
148 /**
149 * @return array
150 */
151 public function normalizeFieldsValidDataProvider() {
152 return array(
153 '1-2 * * * *' => array('1-2 * * * *', '1,2 * * * *'),
154 '* 1-2 * * *' => array('* 1-2 * * *', '* 1,2 * * *'),
155 '* * 1-2 * *' => array('* * 1-2 * *', '* * 1,2 * *'),
156 '* * * 1-2 *' => array('* * * 1-2 *', '* * * 1,2 *'),
157 '* * * * 1-2' => array('* * * * 1-2', '* * * * 1,2')
158 );
159 }
160
161 /**
162 * @test
163 * @dataProvider normalizeFieldsValidDataProvider
164 * @param string $expression Cron command to normalize
165 * @param string $expected Expected result (normalized cron command syntax)
166 */
167 public function normalizeFieldsConvertsField($expression, $expected) {
168 $accessibleProxyClassName = $this->getAccessibleProxy();
169 $result = $accessibleProxyClassName::normalizeFields($expression);
170 $this->assertEquals($expected, $result);
171 }
172
173 /**
174 * @return array
175 */
176 static public function normalizeMonthAndWeekdayFieldValidDataProvider() {
177 return array(
178 '* monthField' => array('*', TRUE, '*'),
179 'string 1 monthField' => array('1', TRUE, '1'),
180 'jan' => array('jan', TRUE, '1'),
181 'feb/2' => array('feb/2', TRUE, '2'),
182 'jan-feb/2' => array('jan-feb/2', TRUE, '1'),
183 '1-2 monthField' => array('1-2', TRUE, '1,2'),
184 '1-3/2,feb,may,6' => array('1-3/2,feb,may,6', TRUE, '1,2,3,5,6'),
185 '*/4' => array('*/4', TRUE, '1,5,9'),
186 '* !monthField' => array('*', FALSE, '*'),
187 'string 1, !monthField' => array('1', FALSE, '1'),
188 'fri' => array('fri', FALSE, '5'),
189 'sun' => array('sun', FALSE, '7'),
190 'string 0 for sunday' => array('0', FALSE, '7'),
191 '0,1' => array('0,1', FALSE, '1,7'),
192 '*/3' => array('*/3', FALSE, '1,4,7'),
193 'tue/2' => array('tue/2', FALSE, '2'),
194 '1-2 !monthField' => array('1-2', FALSE, '1,2'),
195 'tue-fri/2' => array('tue-fri/2', FALSE, '2,4'),
196 '1-3/2,tue,fri,6' => array('1-3/2,tue,fri,6', FALSE, '1,2,3,5,6')
197 );
198 }
199
200 /**
201 * @test
202 * @dataProvider normalizeMonthAndWeekdayFieldValidDataProvider
203 * @param string $expression Cron command partial expression for month and weekday fields
204 * @param bool $isMonthField Flag to designate month field or not
205 * @param string $expected Expected result (normalized months or weekdays)
206 */
207 public function normalizeMonthAndWeekdayFieldReturnsNormalizedListForValidExpression($expression, $isMonthField, $expected) {
208 $accessibleProxyClassName = $this->getAccessibleProxy();
209 $result = $accessibleProxyClassName::normalizeMonthAndWeekdayField($expression, $isMonthField);
210 $this->assertSame($expected, $result);
211 }
212
213 /**
214 * @return array
215 */
216 static public function normalizeMonthAndWeekdayFieldInvalidDataProvider() {
217 return array(
218 'mon' => array('mon', TRUE),
219 '1-2/mon' => array('1-2/mon', TRUE),
220 '0,1' => array('0,1', TRUE),
221 'feb' => array('feb', FALSE),
222 '1-2/feb' => array('1-2/feb', FALSE),
223 '0-fri/2,7' => array('0-fri/2,7', FALSE, '2,4,7')
224 );
225 }
226
227 /**
228 * @test
229 * @dataProvider normalizeMonthAndWeekdayFieldInvalidDataProvider
230 * @expectedException \InvalidArgumentException
231 * @param string $expression Cron command partial expression for month and weekday fields (invalid)
232 * @param bool $isMonthField Flag to designate month field or not
233 */
234 public function normalizeMonthAndWeekdayFieldThrowsExceptionForInvalidExpression($expression, $isMonthField) {
235 $accessibleProxyClassName = $this->getAccessibleProxy();
236 $result = $accessibleProxyClassName::normalizeMonthAndWeekdayField($expression, $isMonthField);
237 }
238
239 /**
240 * @return array
241 */
242 static public function normalizeIntegerFieldValidDataProvider() {
243 return array(
244 '*' => array('*', '*'),
245 'string 2' => array('2', '2'),
246 'integer 3' => array(3, '3'),
247 'list of values' => array('1,2,3', '1,2,3'),
248 'unsorted list of values' => array('3,1,5', '1,3,5'),
249 'duplicate values' => array('0-2/2,2', '0,2'),
250 'additional field between steps' => array('1-3/2,2', '1,2,3'),
251 '2-4' => array('2-4', '2,3,4'),
252 'simple step 4/4' => array('4/4', '4'),
253 'step 2-7/5' => array('2-7/5', '2,7'),
254 'steps 4-12/4' => array('4-12/4', '4,8,12'),
255 '0-59/20' => array('0-59/20', '0,20,40'),
256 '*/20' => array('*/20', '0,20,40')
257 );
258 }
259
260 /**
261 * @test
262 * @dataProvider normalizeIntegerFieldValidDataProvider
263 * @param string $expression Cron command partial integer expression
264 * @param string $expected Expected result (normalized integer or integer list)
265 */
266 public function normalizeIntegerFieldReturnsNormalizedListForValidExpression($expression, $expected) {
267 $accessibleProxyClassName = $this->getAccessibleProxy();
268 $result = $accessibleProxyClassName::normalizeIntegerField($expression);
269 $this->assertSame($expected, $result);
270 }
271
272 /**
273 * @return array
274 */
275 static public function normalizeIntegerFieldInvalidDataProvider() {
276 return array(
277 'string foo' => array('foo', 0, 59),
278 'empty string' => array('', 0, 59),
279 '4-3' => array('4-3', 0, 59),
280 '/2' => array('/2', 0, 59),
281 '/' => array('/', 0, 59),
282 'left bound too low' => array('2-4', 3, 4),
283 'right bound too high' => array('2-4', 2, 3),
284 'left and right bound' => array('2-5', 2, 4),
285 'element in list is lower than allowed' => array('2,1,4', 2, 4),
286 'element in list is higher than allowed' => array('2,5,4', 1, 4)
287 );
288 }
289
290 /**
291 * @test
292 * @dataProvider normalizeIntegerFieldInvalidDataProvider
293 * @expectedException \InvalidArgumentException
294 * @param string $expression Cron command partial integer expression (invalid)
295 * @param int $lowerBound Lower limit
296 * @param int $upperBound Upper limit
297 */
298 public function normalizeIntegerFieldThrowsExceptionForInvalidExpressions($expression, $lowerBound, $upperBound) {
299 $accessibleProxyClassName = $this->getAccessibleProxy();
300 $accessibleProxyClassName::normalizeIntegerField($expression, $lowerBound, $upperBound);
301 }
302
303 /**
304 * @test
305 */
306 public function splitFieldsReturnsIntegerArrayWithFieldsSplitByWhitespace() {
307 $accessibleProxyClassName = $this->getAccessibleProxy();
308 $result = $accessibleProxyClassName::splitFields('12,13 * 1-12/2,14 jan fri');
309 $expectedResult = array(
310 0 => '12,13',
311 1 => '*',
312 2 => '1-12/2,14',
313 3 => 'jan',
314 4 => 'fri'
315 );
316 $this->assertSame($expectedResult, $result);
317 }
318
319 /**
320 * @return array
321 */
322 static public function invalidCronCommandFieldsDataProvider() {
323 return array(
324 'empty string' => array(''),
325 'foo' => array('foo'),
326 'integer 4' => array(4),
327 'four fields' => array('* * * *'),
328 'six fields' => array('* * * * * *')
329 );
330 }
331
332 /**
333 * @test
334 * @expectedException \InvalidArgumentException
335 * @dataProvider invalidCronCommandFieldsDataProvider
336 * @param string $cronCommand Invalid cron command
337 */
338 public function splitFieldsThrowsExceptionIfCronCommandDoesNotContainFiveFields($cronCommand) {
339 $accessibleProxyClassName = $this->getAccessibleProxy();
340 $accessibleProxyClassName::splitFields($cronCommand);
341 }
342
343 /**
344 * @return array
345 */
346 static public function validRangeDataProvider() {
347 return array(
348 'single value' => array('3', '3'),
349 'integer 3' => array(3, '3'),
350 '0-0' => array('0-0', '0'),
351 '4-4' => array('4-4', '4'),
352 '0-3' => array('0-3', '0,1,2,3'),
353 '4-5' => array('4-5', '4,5')
354 );
355 }
356
357 /**
358 * @test
359 * @dataProvider validRangeDataProvider
360 * @param string $range Cron command range expression
361 * @param string $expected Expected result (normalized range)
362 */
363 public function convertRangeToListOfValuesReturnsCorrectListForValidRanges($range, $expected) {
364 $accessibleProxyClassName = $this->getAccessibleProxy();
365 $result = $accessibleProxyClassName::convertRangeToListOfValues($range);
366 $this->assertSame($expected, $result);
367 }
368
369 /**
370 * @return array
371 */
372 static public function invalidRangeDataProvider() {
373 return array(
374 'empty string' => array(''),
375 'string' => array('foo'),
376 'single dash' => array('-'),
377 'left part is string' => array('foo-5'),
378 'right part is string' => array('5-foo'),
379 'range of strings' => array('foo-bar'),
380 'string five minus' => array('5-'),
381 'string minus five' => array('-5'),
382 'more than one dash' => array('2-3-4'),
383 'left part bigger than right part' => array('6-3')
384 );
385 }
386
387 /**
388 * @test
389 * @dataProvider invalidRangeDataProvider
390 * @expectedException \InvalidArgumentException
391 * @param string $range Cron command range expression (invalid)
392 */
393 public function convertRangeToListOfValuesThrowsExceptionForInvalidRanges($range) {
394 $accessibleProxyClassName = $this->getAccessibleProxy();
395 $accessibleProxyClassName::convertRangeToListOfValues($range);
396 }
397
398 /**
399 * @return array
400 */
401 static public function validStepsDataProvider() {
402 return array(
403 '2/2' => array('2/2', '2'),
404 '2,3,4/2' => array('2,3,4/2', '2,4'),
405 '1,2,3,4,5,6,7/3' => array('1,2,3,4,5,6,7/3', '1,4,7'),
406 '0,1,2,3,4,5,6/3' => array('0,1,2,3,4,5,6/3', '0,3,6')
407 );
408 }
409
410 /**
411 * @test
412 * @dataProvider validStepsDataProvider
413 * @param string $stepExpression Cron command step expression
414 * @param string $expected Expected result (normalized range)
415 */
416 public function reduceListOfValuesByStepValueReturnsCorrectListOfValues($stepExpression, $expected) {
417 $accessibleProxyClassName = $this->getAccessibleProxy();
418 $result = $accessibleProxyClassName::reduceListOfValuesByStepValue($stepExpression);
419 $this->assertSame($expected, $result);
420 }
421
422 /**
423 * @return array
424 */
425 static public function invalidStepsDataProvider() {
426 return array(
427 'empty string' => array(''),
428 'slash only' => array('/'),
429 'left part empty' => array('/2'),
430 'right part empty' => array('2/'),
431 'multiples slashes' => array('1/2/3'),
432 '2-2' => array('2-2'),
433 '2.3/2' => array('2.3/2'),
434 '2,3,4/2.3' => array('2,3,4/2.3'),
435 '2,3,4/2,3' => array('2,3,4/2,3')
436 );
437 }
438
439 /**
440 * @test
441 * @dataProvider invalidStepsDataProvider
442 * @expectedException \InvalidArgumentException
443 * @param string $stepExpression Cron command step expression (invalid)
444 */
445 public function reduceListOfValuesByStepValueThrowsExceptionForInvalidStepExpressions($stepExpression) {
446 $accessibleProxyClassName = $this->getAccessibleProxy();
447 $accessibleProxyClassName::reduceListOfValuesByStepValue($stepExpression);
448 }
449
450 /**
451 * @test
452 */
453 public function normalizeMonthAndWeekdayNormalizesAMonth() {
454 $accessibleProxyClassName = $this->getAccessibleProxy();
455 $result = $accessibleProxyClassName::normalizeMonthAndWeekday('feb', TRUE);
456 $this->assertSame('2', $result);
457 }
458
459 /**
460 * @test
461 */
462 public function normalizeMonthAndWeekdayNormalizesAWeekday() {
463 $accessibleProxyClassName = $this->getAccessibleProxy();
464 $result = $accessibleProxyClassName::normalizeMonthAndWeekday('fri', FALSE);
465 $this->assertSame('5', $result);
466 }
467
468 /**
469 * @test
470 */
471 public function normalizeMonthAndWeekdayLeavesValueUnchanged() {
472 $accessibleProxyClassName = $this->getAccessibleProxy();
473 $result = $accessibleProxyClassName::normalizeMonthAndWeekday('2');
474 $this->assertSame('2', $result);
475 }
476
477 /**
478 * @return array
479 */
480 static public function validMonthNamesDataProvider() {
481 return array(
482 'jan' => array('jan', 1),
483 'feb' => array('feb', 2),
484 'MaR' => array('MaR', 3),
485 'aPr' => array('aPr', 4),
486 'MAY' => array('MAY', 5),
487 'jun' => array('jun', 6),
488 'jul' => array('jul', 7),
489 'aug' => array('aug', 8),
490 'sep' => array('sep', 9),
491 'oct' => array('oct', 10),
492 'nov' => array('nov', 11),
493 'dec' => array('dec', 12),
494 'string 7' => array('7', 7),
495 'integer 7' => array(7, 7),
496 'string 07' => array('07', 7),
497 'integer 07' => array(7, 7)
498 );
499 }
500
501 /**
502 * @test
503 * @dataProvider validMonthNamesDataProvider
504 * @param string $monthName Month name
505 * @param int $expectedInteger Number of the month
506 */
507 public function normalizeMonthConvertsName($monthName, $expectedInteger) {
508 $accessibleProxyClassName = $this->getAccessibleProxy();
509 $result = $accessibleProxyClassName::normalizeMonth($monthName);
510 $this->assertEquals($expectedInteger, $result);
511 }
512
513 /**
514 * @test
515 * @dataProvider validMonthNamesDataProvider
516 * @param string $monthName Month name
517 * @param int $expectedInteger Number of the month (not used)
518 */
519 public function normalizeMonthReturnsInteger($monthName, $expectedInteger) {
520 $accessibleProxyClassName = $this->getAccessibleProxy();
521 $result = $accessibleProxyClassName::normalizeMonth($monthName);
522 $this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_INT, $result);
523 }
524
525 /**
526 * @return array
527 */
528 static public function invalidMonthNamesDataProvider() {
529 return array(
530 'sep-' => array('sep-'),
531 '-September-' => array('-September-'),
532 ',sep' => array(',sep'),
533 ',September,' => array(',September,'),
534 'sep/' => array('sep/'),
535 '/sep' => array('/sep'),
536 '/September/' => array('/September/'),
537 'foo' => array('foo'),
538 'Tuesday' => array('Tuesday'),
539 'Tue' => array('Tue'),
540 'string 0' => array('0'),
541 'integer 0' => array(0),
542 'string seven' => array('seven'),
543 'string 13' => array('13'),
544 'integer 13' => array(13),
545 'integer 100' => array(100),
546 'integer 2010' => array(2010),
547 'string minus 7' => array('-7'),
548 'negative integer 7' => array(-7)
549 );
550 }
551
552 /**
553 * @test
554 * @expectedException \InvalidArgumentException
555 * @dataProvider invalidMonthNamesDataProvider
556 * @param string $invalidMonthName Month name (invalid)
557 */
558 public function normalizeMonthThrowsExceptionForInvalidMonthRepresentation($invalidMonthName) {
559 $accessibleProxyClassName = $this->getAccessibleProxy();
560 $accessibleProxyClassName::normalizeMonth($invalidMonthName);
561 }
562
563 /**
564 * @return array
565 */
566 static public function validWeekdayDataProvider() {
567 return array(
568 'string 1' => array('1', 1),
569 'string 2' => array('2', 2),
570 'string 02' => array('02', 2),
571 'integer 02' => array(2, 2),
572 'string 3' => array('3', 3),
573 'string 4' => array('4', 4),
574 'string 5' => array('5', 5),
575 'integer 5' => array(5, 5),
576 'string 6' => array('6', 6),
577 'string 7' => array('7', 7),
578 'string 0' => array('0', 7),
579 'integer 0' => array(0, 7),
580 'mon' => array('mon', 1),
581 'monday' => array('monday', 1),
582 'tue' => array('tue', 2),
583 'tuesday' => array('tuesday', 2),
584 'WED' => array('WED', 3),
585 'WEDnesday' => array('WEDnesday', 3),
586 'tHu' => array('tHu', 4),
587 'Thursday' => array('Thursday', 4),
588 'fri' => array('fri', 5),
589 'friday' => array('friday', 5),
590 'sat' => array('sat', 6),
591 'saturday' => array('saturday', 6),
592 'sun' => array('sun', 7),
593 'sunday' => array('sunday', 7)
594 );
595 }
596
597 /**
598 * @test
599 * @dataProvider validWeekdayDataProvider
600 * @param string $weekday Weekday expression
601 * @param int $expectedInteger Number of weekday
602 */
603 public function normalizeWeekdayConvertsName($weekday, $expectedInteger) {
604 $accessibleProxyClassName = $this->getAccessibleProxy();
605 $result = $accessibleProxyClassName::normalizeWeekday($weekday);
606 $this->assertEquals($expectedInteger, $result);
607 }
608
609 /**
610 * @test
611 * @dataProvider validWeekdayDataProvider
612 * @param string $weekday Weekday expression
613 * @param int $expectedInteger Number of weekday (not used)
614 */
615 public function normalizeWeekdayReturnsInteger($weekday, $expectedInteger) {
616 $accessibleProxyClassName = $this->getAccessibleProxy();
617 $result = $accessibleProxyClassName::normalizeWeekday($weekday);
618 $this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_INT, $result);
619 }
620
621 /**
622 * @return array
623 */
624 static public function invalidWeekdayDataProvider() {
625 return array(
626 '-fri' => array('-fri'),
627 'fri-' => array('fri-'),
628 '-friday-' => array('-friday-'),
629 '/fri' => array('/fri'),
630 'fri/' => array('fri/'),
631 '/friday/' => array('/friday/'),
632 ',fri' => array(',fri'),
633 ',friday,' => array(',friday,'),
634 'string minus 1' => array('-1'),
635 'integer -1' => array(-1),
636 'string seven' => array('seven'),
637 'string 8' => array('8'),
638 'string 8' => array('8'),
639 'string 29' => array('29'),
640 'string 2010' => array('2010'),
641 'Jan' => array('Jan'),
642 'January' => array('January'),
643 'MARCH' => array('MARCH')
644 );
645 }
646
647 /**
648 * @test
649 * @dataProvider invalidWeekdayDataProvider
650 * @expectedException \InvalidArgumentException
651 * @param string $weekday Weekday expression (invalid)
652 */
653 public function normalizeWeekdayThrowsExceptionForInvalidWeekdayRepresentation($weekday) {
654 $accessibleProxyClassName = $this->getAccessibleProxy();
655 $accessibleProxyClassName::normalizeWeekday($weekday);
656 }
657
658 }