‪TYPO3CMS  9.5
UploadViewHelperTest.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  */
16 
17 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
18 use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder;
19 
23 class ‪UploadViewHelperTest extends ViewHelperBaseTestcase
24 {
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 
41  public function ‪renderCorrectlySetsTagName()
42  {
43  $this->tagBuilder = $this->createMock(\‪TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder::class);
44  $this->tagBuilder->expects($this->atLeastOnce())->method('setTagName')->with('input');
45  $this->viewHelper->setTagBuilder($this->tagBuilder);
46  $this->viewHelper->initializeArgumentsAndRender();
47  }
48 
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 
78  public function ‪renderCallsSetErrorClassAttribute()
79  {
80  $this->viewHelper->expects($this->once())->method('setErrorClassAttribute');
81  $this->viewHelper->initializeArgumentsAndRender();
82  }
83 
88  {
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 }
‪TYPO3Fluid
‪TYPO3
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\UploadViewHelperTest\$viewHelper
‪TYPO3 CMS Fluid ViewHelpers Form UploadViewHelper $viewHelper
Definition: UploadViewHelperTest.php:27
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\UploadViewHelperTest\renderSetsAttributeNameAsArrayIfMultipleIsGiven
‪renderSetsAttributeNameAsArrayIfMultipleIsGiven()
Definition: UploadViewHelperTest.php:86
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\EmptySyntaxTreeNode
Definition: EmptySyntaxTreeNode.php:21
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\UploadViewHelperTest\renderCorrectlySetsTypeNameAndValueAttributes
‪renderCorrectlySetsTypeNameAndValueAttributes()
Definition: UploadViewHelperTest.php:51
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form
Definition: AbstractFormFieldViewHelperTest.php:2
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\UploadViewHelperTest\setUp
‪setUp()
Definition: UploadViewHelperTest.php:29
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\UploadViewHelperTest\renderCorrectlySetsTagName
‪renderCorrectlySetsTagName()
Definition: UploadViewHelperTest.php:40
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\UploadViewHelperTest\renderCallsSetErrorClassAttribute
‪renderCallsSetErrorClassAttribute()
Definition: UploadViewHelperTest.php:77
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\UploadViewHelperTest
Definition: UploadViewHelperTest.php:24