‪TYPO3CMS  10.4
TextfieldViewHelperTest.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
22 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
23 
27 class ‪TextfieldViewHelperTest extends ViewHelperBaseTestcase
28 {
32  protected ‪$viewHelper;
33 
34  protected function ‪setUp(): void
35  {
36  parent::setUp();
37  $this->viewHelper = new ‪TextfieldViewHelper();
38  $this->injectDependenciesIntoViewHelper($this->viewHelper);
39  }
40 
44  public function ‪renderCorrectlySetsTagName()
45  {
46  $this->setArgumentsUnderTest(
47  $this->viewHelper
48  );
49 
50  $expectedResult = '<input type="text" name="" />';
51  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
52  self::assertEquals($expectedResult, $actualResult);
53  }
54 
59  {
60  $this->setArgumentsUnderTest(
61  $this->viewHelper,
62  [
63  'name' => 'NameOfTextfield',
64  'value' => 'Current value',
65  'type' => 'text'
66  ]
67  );
68 
69  $this->viewHelper->setViewHelperNode(new EmptySyntaxTreeNode());
70  $expectedResult = '<input type="text" name="NameOfTextfield" value="Current value" />';
71  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
72  self::assertEquals($expectedResult, $actualResult);
73  }
74 
78  public function ‪renderCallsSetErrorClassAttribute()
79  {
80  $this->viewHelper = $this->getAccessibleMock(
81  TextfieldViewHelper::class,
82  [
83  'setErrorClassAttribute',
84  'registerFieldNameForFormTokenGeneration'
85  ]
86  );
87  $this->injectDependenciesIntoViewHelper($this->viewHelper);
88 
89  $this->viewHelper->expects(self::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  self::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  self::assertEquals($expectedResult, $actualResult);
132  }
133 }
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextfieldViewHelperTest\renderCallsSetErrorClassAttribute
‪renderCallsSetErrorClassAttribute()
Definition: TextfieldViewHelperTest.php:77
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextfieldViewHelperTest\renderCorrectlySetsRequiredAttribute
‪renderCorrectlySetsRequiredAttribute()
Definition: TextfieldViewHelperTest.php:115
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextfieldViewHelperTest
Definition: TextfieldViewHelperTest.php:28
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextfieldViewHelperTest\$viewHelper
‪TextfieldViewHelper $viewHelper
Definition: TextfieldViewHelperTest.php:31
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextfieldViewHelperTest\renderCorrectlySetsTypeNameAndValueAttributes
‪renderCorrectlySetsTypeNameAndValueAttributes()
Definition: TextfieldViewHelperTest.php:57
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextfieldViewHelperTest\renderAddsPlaceholder
‪renderAddsPlaceholder()
Definition: TextfieldViewHelperTest.php:95
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextfieldViewHelperTest\setUp
‪setUp()
Definition: TextfieldViewHelperTest.php:33
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\EmptySyntaxTreeNode
Definition: EmptySyntaxTreeNode.php:24
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form
Definition: AbstractFormFieldViewHelperTest.php:16
‪TYPO3\CMS\Fluid\ViewHelpers\Form\TextfieldViewHelper
Definition: TextfieldViewHelper.php:33
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextfieldViewHelperTest\renderCorrectlySetsTagName
‪renderCorrectlySetsTagName()
Definition: TextfieldViewHelperTest.php:43