TYPO3 CMS  TYPO3_8-7
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 
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 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 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 }