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