TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
NumberViewHelperTest.php
Go to the documentation of this file.
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  */
18 
23 {
27  protected $viewHelper;
28 
29  protected function setUp()
30  {
31  parent::setUp();
32  $this->viewHelper = new NumberViewHelper();
33  $this->injectDependenciesIntoViewHelper($this->viewHelper);
34  $this->viewHelper->setRenderChildrenClosure(
35  function () {
36  return pi();
37  }
38  );
39  }
40 
45  {
46  $this->setArgumentsUnderTest(
47  $this->viewHelper,
48  []
49  );
50  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
51  $this->assertEquals('3.14', $actualResult);
52  }
53 
57  public function formatNumberWithDecimalPoint()
58  {
59  $this->setArgumentsUnderTest(
60  $this->viewHelper,
61  [
62  'decimalSeparator' => ',',
63  ]
64  );
65  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
66  $this->assertEquals('3,14', $actualResult);
67  }
68 
72  public function formatNumberWithDecimals()
73  {
74  $this->setArgumentsUnderTest(
75  $this->viewHelper,
76  [
77  'decimals' => 4,
78  ]
79  );
80  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
81  $this->assertEquals('3.1416', $actualResult);
82  }
83 
88  {
89  $this->viewHelper->setRenderChildrenClosure(function () {
90  return pi() * 1000;
91  });
92  $this->setArgumentsUnderTest(
93  $this->viewHelper,
94  [
95  'thousandsSeparator' => ',',
96  ]
97  );
98  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
99  $this->assertEquals('3,141.59', $actualResult);
100  }
101 }
setArgumentsUnderTest(ViewHelperInterface $viewHelper, array $arguments=[])