[FEATURE] Add placeholder argument to VH for Textarea and Textfield
[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 script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License, either version 3 *
9 * of the License, or (at your option) any later version. *
10 * *
11 * The TYPO3 project - inspiring people to share! *
12 * */
13
14 require_once(__DIR__ . '/Fixtures/EmptySyntaxTreeNode.php');
15 require_once(__DIR__ . '/Fixtures/Fixture_UserDomainClass.php');
16 require_once(__DIR__ . '/FormFieldViewHelperBaseTestcase.php');
17
18 /**
19 * Test for the "Textfield" Form view helper
20 */
21 class TextfieldViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\FormFieldViewHelperBaseTestcase {
22
23 /**
24 * @var \TYPO3\CMS\Fluid\ViewHelpers\Form\TextfieldViewHelper
25 */
26 protected $viewHelper;
27
28 public function setUp() {
29 parent::setUp();
30 $this->viewHelper = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Form\\TextfieldViewHelper', array('setErrorClassAttribute', 'registerFieldNameForFormTokenGeneration'));
31 $this->arguments['name'] = '';
32 $this->injectDependenciesIntoViewHelper($this->viewHelper);
33 $this->viewHelper->initializeArguments();
34 }
35
36 /**
37 * @test
38 */
39 public function renderCorrectlySetsTagName() {
40 $mockTagBuilder = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TagBuilder', array('setTagName'), array(), '', FALSE);
41 $mockTagBuilder->expects($this->once())->method('setTagName')->with('input');
42 $this->viewHelper->injectTagBuilder($mockTagBuilder);
43
44 $this->viewHelper->initialize();
45 $this->viewHelper->render();
46 }
47
48 /**
49 * @test
50 */
51 public function renderCorrectlySetsTypeNameAndValueAttributes() {
52 $mockTagBuilder = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TagBuilder', array('addAttribute', 'setContent', 'render'), array(), '', FALSE);
53 $mockTagBuilder->expects($this->at(0))->method('addAttribute')->with('type', 'text');
54 $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('name', 'NameOfTextfield');
55 $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('NameOfTextfield');
56 $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('value', 'Current value');
57 $mockTagBuilder->expects($this->once())->method('render');
58 $this->viewHelper->injectTagBuilder($mockTagBuilder);
59
60 $arguments = array(
61 'name' => 'NameOfTextfield',
62 'value' => 'Current value'
63 );
64 $this->viewHelper->setArguments($arguments);
65
66 $this->viewHelper->setViewHelperNode(new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\EmptySyntaxTreeNode());
67 $this->viewHelper->initialize();
68 $this->viewHelper->render();
69 }
70
71 /**
72 * @test
73 */
74 public function renderCallsSetErrorClassAttribute() {
75 $this->viewHelper->expects($this->once())->method('setErrorClassAttribute');
76 $this->viewHelper->render();
77 }
78
79
80 /**
81 * @test
82 */
83 public function renderAddsPlaceholder() {
84 $mockTagBuilder = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TagBuilder', array('addAttribute', 'setContent', 'render'), array(), '', FALSE);
85 $mockTagBuilder->expects($this->at(0))->method('addAttribute')->with('placeholder', 'SomePlaceholder');
86 $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'text');
87 $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'NameOfTextfield');
88 $mockTagBuilder->expects($this->once())->method('render');
89 $this->viewHelper->injectTagBuilder($mockTagBuilder);
90
91 $arguments = array(
92 'name' => 'NameOfTextfield',
93 'placeholder' => 'SomePlaceholder'
94 );
95 $this->viewHelper->setArguments($arguments);
96
97 $this->viewHelper->setViewHelperNode(new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\EmptySyntaxTreeNode());
98 $this->viewHelper->initialize();
99 $this->viewHelper->render();
100 }
101 }
102
103 ?>