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