‪TYPO3CMS  10.4
TextareaViewHelperTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder;
21 
26 {
30  protected ‪$viewHelper;
31 
32  protected function ‪setUp(): void
33  {
34  parent::setUp();
35  $this->viewHelper = $this->getAccessibleMock(TextareaViewHelper::class, ['setErrorClassAttribute', 'registerFieldNameForFormTokenGeneration']);
36  $this->arguments['name'] = '';
37  $this->‪injectDependenciesIntoViewHelper($this->viewHelper);
38  }
39 
43  public function ‪renderCorrectlySetsTagName()
44  {
45  $mockTagBuilder = $this->getMockBuilder(TagBuilder::class)
46  ->setMethods(['setTagName'])
47  ->disableOriginalConstructor()
48  ->getMock();
49  $mockTagBuilder->expects(self::atLeastOnce())->method('setTagName')->with('textarea');
50  $this->viewHelper->setTagBuilder($mockTagBuilder);
51 
52  $this->viewHelper->initializeArgumentsAndRender();
53  }
54 
59  {
60  $arguments = [
61  'name' => 'NameOfTextarea',
62  'value' => 'Current value'
63  ];
64  $this->viewHelper->setArguments($arguments);
65 
66  $this->viewHelper->setViewHelperNode(new EmptySyntaxTreeNode());
67  $actual = $this->viewHelper->initializeArgumentsAndRender();
68  $expected = '<textarea name="NameOfTextarea">Current value</textarea>';
69  self::assertSame($expected, $actual);
70  }
71 
75  public function ‪renderCallsSetErrorClassAttribute()
76  {
77  $this->viewHelper->expects(self::once())->method('setErrorClassAttribute');
78  $this->viewHelper->render();
79  }
80 
84  public function ‪renderEscapesTextareaContent()
85  {
86  $arguments = [
87  'name' => 'NameOfTextarea',
88  'value' => 'some <tag> & "quotes"'
89  ];
90  $this->viewHelper->setArguments($arguments);
91 
92  $this->viewHelper->setViewHelperNode(new EmptySyntaxTreeNode());
93  $actual = $this->viewHelper->initializeArgumentsAndRender();
94  $expected = '<textarea name="NameOfTextarea">some &lt;tag&gt; &amp; &quot;quotes&quot;</textarea>';
95  self::assertSame($expected, $actual);
96  }
97 
101  public function ‪renderAddsPlaceholder()
102  {
103  $arguments = [
104  'name' => 'NameOfTextarea',
105  'placeholder' => 'SomePlaceholder'
106  ];
107  $this->viewHelper->setArguments($arguments);
108 
109  $this->viewHelper->setViewHelperNode(new EmptySyntaxTreeNode());
110  $actual = $this->viewHelper->initializeArgumentsAndRender();
111  $expected = '<textarea placeholder="SomePlaceholder" name="NameOfTextarea"></textarea>';
112  self::assertSame($expected, $actual);
113  }
114 
118  public function ‪renderAddsReadonly()
119  {
120  $arguments = [
121  'readonly' => 'foo',
122  'name' => 'NameOfTextarea',
123  ];
124  $this->viewHelper->setArguments($arguments);
125 
126  $this->viewHelper->setViewHelperNode(new EmptySyntaxTreeNode());
127  $actual = $this->viewHelper->initializeArgumentsAndRender();
128  $expected = '<textarea readonly="foo" name="NameOfTextarea"></textarea>';
129  self::assertSame($expected, $actual);
130  }
131 
135  public function ‪renderAddsRequired()
136  {
137  $arguments = [
138  'required' => true,
139  'name' => 'NameOfTextarea',
140  ];
141  $this->viewHelper->setArguments($arguments);
142 
143  $this->viewHelper->setViewHelperNode(new EmptySyntaxTreeNode());
144  $actual = $this->viewHelper->initializeArgumentsAndRender();
145  $expected = '<textarea name="NameOfTextarea" required="required"></textarea>';
146  self::assertSame($expected, $actual);
147  }
148 }
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextareaViewHelperTest\renderAddsReadonly
‪renderAddsReadonly()
Definition: TextareaViewHelperTest.php:117
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextareaViewHelperTest\renderAddsPlaceholder
‪renderAddsPlaceholder()
Definition: TextareaViewHelperTest.php:100
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\FormFieldViewHelperBaseTestcase\injectDependenciesIntoViewHelper
‪injectDependenciesIntoViewHelper(ViewHelperInterface $viewHelper)
Definition: FormFieldViewHelperBaseTestcase.php:42
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\FormFieldViewHelperBaseTestcase
Definition: FormFieldViewHelperBaseTestcase.php:28
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextareaViewHelperTest
Definition: TextareaViewHelperTest.php:26
‪TYPO3\CMS\Fluid\ViewHelpers\Form\TextareaViewHelper
Definition: TextareaViewHelper.php:35
‪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\Tests\Unit\ViewHelpers\Form\TextareaViewHelperTest\setUp
‪setUp()
Definition: TextareaViewHelperTest.php:31
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextareaViewHelperTest\$viewHelper
‪TextareaViewHelper $viewHelper
Definition: TextareaViewHelperTest.php:29
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextareaViewHelperTest\renderCorrectlySetsTagName
‪renderCorrectlySetsTagName()
Definition: TextareaViewHelperTest.php:42
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextareaViewHelperTest\renderCallsSetErrorClassAttribute
‪renderCallsSetErrorClassAttribute()
Definition: TextareaViewHelperTest.php:74
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextareaViewHelperTest\renderCorrectlySetsNameAttributeAndContent
‪renderCorrectlySetsNameAttributeAndContent()
Definition: TextareaViewHelperTest.php:57
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextareaViewHelperTest\renderEscapesTextareaContent
‪renderEscapesTextareaContent()
Definition: TextareaViewHelperTest.php:83
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextareaViewHelperTest\renderAddsRequired
‪renderAddsRequired()
Definition: TextareaViewHelperTest.php:134