[!!!][TASK] Remove CMS base ViewHelper classes
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / ViewHelpers / Form / UploadViewHelperTest.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\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
18 use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder;
19
20 /**
21 * Test for the "Upload" Form view helper
22 */
23 class UploadViewHelperTest extends ViewHelperBaseTestcase
24 {
25 /**
26 * @var \TYPO3\CMS\Fluid\ViewHelpers\Form\UploadViewHelper
27 */
28 protected $viewHelper;
29
30 protected function setUp()
31 {
32 parent::setUp();
33 $this->viewHelper = $this->getAccessibleMock(\TYPO3\CMS\Fluid\ViewHelpers\Form\UploadViewHelper::class, ['setErrorClassAttribute', 'registerFieldNameForFormTokenGeneration']);
34 $this->arguments['name'] = '';
35 $this->injectDependenciesIntoViewHelper($this->viewHelper);
36 }
37
38 /**
39 * @test
40 */
41 public function renderCorrectlySetsTagName()
42 {
43 $this->tagBuilder = $this->createMock(\TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder::class);
44 $this->tagBuilder->expects($this->once())->method('setTagName')->with('input');
45 $this->viewHelper->setTagBuilder($this->tagBuilder);
46 $this->viewHelper->initializeArgumentsAndRender();
47 }
48
49 /**
50 * @test
51 */
52 public function renderCorrectlySetsTypeNameAndValueAttributes()
53 {
54 $mockTagBuilder = $this->getMockBuilder(TagBuilder::class)
55 ->setMethods(['addAttribute', 'setContent', 'render'])
56 ->disableOriginalConstructor()
57 ->getMock();
58 $mockTagBuilder->expects($this->at(0))->method('addAttribute')->with('type', 'file');
59 $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('name', 'someName');
60 $this->viewHelper->expects($this->at(0))->method('registerFieldNameForFormTokenGeneration')->with('someName[name]');
61 $this->viewHelper->expects($this->at(1))->method('registerFieldNameForFormTokenGeneration')->with('someName[type]');
62 $this->viewHelper->expects($this->at(2))->method('registerFieldNameForFormTokenGeneration')->with('someName[tmp_name]');
63 $this->viewHelper->expects($this->at(3))->method('registerFieldNameForFormTokenGeneration')->with('someName[error]');
64 $this->viewHelper->expects($this->at(4))->method('registerFieldNameForFormTokenGeneration')->with('someName[size]');
65 $mockTagBuilder->expects($this->once())->method('render');
66 $this->viewHelper->setTagBuilder($mockTagBuilder);
67 $arguments = [
68 'name' => 'someName'
69 ];
70 $this->viewHelper->setArguments($arguments);
71 $this->viewHelper->setViewHelperNode(new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\EmptySyntaxTreeNode());
72 $this->viewHelper->initializeArgumentsAndRender();
73 }
74
75 /**
76 * @test
77 */
78 public function renderCallsSetErrorClassAttribute()
79 {
80 $this->viewHelper->expects($this->once())->method('setErrorClassAttribute');
81 $this->viewHelper->initializeArgumentsAndRender();
82 }
83
84 /**
85 * @test
86 */
87 public function renderSetsAttributeNameAsArrayIfMultipleIsGiven()
88 {
89 /** @var TagBuilder $tagBuilder */
90 $tagBuilder = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(TagBuilder::class);
91 $tagBuilder->addAttribute('multiple', 'multiple');
92 $this->viewHelper->setTagBuilder($tagBuilder);
93 $arguments = [
94 'name' => 'someName',
95 'multiple' => 'multiple'
96 ];
97 $this->viewHelper->setArguments($arguments);
98 $result = $this->viewHelper->initializeArgumentsAndRender();
99 $this->assertEquals('<input multiple="multiple" type="file" name="someName[]" />', $result);
100 }
101 }