TYPO3 CMS  TYPO3_8-7
TextfieldViewHelperTest.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 
21 
25 class TextfieldViewHelperTest extends ViewHelperBaseTestcase
26 {
30  protected $viewHelper;
31 
32  protected function setUp()
33  {
34  parent::setUp();
35  $this->viewHelper = new TextfieldViewHelper();
36  $this->injectDependenciesIntoViewHelper($this->viewHelper);
37  }
38 
42  public function renderCorrectlySetsTagName()
43  {
44  $this->setArgumentsUnderTest(
45  $this->viewHelper
46  );
47 
48  $expectedResult = '<input type="text" name="" />';
49  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
50  $this->assertEquals($expectedResult, $actualResult);
51  }
52 
57  {
58  $this->setArgumentsUnderTest(
59  $this->viewHelper,
60  [
61  'name' => 'NameOfTextfield',
62  'value' => 'Current value',
63  'type' => 'text'
64  ]
65  );
66 
67  $this->viewHelper->setViewHelperNode(new EmptySyntaxTreeNode());
68  $expectedResult = '<input type="text" name="NameOfTextfield" value="Current value" />';
69  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
70  $this->assertEquals($expectedResult, $actualResult);
71  }
72 
77  {
78  $this->viewHelper = $this->getAccessibleMock(
79  TextfieldViewHelper::class,
80  [
81  'setErrorClassAttribute',
82  'registerFieldNameForFormTokenGeneration'
83  ]
84  );
85  $this->injectDependenciesIntoViewHelper($this->viewHelper);
86  $reflectionServiceProphecy = $this->prophesize(ReflectionService::class);
87  $this->viewHelper->injectReflectionService($reflectionServiceProphecy->reveal());
88 
89  $this->viewHelper->expects($this->once())->method('setErrorClassAttribute');
90  $this->viewHelper->render();
91  }
92 
96  public function renderAddsPlaceholder()
97  {
98  $this->setArgumentsUnderTest(
99  $this->viewHelper,
100  [
101  'name' => 'NameOfTextfield',
102  'placeholder' => 'SomePlaceholder',
103  'type' => 'text'
104  ]
105  );
106 
107  $this->viewHelper->setViewHelperNode(new EmptySyntaxTreeNode());
108  $expectedResult = '<input placeholder="SomePlaceholder" type="text" name="NameOfTextfield" />';
109  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
110  $this->assertEquals($expectedResult, $actualResult);
111  }
112 
117  {
118  $this->setArgumentsUnderTest(
119  $this->viewHelper,
120  [
121  'name' => 'NameOfTextfield',
122  'value' => 'Current value',
123  'type' => 'text',
124  'required' => 'required'
125  ]
126  );
127 
128  $this->viewHelper->setViewHelperNode(new EmptySyntaxTreeNode());
129  $expectedResult = '<input type="text" name="NameOfTextfield" value="Current value" required="required" />';
130  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
131  $this->assertEquals($expectedResult, $actualResult);
132  }
133 }