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