TYPO3 CMS  TYPO3_8-7
CurrencyViewHelperTest.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 
23 class CurrencyViewHelperTest extends ViewHelperBaseTestcase
24 {
28  protected $viewHelper;
29 
30  protected function setUp()
31  {
32  parent::setUp();
33  $this->viewHelper = new CurrencyViewHelper();
34  $this->injectDependenciesIntoViewHelper($this->viewHelper);
35  }
36 
41  {
42  $this->viewHelper->setRenderChildrenClosure(
43  function () {
44  return 123.456;
45  }
46  );
47  $this->setArgumentsUnderTest(
48  $this->viewHelper,
49  [
50  ]
51  );
52  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
53  $this->assertEquals('123,46', $actualResult);
54  }
55 
60  {
61  $this->viewHelper->setRenderChildrenClosure(
62  function () {
63  return 123;
64  }
65  );
66  $this->setArgumentsUnderTest(
67  $this->viewHelper,
68  [
69  'currencySign' => 'foo'
70  ]
71  );
72  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
73  $this->assertEquals('123,00 foo', $actualResult);
74  }
75 
80  {
81  $this->viewHelper->setRenderChildrenClosure(
82  function () {
83  return 123;
84  }
85  );
86  $this->setArgumentsUnderTest(
87  $this->viewHelper,
88  [
89  'currencySign' => 'foo',
90  'decimalSeparator' => ',',
91  'thousandsSeparator' => '.',
92  'prependCurrency' => true
93  ]
94  );
95  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
96  $this->assertEquals('foo 123,00', $actualResult);
97  }
98 
103  {
104  $this->viewHelper->setRenderChildrenClosure(
105  function () {
106  return 123;
107  }
108  );
109  $this->setArgumentsUnderTest(
110  $this->viewHelper,
111  [
112  'currencySign' => 'foo',
113  'decimalSeparator' => ',',
114  'thousandsSeparator' => '.',
115  'prependCurrency' => true,
116  'separateCurrency' => false
117  ]
118  );
119  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
120  $this->assertEquals('foo123,00', $actualResult);
121  }
122 
127  {
128  $this->viewHelper->setRenderChildrenClosure(
129  function () {
130  return 12345;
131  }
132  );
133  $this->setArgumentsUnderTest(
134  $this->viewHelper,
135  [
136  'currencySign' => '',
137  'decimalSeparator' => '|'
138  ]
139  );
140  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
141  $this->assertEquals('12.345|00', $actualResult);
142  }
143 
148  {
149  $this->viewHelper->setRenderChildrenClosure(
150  function () {
151  return 12345;
152  }
153  );
154  $this->setArgumentsUnderTest(
155  $this->viewHelper,
156  [
157  'currencySign' => '',
158  'decimalSeparator' => ',',
159  'thousandsSeparator' => '|'
160  ]
161  );
162  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
163  $this->assertEquals('12|345,00', $actualResult);
164  }
165 
169  public function viewHelperRendersNullValues()
170  {
171  $this->viewHelper->setRenderChildrenClosure(
172  function () {
173  return null;
174  }
175  );
176  $this->setArgumentsUnderTest(
177  $this->viewHelper,
178  [
179  ]
180  );
181  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
182  $this->assertEquals('0,00', $actualResult);
183  }
184 
189  {
190  $this->viewHelper->setRenderChildrenClosure(
191  function () {
192  return '';
193  }
194  );
195  $this->setArgumentsUnderTest(
196  $this->viewHelper,
197  [
198  ]
199  );
200  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
201  $this->assertEquals('0,00', $actualResult);
202  }
203 
207  public function viewHelperRendersZeroValues()
208  {
209  $this->viewHelper->setRenderChildrenClosure(
210  function () {
211  return 0;
212  }
213  );
214  $this->setArgumentsUnderTest(
215  $this->viewHelper,
216  [
217  ]
218  );
219  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
220  $this->assertEquals('0,00', $actualResult);
221  }
222 
227  {
228  $this->viewHelper->setRenderChildrenClosure(
229  function () {
230  return -123.456;
231  }
232  );
233  $this->setArgumentsUnderTest(
234  $this->viewHelper,
235  [
236  ]
237  );
238  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
239  $this->assertEquals('-123,46', $actualResult);
240  }
241 
246  {
247  $this->viewHelper->setRenderChildrenClosure(
248  function () {
249  return 'TYPO3';
250  }
251  );
252  $this->setArgumentsUnderTest(
253  $this->viewHelper,
254  [
255  ]
256  );
257  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
258  $this->assertEquals('0,00', $actualResult);
259  }
260 
265  {
266  $this->viewHelper->setRenderChildrenClosure(
267  function () {
268  return '12,34.00';
269  }
270  );
271  $this->setArgumentsUnderTest(
272  $this->viewHelper,
273  [
274  ]
275  );
276  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
277  $this->assertEquals('12,00', $actualResult);
278  }
279 
284  {
285  $this->viewHelper->setRenderChildrenClosure(
286  function () {
287  return '54321';
288  }
289  );
290  $this->setArgumentsUnderTest(
291  $this->viewHelper,
292  [
293  'currencySign' => '',
294  'decimalSeparator' => ',',
295  'thousandsSeparator' => '.',
296  'prependCurrency' => false,
297  'separateCurrency' => true,
298  'decimals' => 0
299  ]
300  );
301  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
302  $this->assertEquals('54.321', $actualResult);
303  }
304 
309  {
310  $this->viewHelper->setRenderChildrenClosure(
311  function () {
312  return '54321';
313  }
314  );
315  $this->setArgumentsUnderTest(
316  $this->viewHelper,
317  [
318  'currencySign' => '',
319  'decimalSeparator' => ',',
320  'thousandsSeparator' => '.',
321  'prependCurrency' => false,
322  'separateCurrency' => true,
323  'decimals' => 3
324  ]
325  );
326  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
327  $this->assertEquals('54.321,000', $actualResult);
328  }
329 }