TYPO3 CMS  TYPO3_8-7
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 
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  $this->viewHelper->initializeArguments();
37  }
38 
42  public function renderCorrectlySetsTagName()
43  {
44  $this->tagBuilder = $this->createMock(\TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder::class);
45  $this->tagBuilder->expects($this->once())->method('setTagName')->with('input');
46  $this->viewHelper->_set('tag', $this->tagBuilder);
47  $this->viewHelper->initialize();
48  $this->viewHelper->render();
49  }
50 
55  {
56  $mockTagBuilder = $this->getMockBuilder(TagBuilder::class)
57  ->setMethods(['addAttribute', 'setContent', 'render'])
58  ->disableOriginalConstructor()
59  ->getMock();
60  $mockTagBuilder->expects($this->at(0))->method('addAttribute')->with('type', 'file');
61  $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('name', 'someName');
62  $this->viewHelper->expects($this->at(0))->method('registerFieldNameForFormTokenGeneration')->with('someName[name]');
63  $this->viewHelper->expects($this->at(1))->method('registerFieldNameForFormTokenGeneration')->with('someName[type]');
64  $this->viewHelper->expects($this->at(2))->method('registerFieldNameForFormTokenGeneration')->with('someName[tmp_name]');
65  $this->viewHelper->expects($this->at(3))->method('registerFieldNameForFormTokenGeneration')->with('someName[error]');
66  $this->viewHelper->expects($this->at(4))->method('registerFieldNameForFormTokenGeneration')->with('someName[size]');
67  $mockTagBuilder->expects($this->once())->method('render');
68  $this->viewHelper->_set('tag', $mockTagBuilder);
69  $arguments = [
70  'name' => 'someName'
71  ];
72  $this->viewHelper->setArguments($arguments);
73  $this->viewHelper->setViewHelperNode(new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\EmptySyntaxTreeNode());
74  $this->viewHelper->initialize();
75  $this->viewHelper->render();
76  }
77 
82  {
83  $this->viewHelper->expects($this->once())->method('setErrorClassAttribute');
84  $this->viewHelper->render();
85  }
86 
90  public function renderSetsAttributeNameAsArrayIfMultipleIsGiven()
91  {
93  $tagBuilder = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(TagBuilder::class);
94  $tagBuilder->addAttribute('multiple', 'multiple');
95  $this->viewHelper->_set('tag', $tagBuilder);
96  $arguments = [
97  'name' => 'someName',
98  'multiple' => 'multiple'
99  ];
100  $this->viewHelper->setArguments($arguments);
101  $this->viewHelper->initialize();
102  $result = $this->viewHelper->render();
103  $this->assertEquals('<input multiple="multiple" type="file" name="someName[]" />', $result);
104  }
105 }
static makeInstance($className,... $constructorArguments)