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