[TASK] Extend markup of icons
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Controller / File / FileControllerTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Controller\File;
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\CMS\Core\Http\ServerRequest;
18 use TYPO3\CMS\Core\Http\Response;
19
20 /**
21 * Tests for \TYPO3\CMS\Backend\Tests\Unit\Controller\File\FileController
22 */
23 class FileControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
24 {
25 /**
26 * @var \TYPO3\CMS\Backend\Controller\File\FileController|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
27 */
28 protected $fileController;
29
30 /**
31 * @var \TYPO3\CMS\Core\Resource\File|\PHPUnit_Framework_MockObject_MockObject
32 */
33 protected $fileResourceMock;
34
35 /**
36 * @var \TYPO3\CMS\Core\Resource\Folder|\PHPUnit_Framework_MockObject_MockObject
37 */
38 protected $folderResourceMock;
39
40 /**
41 * @var \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility|\PHPUnit_Framework_MockObject_MockObject
42 */
43 protected $mockFileProcessor;
44
45 /**
46 * @var ServerRequest|\PHPUnit_Framework_MockObject_MockObject
47 */
48 protected $request;
49
50 /**
51 * @var Response|\PHPUnit_Framework_MockObject_MockObject
52 */
53 protected $response;
54
55 /**
56 * Sets up this test case.
57 */
58 protected function setUp()
59 {
60 $this->fileResourceMock = $this->getMock(\TYPO3\CMS\Core\Resource\File::class, array('toArray', 'getModificationTime', 'getExtension'), array(), '', false);
61 $this->folderResourceMock = $this->getMock(\TYPO3\CMS\Core\Resource\Folder::class, array('getIdentifier'), array(), '', false);
62 $this->mockFileProcessor = $this->getMock(\TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::class, array('getErrorMessages'), array(), '', false);
63
64 $this->fileResourceMock->expects($this->any())->method('toArray')->will($this->returnValue(array('id' => 'foo')));
65 $this->fileResourceMock->expects($this->any())->method('getModificationTime')->will($this->returnValue(123456789));
66 $this->fileResourceMock->expects($this->any())->method('getExtension')->will($this->returnValue('html'));
67
68 $this->request = new ServerRequest();
69 $this->response = new Response();
70 }
71
72 /**
73 * @test
74 */
75 public function flattenResultDataValueFlattensFileAndFolderResourcesButReturnsAnythingElseAsIs()
76 {
77 $this->fileController = $this->getAccessibleMock(\TYPO3\CMS\Backend\Controller\File\FileController::class, array('dummy'));
78
79 $this->folderResourceMock->expects($this->once())->method('getIdentifier')->will($this->returnValue('bar'));
80
81 $this->mockFileProcessor->expects($this->any())->method('getErrorMessages')->will($this->returnValue(array()));
82
83 $this->assertTrue($this->fileController->_call('flattenResultDataValue', true));
84 $this->assertSame(array(), $this->fileController->_call('flattenResultDataValue', array()));
85 $result = $this->fileController->_call('flattenResultDataValue', $this->fileResourceMock);
86 $this->assertContains('<span class="t3js-icon icon icon-size-small icon-state-default icon-mimetypes-text-html" data-identifier="mimetypes-text-html">', $result['icon']);
87 unset($result['icon']);
88 $this->assertSame(
89 array(
90 'id' => 'foo',
91 'date' => '29-11-73',
92 'thumbUrl' => '',
93 ),
94 $result
95 );
96
97 $this->assertSame(
98 'bar',
99 $this->fileController->_call('flattenResultDataValue', $this->folderResourceMock)
100 );
101 }
102
103 /**
104 * @test
105 */
106 public function processAjaxRequestDeleteProcessActuallyDoesNotChangeFileData()
107 {
108 $this->fileController = $this->getAccessibleMock(\TYPO3\CMS\Backend\Controller\File\FileController::class, array('init', 'main'));
109
110 $fileData = array('delete' => array(true));
111 $this->fileController->_set('fileProcessor', $this->mockFileProcessor);
112 $this->fileController->_set('fileData', $fileData);
113 $this->fileController->_set('redirect', false);
114
115 $this->fileController->expects($this->once())->method('main');
116
117 $this->fileController->processAjaxRequest($this->request, $this->response);
118 }
119
120 /**
121 * @test
122 */
123 public function processAjaxRequestEditFileProcessActuallyDoesNotChangeFileData()
124 {
125 $this->fileController = $this->getAccessibleMock(\TYPO3\CMS\Backend\Controller\File\FileController::class, array('init', 'main'));
126
127 $fileData = array('editfile' => array(true));
128 $this->fileController->_set('fileProcessor', $this->mockFileProcessor);
129 $this->fileController->_set('fileData', $fileData);
130 $this->fileController->_set('redirect', false);
131
132 $this->fileController->expects($this->once())->method('main');
133
134 $this->fileController->processAjaxRequest($this->request, $this->response);
135 }
136
137 /**
138 * @test
139 */
140 public function processAjaxRequestUnzipProcessActuallyDoesNotChangeFileData()
141 {
142 $this->fileController = $this->getAccessibleMock(\TYPO3\CMS\Backend\Controller\File\FileController::class, array('init', 'main'));
143
144 $fileData = array('unzip' => array(true));
145 $this->fileController->_set('fileProcessor', $this->mockFileProcessor);
146 $this->fileController->_set('fileData', $fileData);
147 $this->fileController->_set('redirect', false);
148
149 $this->fileController->expects($this->once())->method('main');
150
151 $this->fileController->processAjaxRequest($this->request, $this->response);
152 }
153 }