2 namespace TYPO3\CMS\Backend\Tests\Unit\Controller\File
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
18 * Tests for \TYPO3\CMS\Backend\Tests\Unit\Controller\File\FileController
20 class FileControllerTest
extends \TYPO3\CMS\Core\Tests\UnitTestCase
{
23 * @var \TYPO3\CMS\Backend\Controller\File\FileController|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
25 protected $fileController;
28 * @var \TYPO3\CMS\Core\Resource\File|\PHPUnit_Framework_MockObject_MockObject
30 protected $fileResourceMock;
33 * @var \TYPO3\CMS\Core\Resource\Folder|\PHPUnit_Framework_MockObject_MockObject
35 protected $folderResourceMock;
38 * @var \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility|\PHPUnit_Framework_MockObject_MockObject
40 protected $mockFileProcessor;
43 * @var \TYPO3\CMS\Core\Http\AjaxRequestHandler|\PHPUnit_Framework_MockObject_MockObject
45 protected $mockAjaxRequestHandler;
48 * Sets up this test case.
50 protected function setUp() {
51 $this->fileResourceMock
= $this->getMock(\TYPO3\CMS\Core\
Resource\File
::class, array('toArray', 'getModificationTime', 'getExtension'), array(), '', FALSE);
52 $this->folderResourceMock
= $this->getMock(\TYPO3\CMS\Core\
Resource\Folder
::class, array('getIdentifier'), array(), '', FALSE);
53 $this->mockFileProcessor
= $this->getMock(\TYPO3\CMS\Core\Utility\File\ExtendedFileUtility
::class, array('getErrorMessages'), array(), '', FALSE);
55 $this->fileResourceMock
->expects($this->any())->method('toArray')->will($this->returnValue(array('id' => 'foo')));
56 $this->fileResourceMock
->expects($this->any())->method('getModificationTime')->will($this->returnValue(123456789));
57 $this->fileResourceMock
->expects($this->any())->method('getExtension')->will($this->returnValue('html'));
63 public function flattenResultDataValueFlattensFileAndFolderResourcesButReturnsAnythingElseAsIs() {
64 $this->fileController
= $this->getAccessibleMock(\TYPO3\CMS\Backend\Controller\File\FileController
::class, array('dummy'));
66 $this->folderResourceMock
->expects($this->once())->method('getIdentifier')->will($this->returnValue('bar'));
68 $this->mockFileProcessor
->expects($this->any())->method('getErrorMessages')->will($this->returnValue(array()));
70 $this->assertTrue($this->fileController
->_call('flattenResultDataValue', TRUE));
71 $this->assertSame(array(), $this->fileController
->_call('flattenResultDataValue', array()));
77 'iconClasses' => 't3-icon t3-icon-mimetypes t3-icon-mimetypes-text t3-icon-text-html'
79 $this->fileController
->_call('flattenResultDataValue', $this->fileResourceMock
)
84 $this->fileController
->_call('flattenResultDataValue', $this->folderResourceMock
)
91 public function processAjaxRequestDeleteProcessActuallyDoesNotChangeFileData() {
92 $this->fileController
= $this->getAccessibleMock(\TYPO3\CMS\Backend\Controller\File\FileController
::class, array('init', 'main'));
93 $this->mockAjaxRequestHandler
= $this->getMock(\TYPO3\CMS\Core\Http\AjaxRequestHandler
::class, array('addContent', 'setContentFormat'), array(), '', FALSE);
95 $fileData = array('delete' => array(TRUE));
96 $this->fileController
->_set('fileProcessor', $this->mockFileProcessor
);
97 $this->fileController
->_set('fileData', $fileData);
98 $this->fileController
->_set('redirect', FALSE);
100 $this->fileController
->expects($this->once())->method('init');
101 $this->fileController
->expects($this->once())->method('main');
102 $this->mockAjaxRequestHandler
->expects($this->once())->method('addContent')->with('result', $fileData);
103 $this->mockAjaxRequestHandler
->expects($this->once())->method('setContentFormat')->with('json');
105 $this->fileController
->processAjaxRequest(array(), $this->mockAjaxRequestHandler
);
111 public function processAjaxRequestEditFileProcessActuallyDoesNotChangeFileData() {
112 $this->fileController
= $this->getAccessibleMock(\TYPO3\CMS\Backend\Controller\File\FileController
::class, array('init', 'main'));
113 $this->mockAjaxRequestHandler
= $this->getMock(\TYPO3\CMS\Core\Http\AjaxRequestHandler
::class, array('addContent', 'setContentFormat'), array(), '', FALSE);
115 $fileData = array('editfile' => array(TRUE));
116 $this->fileController
->_set('fileProcessor', $this->mockFileProcessor
);
117 $this->fileController
->_set('fileData', $fileData);
118 $this->fileController
->_set('redirect', FALSE);
120 $this->fileController
->expects($this->once())->method('init');
121 $this->fileController
->expects($this->once())->method('main');
122 $this->mockAjaxRequestHandler
->expects($this->once())->method('addContent')->with('result', $fileData);
123 $this->mockAjaxRequestHandler
->expects($this->once())->method('setContentFormat')->with('json');
125 $this->fileController
->processAjaxRequest(array(), $this->mockAjaxRequestHandler
);
131 public function processAjaxRequestUnzipProcessActuallyDoesNotChangeFileData() {
132 $this->fileController
= $this->getAccessibleMock(\TYPO3\CMS\Backend\Controller\File\FileController
::class, array('init', 'main'));
133 $this->mockAjaxRequestHandler
= $this->getMock(\TYPO3\CMS\Core\Http\AjaxRequestHandler
::class, array('addContent', 'setContentFormat'), array(), '', FALSE);
135 $fileData = array('unzip' => array(TRUE));
136 $this->fileController
->_set('fileProcessor', $this->mockFileProcessor
);
137 $this->fileController
->_set('fileData', $fileData);
138 $this->fileController
->_set('redirect', FALSE);
140 $this->fileController
->expects($this->once())->method('init');
141 $this->fileController
->expects($this->once())->method('main');
142 $this->mockAjaxRequestHandler
->expects($this->once())->method('addContent')->with('result', $fileData);
143 $this->mockAjaxRequestHandler
->expects($this->once())->method('setContentFormat')->with('json');
145 $this->fileController
->processAjaxRequest(array(), $this->mockAjaxRequestHandler
);
151 public function processAjaxRequestUploadProcess() {
152 $this->fileController
= $this->getAccessibleMock(\TYPO3\CMS\Backend\Controller\File\FileController
::class, array('init', 'main'));
153 $this->mockAjaxRequestHandler
= $this->getMock(\TYPO3\CMS\Core\Http\AjaxRequestHandler
::class, array('addContent', 'setContentFormat'), array(), '', FALSE);
155 $fileData = array('upload' => array(array($this->fileResourceMock
)));
156 $result = array('upload' => array(array(
158 'date' => '29-11-73',
159 'iconClasses' => 't3-icon t3-icon-mimetypes t3-icon-mimetypes-text t3-icon-text-html'
161 $this->fileController
->_set('fileProcessor', $this->mockFileProcessor
);
162 $this->fileController
->_set('fileData', $fileData);
163 $this->fileController
->_set('redirect', FALSE);
165 $this->fileController
->expects($this->once())->method('init');
166 $this->fileController
->expects($this->once())->method('main');
167 $this->mockAjaxRequestHandler
->expects($this->once())->method('addContent')->with('result', $result);
168 $this->mockAjaxRequestHandler
->expects($this->once())->method('setContentFormat')->with('json');
170 $this->fileController
->processAjaxRequest(array(), $this->mockAjaxRequestHandler
);