914e0227e9245f2a0453d4f98099b6139fa03d2e
[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\Extbase\Reflection\ReflectionService;
18 use TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\EmptySyntaxTreeNode;
19 use TYPO3\CMS\Fluid\ViewHelpers\Form\TextfieldViewHelper;
20 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
21
22 /**
23 * Test for the "Textfield" Form view helper
24 */
25 class TextfieldViewHelperTest extends ViewHelperBaseTestcase
26 {
27 /**
28 * @var TextfieldViewHelper
29 */
30 protected $viewHelper;
31
32 protected function setUp()
33 {
34 parent::setUp();
35 $this->viewHelper = new TextfieldViewHelper();
36 $this->injectDependenciesIntoViewHelper($this->viewHelper);
37 }
38
39 /**
40 * @test
41 */
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
53 /**
54 * @test
55 */
56 public function renderCorrectlySetsTypeNameAndValueAttributes()
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
73 /**
74 * @test
75 */
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 $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
93 /**
94 * @test
95 */
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
113 /**
114 * @test
115 */
116 public function renderCorrectlySetsRequiredAttribute()
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 }