‪TYPO3CMS  10.4
UploadViewHelperTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
21 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
22 use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder;
23 
27 class ‪UploadViewHelperTest extends ViewHelperBaseTestcase
28 {
32  protected ‪$viewHelper;
33 
34  protected function ‪setUp(): void
35  {
36  parent::setUp();
37  $this->viewHelper = $this->getAccessibleMock(UploadViewHelper::class, ['setErrorClassAttribute', 'registerFieldNameForFormTokenGeneration']);
38  $this->arguments['name'] = '';
39  $this->injectDependenciesIntoViewHelper($this->viewHelper);
40  }
41 
45  public function ‪renderCorrectlySetsTagName()
46  {
47  $this->tagBuilder = $this->createMock(TagBuilder::class);
48  $this->tagBuilder->expects(self::atLeastOnce())->method('setTagName')->with('input');
49  $this->viewHelper->setTagBuilder($this->tagBuilder);
50  $this->viewHelper->initializeArgumentsAndRender();
51  }
52 
57  {
58  $mockTagBuilder = $this->getMockBuilder(TagBuilder::class)
59  ->setMethods(['addAttribute', 'setContent', 'render'])
60  ->disableOriginalConstructor()
61  ->getMock();
62  $mockTagBuilder->expects(self::exactly(2))->method('addAttribute')->withConsecutive(
63  ['type', 'file'],
64  ['name', 'someName']
65  );
66  $this->viewHelper->expects(self::exactly(5))->method('registerFieldNameForFormTokenGeneration')->withConsecutive(
67  ['someName[name]'],
68  ['someName[type]'],
69  ['someName[tmp_name]'],
70  ['someName[error]'],
71  ['someName[size]']
72  );
73  $mockTagBuilder->expects(self::once())->method('render');
74  $this->viewHelper->setTagBuilder($mockTagBuilder);
75  $arguments = [
76  'name' => 'someName'
77  ];
78  $this->viewHelper->setArguments($arguments);
79  $this->viewHelper->setViewHelperNode(new EmptySyntaxTreeNode());
80  $this->viewHelper->initializeArgumentsAndRender();
81  }
82 
86  public function ‪renderCallsSetErrorClassAttribute()
87  {
88  $this->viewHelper->expects(self::once())->method('setErrorClassAttribute');
89  $this->viewHelper->initializeArgumentsAndRender();
90  }
91 
96  {
98  $tagBuilder = GeneralUtility::makeInstance(TagBuilder::class);
99  $tagBuilder->addAttribute('multiple', 'multiple');
100  $this->viewHelper->setTagBuilder($tagBuilder);
101  $arguments = [
102  'name' => 'someName',
103  'multiple' => 'multiple'
104  ];
105  $this->viewHelper->setArguments($arguments);
106  $result = $this->viewHelper->initializeArgumentsAndRender();
107  self::assertEquals('<input multiple="multiple" type="file" name="someName[]" />', $result);
108  }
109 }
‪TYPO3\CMS\Fluid\ViewHelpers\Form\UploadViewHelper
Definition: UploadViewHelper.php:34
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\UploadViewHelperTest\$viewHelper
‪TYPO3 CMS Fluid ViewHelpers Form UploadViewHelper $viewHelper
Definition: UploadViewHelperTest.php:31
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\UploadViewHelperTest\renderSetsAttributeNameAsArrayIfMultipleIsGiven
‪renderSetsAttributeNameAsArrayIfMultipleIsGiven()
Definition: UploadViewHelperTest.php:94
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\EmptySyntaxTreeNode
Definition: EmptySyntaxTreeNode.php:24
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\UploadViewHelperTest\renderCorrectlySetsTypeNameAndValueAttributes
‪renderCorrectlySetsTypeNameAndValueAttributes()
Definition: UploadViewHelperTest.php:55
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form
Definition: AbstractFormFieldViewHelperTest.php:16
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\UploadViewHelperTest\setUp
‪setUp()
Definition: UploadViewHelperTest.php:33
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\UploadViewHelperTest\renderCorrectlySetsTagName
‪renderCorrectlySetsTagName()
Definition: UploadViewHelperTest.php:44
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\UploadViewHelperTest\renderCallsSetErrorClassAttribute
‪renderCallsSetErrorClassAttribute()
Definition: UploadViewHelperTest.php:85
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\UploadViewHelperTest
Definition: UploadViewHelperTest.php:28
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46