‪TYPO3CMS  ‪main
CurrencyViewHelperTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
23 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
24 use TYPO3Fluid\Fluid\View\TemplateView;
25 
26 final class ‪CurrencyViewHelperTest extends FunctionalTestCase
27 {
28  protected bool ‪$initializeDatabase = false;
29 
30  public static function ‪renderConvertsAValueDataProvider(): array
31  {
32  return [
33  'rounds float correctly' => [
34  '<f:format.currency>123.456</f:format.currency>',
35  '123,46',
36  ],
37  'currency sign' => [
38  '<f:format.currency currencySign="foo">123</f:format.currency>',
39  '123,00 foo',
40  ],
41  'prepended currency sign' => [
42  '<f:format.currency currencySign="foo" prependCurrency="true" decimalSeparator="," thousandsSeparator=".">123</f:format.currency>',
43  'foo 123,00',
44  ],
45  'respects currency separator' => [
46  '<f:format.currency currencySign="foo" separateCurrency="false" prependCurrency="true" decimalSeparator="," thousandsSeparator=".">123</f:format.currency>',
47  'foo123,00',
48  ],
49  'respects decimal separator' => [
50  '<f:format.currency currencySign="" decimalSeparator="|">12345</f:format.currency>',
51  '12.345|00',
52  ],
53  'respects thousands separator' => [
54  '<f:format.currency currencySign="" decimalSeparator=","thousandsSeparator="|">12345</f:format.currency>',
55  '12|345,00',
56  ],
57  'empty value' => [
58  '<f:format.currency></f:format.currency>',
59  '0,00',
60  ],
61  'zero values' => [
62  '<f:format.currency>0</f:format.currency>',
63  '0,00',
64  ],
65  'negative amounts' => [
66  '<f:format.currency>-123.456</f:format.currency>',
67  '-123,46',
68  ],
69  'strings to zero value float' => [
70  '<f:format.currency>TYPO3</f:format.currency>',
71  '0,00',
72  ],
73  'comma values to value before comma' => [
74  '<f:format.currency>12,34.00</f:format.currency>',
75  '12,00',
76  ],
77  'without decimals' => [
78  '<f:format.currency decimals="0">54321</f:format.currency>',
79  '54.321',
80  ],
81  'three decimals' => [
82  '<f:format.currency decimals="3">54321</f:format.currency>',
83  '54.321,000',
84  ],
85  'with dash' => [
86  '<f:format.currency useDash="true">54321.00</f:format.currency>',
87  '54.321,—',
88  ],
89  'without dash' => [
90  '<f:format.currency useDash="true">54321.45</f:format.currency>',
91  '54.321,45',
92  ],
93  ];
94  }
95 
96  #[DataProvider('renderConvertsAValueDataProvider')]
97  #[Test]
98  public function ‪renderConvertsAValue(string $src, string $expected): void
99  {
100  $context = $this->get(RenderingContextFactory::class)->create();
101  $context->getTemplatePaths()->setTemplateSource($src);
102  self::assertSame($expected, (new TemplateView($context))->render());
103  }
104 }
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Format
Definition: BytesViewHelperTest.php:18
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Format\CurrencyViewHelperTest\$initializeDatabase
‪bool $initializeDatabase
Definition: CurrencyViewHelperTest.php:28
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Format\CurrencyViewHelperTest
Definition: CurrencyViewHelperTest.php:27
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContextFactory
Definition: RenderingContextFactory.php:51
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Format\CurrencyViewHelperTest\renderConvertsAValueDataProvider
‪static renderConvertsAValueDataProvider()
Definition: CurrencyViewHelperTest.php:30
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Format\CurrencyViewHelperTest\renderConvertsAValue
‪renderConvertsAValue(string $src, string $expected)
Definition: CurrencyViewHelperTest.php:98