[TASK] Use PHP_SAPI, PHP_VERSION and M_PI constant instead of functons calls
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / ViewHelpers / Format / NumberViewHelperTest.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format;
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
17 use TYPO3\CMS\Fluid\ViewHelpers\Format\NumberViewHelper;
18 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
19
20 /**
21 * Test case
22 */
23 class NumberViewHelperTest extends ViewHelperBaseTestcase
24 {
25 /**
26 * @var NumberViewHelper
27 */
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
42 /**
43 * @test
44 */
45 public function formatNumberDefaultsToEnglishNotationWithTwoDecimals()
46 {
47 $this->setArgumentsUnderTest(
48 $this->viewHelper,
49 []
50 );
51 $actualResult = $this->viewHelper->initializeArgumentsAndRender();
52 $this->assertEquals('3.14', $actualResult);
53 }
54
55 /**
56 * @test
57 */
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
70 /**
71 * @test
72 */
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
85 /**
86 * @test
87 */
88 public function formatNumberWithThousandsSeparator()
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 }