‪TYPO3CMS  10.4
NumberViewHelperTest.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 ‪NumberViewHelperTest extends ViewHelperBaseTestcase
25 {
29  protected ‪$viewHelper;
30 
31  protected function ‪setUp(): void
32  {
33  parent::setUp();
34  $this->viewHelper = new ‪NumberViewHelper();
35  $this->injectDependenciesIntoViewHelper($this->viewHelper);
36  $this->viewHelper->setRenderChildrenClosure(
37  function () {
38  return M_PI;
39  }
40  );
41  }
42 
47  {
48  $this->setArgumentsUnderTest(
49  $this->viewHelper,
50  []
51  );
52  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
53  self::assertEquals('3.14', $actualResult);
54  }
55 
59  public function ‪formatNumberWithDecimalPoint()
60  {
61  $this->setArgumentsUnderTest(
62  $this->viewHelper,
63  [
64  'decimalSeparator' => ',',
65  ]
66  );
67  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
68  self::assertEquals('3,14', $actualResult);
69  }
70 
74  public function ‪formatNumberWithDecimals()
75  {
76  $this->setArgumentsUnderTest(
77  $this->viewHelper,
78  [
79  'decimals' => 4,
80  ]
81  );
82  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
83  self::assertEquals('3.1416', $actualResult);
84  }
85 
90  {
91  $this->viewHelper->setRenderChildrenClosure(function () {
92  return M_PI * 1000;
93  });
94  $this->setArgumentsUnderTest(
95  $this->viewHelper,
96  [
97  'thousandsSeparator' => ',',
98  ]
99  );
100  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
101  self::assertEquals('3,141.59', $actualResult);
102  }
103 
107  public function ‪formatNumberWithEmptyInput()
108  {
109  $this->viewHelper->setRenderChildrenClosure(function () {
110  return '';
111  });
112  $this->setArgumentsUnderTest(
113  $this->viewHelper,
114  []
115  );
116  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
117  self::assertEquals('0.00', $actualResult);
118  }
119 }
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\NumberViewHelperTest\formatNumberWithEmptyInput
‪formatNumberWithEmptyInput()
Definition: NumberViewHelperTest.php:106
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\NumberViewHelperTest\formatNumberWithThousandsSeparator
‪formatNumberWithThousandsSeparator()
Definition: NumberViewHelperTest.php:88
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\NumberViewHelperTest\setUp
‪setUp()
Definition: NumberViewHelperTest.php:30
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\NumberViewHelperTest\formatNumberWithDecimalPoint
‪formatNumberWithDecimalPoint()
Definition: NumberViewHelperTest.php:58
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\NumberViewHelperTest\formatNumberDefaultsToEnglishNotationWithTwoDecimals
‪formatNumberDefaultsToEnglishNotationWithTwoDecimals()
Definition: NumberViewHelperTest.php:45
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format
Definition: ScriptViewHelperTest.php:18
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\NumberViewHelperTest\$viewHelper
‪NumberViewHelper $viewHelper
Definition: NumberViewHelperTest.php:28
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\NumberViewHelperTest\formatNumberWithDecimals
‪formatNumberWithDecimals()
Definition: NumberViewHelperTest.php:73
‪TYPO3\CMS\Fluid\ViewHelpers\Format\NumberViewHelper
Definition: NumberViewHelper.php:50
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\NumberViewHelperTest
Definition: NumberViewHelperTest.php:25