‪TYPO3CMS  9.5
TextareaViewHelperTest.php
Go to the documentation of this file.
1 <?php
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  */
17 use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder;
18 
23 {
27  protected ‪$viewHelper;
28 
29  protected function ‪setUp()
30  {
31  parent::setUp();
32  $this->viewHelper = $this->getAccessibleMock(TextareaViewHelper::class, ['setErrorClassAttribute', 'registerFieldNameForFormTokenGeneration']);
33  $this->arguments['name'] = '';
34  $this->‪injectDependenciesIntoViewHelper($this->viewHelper);
35  }
36 
40  public function ‪renderCorrectlySetsTagName()
41  {
42  $mockTagBuilder = $this->getMockBuilder(TagBuilder::class)
43  ->setMethods(['setTagName'])
44  ->disableOriginalConstructor()
45  ->getMock();
46  $mockTagBuilder->expects($this->atLeastOnce())->method('setTagName')->with('textarea');
47  $this->viewHelper->setTagBuilder($mockTagBuilder);
48 
49  $this->viewHelper->initializeArgumentsAndRender();
50  }
51 
56  {
57  $arguments = [
58  'name' => 'NameOfTextarea',
59  'value' => 'Current value'
60  ];
61  $this->viewHelper->setArguments($arguments);
62 
63  $this->viewHelper->setViewHelperNode(new Fixtures\EmptySyntaxTreeNode());
64  $actual = $this->viewHelper->initializeArgumentsAndRender();
65  $expected = '<textarea name="NameOfTextarea">Current value</textarea>';
66  $this->assertSame($expected, $actual);
67  }
68 
72  public function ‪renderCallsSetErrorClassAttribute()
73  {
74  $this->viewHelper->expects($this->once())->method('setErrorClassAttribute');
75  $this->viewHelper->render();
76  }
77 
81  public function ‪renderEscapesTextareaContent()
82  {
83  $arguments = [
84  'name' => 'NameOfTextarea',
85  'value' => 'some <tag> & "quotes"'
86  ];
87  $this->viewHelper->setArguments($arguments);
88 
89  $this->viewHelper->setViewHelperNode(new Fixtures\EmptySyntaxTreeNode());
90  $actual = $this->viewHelper->initializeArgumentsAndRender();
91  $expected = '<textarea name="NameOfTextarea">some &lt;tag&gt; &amp; &quot;quotes&quot;</textarea>';
92  $this->assertSame($expected, $actual);
93  }
94 
98  public function ‪renderAddsPlaceholder()
99  {
100  $arguments = [
101  'name' => 'NameOfTextarea',
102  'placeholder' => 'SomePlaceholder'
103  ];
104  $this->viewHelper->setArguments($arguments);
105 
106  $this->viewHelper->setViewHelperNode(new Fixtures\EmptySyntaxTreeNode());
107  $actual = $this->viewHelper->initializeArgumentsAndRender();
108  $expected = '<textarea placeholder="SomePlaceholder" name="NameOfTextarea"></textarea>';
109  $this->assertSame($expected, $actual);
110  }
111 
115  public function ‪renderAddsReadonly()
116  {
117  $arguments = [
118  'readonly' => 'foo',
119  'name' => 'NameOfTextarea',
120  ];
121  $this->viewHelper->setArguments($arguments);
122 
123  $this->viewHelper->setViewHelperNode(new Fixtures\EmptySyntaxTreeNode());
124  $actual = $this->viewHelper->initializeArgumentsAndRender();
125  $expected = '<textarea readonly="foo" name="NameOfTextarea"></textarea>';
126  $this->assertSame($expected, $actual);
127  }
128 
132  public function ‪renderAddsRequired()
133  {
134  $arguments = [
135  'required' => true,
136  'name' => 'NameOfTextarea',
137  ];
138  $this->viewHelper->setArguments($arguments);
139 
140  $this->viewHelper->setViewHelperNode(new Fixtures\EmptySyntaxTreeNode());
141  $actual = $this->viewHelper->initializeArgumentsAndRender();
142  $expected = '<textarea name="NameOfTextarea" required="required"></textarea>';
143  $this->assertSame($expected, $actual);
144  }
145 }
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextareaViewHelperTest\renderAddsReadonly
‪renderAddsReadonly()
Definition: TextareaViewHelperTest.php:114
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextareaViewHelperTest\renderAddsPlaceholder
‪renderAddsPlaceholder()
Definition: TextareaViewHelperTest.php:97
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\FormFieldViewHelperBaseTestcase\injectDependenciesIntoViewHelper
‪injectDependenciesIntoViewHelper(ViewHelperInterface $viewHelper)
Definition: FormFieldViewHelperBaseTestcase.php:40
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\FormFieldViewHelperBaseTestcase
Definition: FormFieldViewHelperBaseTestcase.php:24
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextareaViewHelperTest
Definition: TextareaViewHelperTest.php:23
‪TYPO3\CMS\Fluid\ViewHelpers\Form\TextareaViewHelper
Definition: TextareaViewHelper.php:34
‪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\Tests\Unit\ViewHelpers\Form\TextareaViewHelperTest\setUp
‪setUp()
Definition: TextareaViewHelperTest.php:28
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextareaViewHelperTest\$viewHelper
‪TextareaViewHelper $viewHelper
Definition: TextareaViewHelperTest.php:26
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextareaViewHelperTest\renderCorrectlySetsTagName
‪renderCorrectlySetsTagName()
Definition: TextareaViewHelperTest.php:39
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextareaViewHelperTest\renderCallsSetErrorClassAttribute
‪renderCallsSetErrorClassAttribute()
Definition: TextareaViewHelperTest.php:71
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextareaViewHelperTest\renderCorrectlySetsNameAttributeAndContent
‪renderCorrectlySetsNameAttributeAndContent()
Definition: TextareaViewHelperTest.php:54
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextareaViewHelperTest\renderEscapesTextareaContent
‪renderEscapesTextareaContent()
Definition: TextareaViewHelperTest.php:80
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\TextareaViewHelperTest\renderAddsRequired
‪renderAddsRequired()
Definition: TextareaViewHelperTest.php:131