TYPO3 CMS  TYPO3_7-6
SchedulerModuleControllerTest.php
Go to the documentation of this file.
1 <?php
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 
21 {
25  protected $testObject;
26 
32  protected function setUp()
33  {
34  $this->testObject = $this->getMock(\TYPO3\CMS\Scheduler\Controller\SchedulerModuleController::class, ['dummy'], [], '', false);
35  }
36 
44  {
45  return [
46  'now' => [
47  'now',
48  ],
49  '10 September 2000' => [
50  '10 September 2000',
51  ],
52  '+1 day' => [
53  '+1 day',
54  ],
55  '+1 week' => [
56  '+1 week',
57  ],
58  '+1 week 2 days 4 hours 2 seconds' => [
59  '+1 week 2 days 4 hours 2 seconds',
60  ],
61  'next Thursday' => [
62  'next Thursday',
63  ],
64  'last Monday' => [
65  'last Monday',
66  ]
67  ];
68  }
69 
76  public function checkDateWithStrtotimeValues($strToTimeValue)
77  {
78  $expectedTimestamp = strtotime($strToTimeValue);
79  $checkDateResult = $this->testObject->checkDate($strToTimeValue);
80  // We use assertLessThan here, because we test with relative values (eg. next Thursday, now, ..)
81  // If this tests runs over 1 seconds the test will fail if we use assertSame / assertEquals
82  // With assertLessThan the tests could run 0 till 3 seconds ($delta = 4)
83  $delta = 4;
84  $this->assertLessThan($delta, $checkDateResult - $expectedTimestamp, 'assertLessThan fails with value "' . $strToTimeValue . '"');
85  $this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_INT, $checkDateResult, 'assertType fails with value "' . $strToTimeValue . '"');
86  }
87 
95  {
96  return [
97  '00:00 2011-05-30' => [
98  '00:00 2011-05-30',
99  mktime(0, 0, 0, 5, 30, 2011)
100  ],
101  '00:01 2011-05-30' => [
102  '00:01 2011-05-30',
103  mktime(0, 1, 0, 5, 30, 2011)
104  ],
105  '23:59 2011-05-30' => [
106  '23:59 2011-05-30',
107  mktime(23, 59, 0, 5, 30, 2011)
108  ],
109  '15:35 2000-12-24' => [
110  '15:35 2000-12-24',
111  mktime(15, 35, 0, 12, 24, 2000)
112  ],
113  '00:01 1970-01-01' => [
114  '00:01 1970-01-01',
115  mktime(0, 1, 0, 1, 1, 1970)
116  ],
117  '17:26 2020-03-15' => [
118  '17:26 2020-03-15',
119  mktime(17, 26, 0, 3, 15, 2020)
120  ],
121  '1:5 2020-03-15' => [
122  '1:5 2020-03-15',
123  mktime(1, 5, 0, 3, 15, 2020)
124  ],
125  '10:50 2020-3-5' => [
126  '10:50 2020-3-5',
127  mktime(10, 50, 0, 3, 5, 2020)
128  ],
129  '01:01 1968-01-01' => [
130  '01:01 1968-01-01',
131  mktime(1, 1, 0, 1, 1, 1968)
132  ]
133  ];
134  }
135 
142  public function checkDateWithTypo3DateSyntax($typo3DateValue, $expectedTimestamp)
143  {
144  $this->assertSame($expectedTimestamp, $this->testObject->checkDate($typo3DateValue), 'Fails with value "' . $typo3DateValue . '"');
145  }
146 
154  {
155  return [
156  'Not Good' => [
157  'Not Good'
158  ],
159  'HH:ii yyyy-mm-dd' => [
160  'HH:ii yyyy-mm-dd'
161  ]
162  ];
163  }
164 
173  public function checkDateWithInvalidDateValues($dateValue)
174  {
175  $this->testObject->checkDate($dateValue);
176  }
177 }