TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
PaddingViewHelperTest.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 PaddingViewHelper();
33  $this->injectDependenciesIntoViewHelper($this->viewHelper);
34  }
35 
40  {
41  $this->viewHelper->setRenderChildrenClosure(
42  function () {
43  return 'foo';
44  }
45  );
46  $this->setArgumentsUnderTest(
47  $this->viewHelper,
48  [
49  'padLength' => 10
50  ]
51  );
52  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
53  $this->assertEquals('foo ', $actualResult);
54  }
55 
59  public function paddingStringCanBeSpecified()
60  {
61  $this->viewHelper->setRenderChildrenClosure(
62  function () {
63  return 'foo';
64  }
65  );
66  $this->setArgumentsUnderTest(
67  $this->viewHelper,
68  [
69  'padLength' => 10,
70  'padString' => '-='
71  ]
72  );
73  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
74  $this->assertEquals('foo-=-=-=-', $actualResult);
75  }
76 
81  {
82  $this->viewHelper->setRenderChildrenClosure(
83  function () {
84  return 'some long string';
85  }
86  );
87  $this->setArgumentsUnderTest(
88  $this->viewHelper,
89  [
90  'padLength' => 5
91  ]
92  );
93  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
94  $this->assertEquals('some long string', $actualResult);
95  }
96 
100  public function integersAreRespectedAsValue()
101  {
102  $this->viewHelper->setRenderChildrenClosure(
103  function () {
104  return 123;
105  }
106  );
107  $this->setArgumentsUnderTest(
108  $this->viewHelper,
109  [
110  'padLength' => 5,
111  'padString' => '0'
112  ]
113  );
114  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
115  $this->assertEquals('12300', $actualResult);
116  }
117 
121  public function valueParameterIsRespected()
122  {
123  $this->setArgumentsUnderTest(
124  $this->viewHelper,
125  [
126  'value' => 'foo',
127  'padLength' => 5,
128  'padString' => '0',
129  ]
130  );
131  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
132  $this->assertEquals('foo00', $actualResult);
133  }
134 }
setArgumentsUnderTest(ViewHelperInterface $viewHelper, array $arguments=[])