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