‪TYPO3CMS  10.4
AbstractFormElementTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20 
24 class ‪AbstractFormElementTest extends UnitTestCase
25 {
29  public function ‪formatValueDataProvider()
30  {
31  return [
32  'format with empty format configuration' => [
33  [
34  'format' => '',
35  ],
36  '',
37  '',
38  ],
39  'format to date' => [
40  [
41  'format' => 'date',
42  ],
43  '1412358894',
44  '03-10-2014'
45  ],
46  'format to date with empty timestamp' => [
47  [
48  'format' => 'date',
49  ],
50  '0',
51  ''
52  ],
53  'format to date with blank timestamp' => [
54  [
55  'format' => 'date',
56  ],
57  '',
58  ''
59  ],
60  'format to date with option strftime' => [
61  [
62  'format' => 'date',
63  'format.' => [
64  'option' => '%d-%m',
65  'strftime' => true,
66  ],
67  ],
68  '1412358894',
69  '03-10'
70  ],
71  'format to date with option' => [
72  [
73  'format' => 'date',
74  'format.' => [
75  'option' => 'd-m',
76  ],
77  ],
78  '1412358894',
79  '03-10'
80  ],
81  'format to datetime' => [
82  [
83  'format' => 'datetime',
84  ],
85  '1412358894',
86  '03-10-14 17:54'
87  ],
88  'format to datetime with empty value' => [
89  [
90  'format' => 'datetime',
91  ],
92  '',
93  ''
94  ],
95  'format to datetime with null value' => [
96  [
97  'format' => 'datetime',
98  ],
99  null,
100  ''
101  ],
102  'format to time' => [
103  [
104  'format' => 'time',
105  ],
106  '64440',
107  '17:54'
108  ],
109  'format to time with empty value' => [
110  [
111  'format' => 'time',
112  ],
113  '',
114  ''
115  ],
116  'format to time with null value' => [
117  [
118  'format' => 'time',
119  ],
120  null,
121  ''
122  ],
123  'format to timesec' => [
124  [
125  'format' => 'timesec',
126  ],
127  '64494',
128  '17:54:54'
129  ],
130  'format to timesec with empty value' => [
131  [
132  'format' => 'timesec',
133  ],
134  '',
135  ''
136  ],
137  'format to timesec with null value' => [
138  [
139  'format' => 'timesec',
140  ],
141  null,
142  ''
143  ],
144  'format to year' => [
145  [
146  'format' => 'year',
147  ],
148  '1412358894',
149  '2014'
150  ],
151  'format to year with empty value' => [
152  [
153  'format' => 'year',
154  ],
155  '',
156  ''
157  ],
158  'format to year with null value' => [
159  [
160  'format' => 'year',
161  ],
162  null,
163  ''
164  ],
165  'format to int' => [
166  [
167  'format' => 'int',
168  ],
169  '123.00',
170  '123'
171  ],
172  'format to int with base' => [
173  [
174  'format' => 'int',
175  'format.' => [
176  'base' => 'oct',
177  ],
178  ],
179  '123',
180  '173'
181  ],
182  'format to int with empty value' => [
183  [
184  'format' => 'int',
185  ],
186  '',
187  '0'
188  ],
189  'format to float' => [
190  [
191  'format' => 'float',
192  ],
193  '123',
194  '123.00'
195  ],
196  'format to float with precision' => [
197  [
198  'format' => 'float',
199  'format.' => [
200  'precision' => '4',
201  ],
202  ],
203  '123',
204  '123.0000'
205  ],
206  'format to float with empty value' => [
207  [
208  'format' => 'float',
209  ],
210  '',
211  '0.00'
212  ],
213  'format to number' => [
214  [
215  'format' => 'number',
216  'format.' => [
217  'option' => 'b',
218  ],
219  ],
220  '123',
221  '1111011'
222  ],
223  'format to number with empty option' => [
224  [
225  'format' => 'number',
226  ],
227  '123',
228  ''
229  ],
230  'format to md5' => [
231  [
232  'format' => 'md5',
233  ],
234  'joh316',
235  'bacb98acf97e0b6112b1d1b650b84971'
236  ],
237  'format to md5 with empty value' => [
238  [
239  'format' => 'md5',
240  ],
241  '',
242  'd41d8cd98f00b204e9800998ecf8427e'
243  ],
244  'format to filesize' => [
245  [
246  'format' => 'filesize',
247  ],
248  '100000',
249  '98 Ki'
250  ],
251  'format to filesize with empty value' => [
252  [
253  'format' => 'filesize',
254  ],
255  '',
256  '0 '
257  ],
258  'format to filesize with option appendByteSize' => [
259  [
260  'format' => 'filesize',
261  'format.' => [
262  'appendByteSize' => true,
263  ],
264  ],
265  '100000',
266  '98 Ki (100000)'
267  ],
268  ];
269  }
270 
278  public function ‪formatValueWithGivenConfiguration($config, $itemValue, $expectedResult)
279  {
281  $subject = $this->getAccessibleMock(AbstractFormElement::class, ['render'], [], '', false);
282  $timezoneBackup = date_default_timezone_get();
283  date_default_timezone_set('UTC');
284  $result = $subject->_call('formatValue', $config['format'], $itemValue, $config['format.'] ?? []);
285  date_default_timezone_set($timezoneBackup);
286 
287  self::assertEquals($expectedResult, $result);
288  }
289 }
‪TYPO3\CMS\Backend\Tests\Unit\Form\Element\AbstractFormElementTest\formatValueWithGivenConfiguration
‪formatValueWithGivenConfiguration($config, $itemValue, $expectedResult)
Definition: AbstractFormElementTest.php:278
‪TYPO3\CMS\Backend\Tests\Unit\Form\Element\AbstractFormElementTest
Definition: AbstractFormElementTest.php:25
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement
Definition: AbstractFormElement.php:32
‪TYPO3\CMS\Backend\Tests\Unit\Form\Element\AbstractFormElementTest\formatValueDataProvider
‪array formatValueDataProvider()
Definition: AbstractFormElementTest.php:29
‪TYPO3\CMS\Backend\Tests\Unit\Form\Element
Definition: AbstractFormElementTest.php:16