[BUGFIX] Fix PHP warning with date function in FormEngine
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / FormEngineTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Form;
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 use TYPO3\CMS\Core\Tests\UnitTestCase;
18
19 /**
20 * Test case
21 */
22 class FormEngineTest extends UnitTestCase {
23
24 /**
25 * @var \TYPO3\CMS\Backend\Form\FormEngine|\PHPUnit_Framework_MockObject_MockObject
26 */
27 protected $subject;
28
29 /**
30 * Sets up this test case.
31 */
32 protected function setUp() {
33 $this->subject = $this->getMock('TYPO3\\CMS\\Backend\\Form\\FormEngine', array('dummy'), array(), '', FALSE);
34 }
35
36 /**
37 * @return array
38 */
39 public function formatValueDataProvider() {
40 return array(
41 'format with empty format configuration' => array(
42 array(
43 'format' => '',
44 ),
45 '',
46 '',
47 ),
48 'format to date' => array(
49 array(
50 'format' => 'date',
51 ),
52 '1412358894',
53 '03-10-2014'
54 ),
55 'format to date with empty timestamp' => array(
56 array(
57 'format' => 'date',
58 ),
59 '0',
60 ''
61 ),
62 'format to date with blank timestamp' => array(
63 array(
64 'format' => 'date',
65 ),
66 '',
67 ''
68 ),
69 'format to date with option strftime' => array(
70 array(
71 'format' => 'date',
72 'format.' => array(
73 'option' => '%d-%m',
74 'strftime' => TRUE,
75 ),
76 ),
77 '1412358894',
78 '03-10'
79 ),
80 'format to date with option' => array(
81 array(
82 'format' => 'date',
83 'format.' => array(
84 'option' => 'd-m',
85 ),
86 ),
87 '1412358894',
88 '03-10'
89 ),
90 'format to datetime' => array(
91 array(
92 'format' => 'datetime',
93 ),
94 '1412358894',
95 '17:54 03-10-2014'
96 ),
97 'format to datetime with empty value' => array(
98 array(
99 'format' => 'datetime',
100 ),
101 '',
102 ''
103 ),
104 'format to time' => array(
105 array(
106 'format' => 'time',
107 ),
108 '1412358894',
109 '17:54'
110 ),
111 'format to time with empty value' => array(
112 array(
113 'format' => 'time',
114 ),
115 '',
116 ''
117 ),
118 'format to timesec' => array(
119 array(
120 'format' => 'timesec',
121 ),
122 '1412358894',
123 '17:54:54'
124 ),
125 'format to timesec with empty value' => array(
126 array(
127 'format' => 'timesec',
128 ),
129 '',
130 ''
131 ),
132 'format to year' => array(
133 array(
134 'format' => 'year',
135 ),
136 '1412358894',
137 '2014'
138 ),
139 'format to int' => array(
140 array(
141 'format' => 'int',
142 ),
143 '123.00',
144 '123'
145 ),
146 'format to int with base' => array(
147 array(
148 'format' => 'int',
149 'format.' => array(
150 'base' => 'oct',
151 ),
152 ),
153 '123',
154 '173'
155 ),
156 'format to int with empty value' => array(
157 array(
158 'format' => 'int',
159 ),
160 '',
161 '0'
162 ),
163 'format to float' => array(
164 array(
165 'format' => 'float',
166 ),
167 '123',
168 '123.00'
169 ),
170 'format to float with precision' => array(
171 array(
172 'format' => 'float',
173 'format.' => array(
174 'precision' => '4',
175 ),
176 ),
177 '123',
178 '123.0000'
179 ),
180 'format to float with empty value' => array(
181 array(
182 'format' => 'float',
183 ),
184 '',
185 '0.00'
186 ),
187 'format to number' => array(
188 array(
189 'format' => 'number',
190 'format.' => array(
191 'option' => 'b',
192 ),
193 ),
194 '123',
195 '1111011'
196 ),
197 'format to number with empty option' => array(
198 array(
199 'format' => 'number',
200 ),
201 '123',
202 ''
203 ),
204 'format to md5' => array(
205 array(
206 'format' => 'md5',
207 ),
208 'joh316',
209 'bacb98acf97e0b6112b1d1b650b84971'
210 ),
211 'format to md5 with empty value' => array(
212 array(
213 'format' => 'md5',
214 ),
215 '',
216 'd41d8cd98f00b204e9800998ecf8427e'
217 ),
218 'format to filesize' => array(
219 array(
220 'format' => 'filesize',
221 ),
222 '100000',
223 '98 K'
224 ),
225 'format to filesize with empty value' => array(
226 array(
227 'format' => 'filesize',
228 ),
229 '',
230 '0 '
231 ),
232 'format to filesize with option appendByteSize' => array(
233 array(
234 'format' => 'filesize',
235 'format.' => array(
236 'appendByteSize' => TRUE,
237 ),
238 ),
239 '100000',
240 '98 K (100000)'
241 ),
242 );
243 }
244
245 /**
246 * @param array $config
247 * @param string $itemValue
248 * @param string $expectedResult
249 * @dataProvider formatValueDataProvider
250 * @test
251 */
252 public function formatValueWithGivenConfiguration($config, $itemValue, $expectedResult) {
253 $timezoneBackup = date_default_timezone_get();
254 date_default_timezone_set('UTC');
255 $result = $this->subject->formatValue($config, $itemValue);
256 date_default_timezone_set($timezoneBackup);
257
258 $this->assertEquals($expectedResult, $result);
259 }
260
261 }