TYPO3 CMS  TYPO3_8-7
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 
22 {
26  protected $viewHelper;
27 
28  protected function setUp()
29  {
30  parent::setUp();
31  $this->viewHelper = $this->getAccessibleMock(\TYPO3\CMS\Fluid\ViewHelpers\Form\TextareaViewHelper::class, ['setErrorClassAttribute', 'registerFieldNameForFormTokenGeneration']);
32  $this->arguments['name'] = '';
33  $this->injectDependenciesIntoViewHelper($this->viewHelper);
34  $this->viewHelper->initializeArguments();
35  }
36 
40  public function renderCorrectlySetsTagName()
41  {
42  $mockTagBuilder = $this->getMockBuilder(TagBuilder::class)
43  ->setMethods(['setTagName'])
44  ->disableOriginalConstructor()
45  ->getMock();
46  $mockTagBuilder->expects($this->once())->method('setTagName')->with('textarea');
47  $this->viewHelper->_set('tag', $mockTagBuilder);
48 
49  $this->viewHelper->initialize();
50  $this->viewHelper->render();
51  }
52 
57  {
58  $mockTagBuilder = $this->getMockBuilder(TagBuilder::class)
59  ->setMethods(['addAttribute', 'setContent', 'render'])
60  ->disableOriginalConstructor()
61  ->getMock();
62  $mockTagBuilder->expects($this->once())->method('addAttribute')->with('name', 'NameOfTextarea');
63  $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('NameOfTextarea');
64  $mockTagBuilder->expects($this->once())->method('setContent')->with('Current value');
65  $mockTagBuilder->expects($this->once())->method('render');
66  $this->viewHelper->_set('tag', $mockTagBuilder);
67 
68  $arguments = [
69  'name' => 'NameOfTextarea',
70  'value' => 'Current value'
71  ];
72  $this->viewHelper->setArguments($arguments);
73 
74  $this->viewHelper->setViewHelperNode(new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\EmptySyntaxTreeNode());
75  $this->viewHelper->initialize();
76  $this->viewHelper->render();
77  }
78 
83  {
84  $this->viewHelper->expects($this->once())->method('setErrorClassAttribute');
85  $this->viewHelper->render();
86  }
87 
91  public function renderEscapesTextareaContent()
92  {
93  $mockTagBuilder = $this->getMockBuilder(TagBuilder::class)
94  ->setMethods(['addAttribute', 'setContent', 'render'])
95  ->disableOriginalConstructor()
96  ->getMock();
97  $mockTagBuilder->expects($this->once())->method('addAttribute')->with('name', 'NameOfTextarea');
98  $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('NameOfTextarea');
99  $mockTagBuilder->expects($this->once())->method('setContent')->with('some &lt;tag&gt; &amp; &quot;quotes&quot;');
100  $mockTagBuilder->expects($this->once())->method('render');
101  $this->viewHelper->_set('tag', $mockTagBuilder);
102 
103  $arguments = [
104  'name' => 'NameOfTextarea',
105  'value' => 'some <tag> & "quotes"'
106  ];
107  $this->viewHelper->setArguments($arguments);
108 
109  $this->viewHelper->setViewHelperNode(new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\EmptySyntaxTreeNode());
110  $this->viewHelper->initialize();
111  $this->viewHelper->render();
112  }
113 
117  public function renderAddsPlaceholder()
118  {
119  $mockTagBuilder = $this->getMockBuilder(TagBuilder::class)
120  ->setMethods(['addAttribute', 'setContent', 'render'])
121  ->disableOriginalConstructor()
122  ->getMock();
123  $mockTagBuilder->expects($this->at(0))->method('addAttribute')->with('placeholder', 'SomePlaceholder');
124  $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('name', 'NameOfTextarea');
125  $mockTagBuilder->expects($this->once())->method('render');
126  $this->viewHelper->_set('tag', $mockTagBuilder);
127 
128  $arguments = [
129  'name' => 'NameOfTextarea',
130  'placeholder' => 'SomePlaceholder'
131  ];
132  $this->viewHelper->setArguments($arguments);
133 
134  $this->viewHelper->setViewHelperNode(new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\EmptySyntaxTreeNode());
135  $this->viewHelper->initialize();
136  $this->viewHelper->render();
137  }
138 }