[TASK] Deprecate render method arguments on ViewHelpers
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / ViewHelpers / Form / TextfieldViewHelperTest.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form;
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
17 use TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\EmptySyntaxTreeNode;
18 use TYPO3\CMS\Fluid\ViewHelpers\Form\TextfieldViewHelper;
19 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
20
21 /**
22 * Test for the "Textfield" Form view helper
23 */
24 class TextfieldViewHelperTest extends ViewHelperBaseTestcase
25 {
26 /**
27 * @var TextfieldViewHelper
28 */
29 protected $viewHelper;
30
31 protected function setUp()
32 {
33 parent::setUp();
34 $this->viewHelper = new TextfieldViewHelper();
35 $this->injectDependenciesIntoViewHelper($this->viewHelper);
36 }
37
38 /**
39 * @test
40 */
41 public function renderCorrectlySetsTagName()
42 {
43 $this->setArgumentsUnderTest(
44 $this->viewHelper
45 );
46
47 $expectedResult = '<input type="text" name="" />';
48 $actualResult = $this->viewHelper->initializeArgumentsAndRender();
49 $this->assertEquals($expectedResult, $actualResult);
50 }
51
52 /**
53 * @test
54 */
55 public function renderCorrectlySetsTypeNameAndValueAttributes()
56 {
57 $this->setArgumentsUnderTest(
58 $this->viewHelper,
59 [
60 'name' => 'NameOfTextfield',
61 'value' => 'Current value',
62 'type' => 'text'
63 ]
64 );
65
66 $this->viewHelper->setViewHelperNode(new EmptySyntaxTreeNode());
67 $expectedResult = '<input type="text" name="NameOfTextfield" value="Current value" />';
68 $actualResult = $this->viewHelper->initializeArgumentsAndRender();
69 $this->assertEquals($expectedResult, $actualResult);
70 }
71
72 /**
73 * @test
74 */
75 public function renderCallsSetErrorClassAttribute()
76 {
77 $this->viewHelper = $this->getAccessibleMock(
78 TextfieldViewHelper::class,
79 [
80 'setErrorClassAttribute',
81 'registerFieldNameForFormTokenGeneration'
82 ]
83 );
84 $this->injectDependenciesIntoViewHelper($this->viewHelper);
85
86 $this->viewHelper->expects($this->once())->method('setErrorClassAttribute');
87 $this->viewHelper->render();
88 }
89
90 /**
91 * @test
92 */
93 public function renderAddsPlaceholder()
94 {
95 $this->setArgumentsUnderTest(
96 $this->viewHelper,
97 [
98 'name' => 'NameOfTextfield',
99 'placeholder' => 'SomePlaceholder',
100 'type' => 'text'
101 ]
102 );
103
104 $this->viewHelper->setViewHelperNode(new EmptySyntaxTreeNode());
105 $expectedResult = '<input placeholder="SomePlaceholder" type="text" name="NameOfTextfield" />';
106 $actualResult = $this->viewHelper->initializeArgumentsAndRender();
107 $this->assertEquals($expectedResult, $actualResult);
108 }
109
110 /**
111 * @test
112 */
113 public function renderCorrectlySetsRequiredAttribute()
114 {
115 $this->setArgumentsUnderTest(
116 $this->viewHelper,
117 [
118 'name' => 'NameOfTextfield',
119 'value' => 'Current value',
120 'type' => 'text',
121 'required' => 'required'
122 ]
123 );
124
125 $this->viewHelper->setViewHelperNode(new EmptySyntaxTreeNode());
126 $expectedResult = '<input type="text" name="NameOfTextfield" value="Current value" required="required" />';
127 $actualResult = $this->viewHelper->initializeArgumentsAndRender();
128 $this->assertEquals($expectedResult, $actualResult);
129 }
130 }