‪TYPO3CMS  9.5
TextfieldViewHelperTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
20 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
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 
76  public function ‪renderCallsSetErrorClassAttribute()
77  {
78  $this->viewHelper = $this->getAccessibleMock(
79  TextfieldViewHelper::class,
80  [
81  'setErrorClassAttribute',
82  'registerFieldNameForFormTokenGeneration'
83  ]
84  );
85  $this->injectDependenciesIntoViewHelper($this->viewHelper);
86 
87  $this->viewHelper->expects($this->once())->method('setErrorClassAttribute');
88  $this->viewHelper->render();
89  }
90 
94  public function ‪renderAddsPlaceholder()
95  {
96  $this->setArgumentsUnderTest(
97  $this->viewHelper,
98  [
99  'name' => 'NameOfTextfield',
100  'placeholder' => 'SomePlaceholder',
101  'type' => 'text'
102  ]
103  );
104 
105  $this->viewHelper->setViewHelperNode(new EmptySyntaxTreeNode());
106  $expectedResult = '<input placeholder="SomePlaceholder" type="text" name="NameOfTextfield" />';
107  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
108  $this->assertEquals($expectedResult, $actualResult);
109  }
110 
115  {
116  $this->setArgumentsUnderTest(
117  $this->viewHelper,
118  [
119  'name' => 'NameOfTextfield',
120  'value' => 'Current value',
121  'type' => 'text',
122  'required' => 'required'
123  ]
124  );
125 
126  $this->viewHelper->setViewHelperNode(new EmptySyntaxTreeNode());
127  $expectedResult = '<input type="text" name="NameOfTextfield" value="Current value" required="required" />';
128  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
129  $this->assertEquals($expectedResult, $actualResult);
130  }
131 }
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextfieldViewHelperTest\renderCallsSetErrorClassAttribute
‪renderCallsSetErrorClassAttribute()
Definition: TextfieldViewHelperTest.php:75
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextfieldViewHelperTest\renderCorrectlySetsRequiredAttribute
‪renderCorrectlySetsRequiredAttribute()
Definition: TextfieldViewHelperTest.php:113
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextfieldViewHelperTest
Definition: TextfieldViewHelperTest.php:26
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextfieldViewHelperTest\$viewHelper
‪TextfieldViewHelper $viewHelper
Definition: TextfieldViewHelperTest.php:29
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextfieldViewHelperTest\renderCorrectlySetsTypeNameAndValueAttributes
‪renderCorrectlySetsTypeNameAndValueAttributes()
Definition: TextfieldViewHelperTest.php:55
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextfieldViewHelperTest\renderAddsPlaceholder
‪renderAddsPlaceholder()
Definition: TextfieldViewHelperTest.php:93
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextfieldViewHelperTest\setUp
‪setUp()
Definition: TextfieldViewHelperTest.php:31
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\EmptySyntaxTreeNode
Definition: EmptySyntaxTreeNode.php:21
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form
Definition: AbstractFormFieldViewHelperTest.php:2
‪TYPO3\CMS\Fluid\ViewHelpers\Form\TextfieldViewHelper
Definition: TextfieldViewHelper.php:32
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextfieldViewHelperTest\renderCorrectlySetsTagName
‪renderCorrectlySetsTagName()
Definition: TextfieldViewHelperTest.php:41