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