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