‪TYPO3CMS  9.5
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 
18 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
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 
40  public function ‪valueDataProvider()
41  {
42  return [
43  'rounds float correctly' => [
44  'value' => 123.456,
45  'arguments' =>
46  [
47  ],
48  'expected' => '123,46',
49  ],
50  'currency sign' => [
51  'value' => 123,
52  'arguments' =>
53  [
54  'currencySign' => 'foo'
55  ],
56  'expected' => '123,00 foo',
57  ],
58  'prepended currency sign' => [
59  'value' => 123,
60  'arguments' =>
61  [
62  'currencySign' => 'foo',
63  'decimalSeparator' => ',',
64  'thousandsSeparator' => '.',
65  'prependCurrency' => true
66  ],
67  'expected' => 'foo 123,00',
68  ],
69  'respects currency separator' =>[
70  'value' => 123,
71  'arguments' =>
72  [
73  'currencySign' => 'foo',
74  'decimalSeparator' => ',',
75  'thousandsSeparator' => '.',
76  'prependCurrency' => true,
77  'separateCurrency' => false
78  ],
79  'expected' => 'foo123,00',
80  ],
81  'respects decimal separator' => [
82  'value' => 12345,
83  'arguments' =>
84  [
85  'currencySign' => '',
86  'decimalSeparator' => '|'
87  ],
88  'expected' => '12.345|00',
89  ],
90  'respects thousands separator' => [
91  'value' => 12345,
92  'arguments' =>
93  [
94  'currencySign' => '',
95  'decimalSeparator' => ',',
96  'thousandsSeparator' => '|'
97  ],
98  'expected' => '12|345,00',
99  ],
100  'null values' => [
101  'value' => null,
102  'arguments' =>
103  [
104  ],
105  'expected' => '0,00',
106  ],
107  'empty string' => [
108  'value' => '',
109  'arguments' =>
110  [
111  ],
112  'expected' => '0,00',
113  ],
114  'zero values' => [
115  'value' => 0,
116  'arguments' =>
117  [
118  ],
119  'expected' => '0,00',
120  ],
121  'negative amounts' => [
122  'value' => '-123.456',
123  'arguments' =>
124  [
125  ],
126  'expected' => '-123,46',
127  ],
128  'strings to zero value float' => [
129  'value' => 'TYPO3',
130  'arguments' =>
131  [
132  ],
133  'expected' => '0,00',
134  ],
135  'comma values to value before comma' => [
136  'value' => '12,34.00',
137  'arguments' =>
138  [
139  ],
140  'expected' => '12,00',
141  ],
142  'without decimals' => [
143  'value' => '54321',
144  'arguments' =>
145  [
146  'currencySign' => '',
147  'decimalSeparator' => ',',
148  'thousandsSeparator' => '.',
149  'prependCurrency' => false,
150  'separateCurrency' => true,
151  'decimals' => 0
152  ],
153  'expected' => '54.321',
154  ],
155  'three decimals' => [
156  'value' => '54321',
157  'arguments' =>
158  [
159  'currencySign' => '',
160  'decimalSeparator' => ',',
161  'thousandsSeparator' => '.',
162  'prependCurrency' => false,
163  'separateCurrency' => true,
164  'decimals' => 3
165  ],
166  'expected' => '54.321,000',
167  ],
168  'with dash' => [
169  'value' => '54321.00',
170  'arguments' =>
171  [
172  'decimalSeparator' => ',',
173  'thousandsSeparator' => '.',
174  'prependCurrency' => false,
175  'separateCurrency' => true,
176  'useDash' => true,
177  ],
178  'expected' => '54.321,—',
179  ],
180  'without dash' => [
181  'value' => '54321.45',
182  'arguments' =>
183  [
184  'decimalSeparator' => ',',
185  'thousandsSeparator' => '.',
186  'prependCurrency' => false,
187  'separateCurrency' => true,
188  'useDash' => true,
189  ],
190  'expected' => '54.321,45',
191  ],
192  ];
193  }
194 
202  public function ‪viewHelperRender($value, array $arguments, string $expected)
203  {
204  $this->viewHelper->setRenderChildrenClosure(
205  function () use ($value) {
206  return $value;
207  }
208  );
209  $this->setArgumentsUnderTest($this->viewHelper, $arguments);
210  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
211  $this->assertEquals($expected, $actualResult);
212  }
213 }
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CurrencyViewHelperTest\valueDataProvider
‪array valueDataProvider()
Definition: CurrencyViewHelperTest.php:39
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CurrencyViewHelperTest\viewHelperRender
‪viewHelperRender($value, array $arguments, string $expected)
Definition: CurrencyViewHelperTest.php:201
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format
Definition: BytesViewHelperTest.php:2
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CurrencyViewHelperTest\$viewHelper
‪CurrencyViewHelper $viewHelper
Definition: CurrencyViewHelperTest.php:27
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CurrencyViewHelperTest
Definition: CurrencyViewHelperTest.php:24
‪TYPO3\CMS\Fluid\ViewHelpers\Format\CurrencyViewHelper
Definition: CurrencyViewHelper.php:78
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CurrencyViewHelperTest\setUp
‪setUp()
Definition: CurrencyViewHelperTest.php:29