TYPO3 CMS  TYPO3_7-6
FileControllerTest.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 
24 {
28  protected $fileController;
29 
33  protected $fileResourceMock;
34 
39 
43  protected $mockFileProcessor;
44 
48  protected $request;
49 
53  protected $response;
54 
58  protected function setUp()
59  {
60  $this->fileResourceMock = $this->getMock(\TYPO3\CMS\Core\Resource\File::class, ['toArray', 'getModificationTime', 'getExtension'], [], '', false);
61  $this->folderResourceMock = $this->getMock(\TYPO3\CMS\Core\Resource\Folder::class, ['getIdentifier'], [], '', false);
62  $this->mockFileProcessor = $this->getMock(\TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::class, ['getErrorMessages'], [], '', false);
63 
64  $this->fileResourceMock->expects($this->any())->method('toArray')->will($this->returnValue(['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 
76  {
77  $this->fileController = $this->getAccessibleMock(\TYPO3\CMS\Backend\Controller\File\FileController::class, ['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([]));
82 
83  $this->assertTrue($this->fileController->_call('flattenResultDataValue', true));
84  $this->assertSame([], $this->fileController->_call('flattenResultDataValue', []));
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  [
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 
107  {
108  $this->fileController = $this->getAccessibleMock(\TYPO3\CMS\Backend\Controller\File\FileController::class, ['init', 'main']);
109 
110  $fileData = ['delete' => [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 
124  {
125  $this->fileController = $this->getAccessibleMock(\TYPO3\CMS\Backend\Controller\File\FileController::class, ['init', 'main']);
126 
127  $fileData = ['editfile' => [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 
141  {
142  $this->fileController = $this->getAccessibleMock(\TYPO3\CMS\Backend\Controller\File\FileController::class, ['init', 'main']);
143 
144  $fileData = ['unzip' => [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 
158  {
159  $this->fileController = $this->getAccessibleMock(\TYPO3\CMS\Backend\Controller\File\FileController::class, ['init', 'main']);
160 
161  $fileData = ['editfile' => [true]];
162  $this->fileController->_set('fileProcessor', $this->mockFileProcessor);
163  $this->fileController->_set('fileData', $fileData);
164  $this->fileController->_set('redirect', false);
165 
166  $result = $this->fileController->processAjaxRequest($this->request, $this->response);
167  $this->assertEquals(200, $result->getStatusCode());
168  }
169 
174  {
175  $this->fileController = $this->getAccessibleMock(\TYPO3\CMS\Backend\Controller\File\FileController::class, ['init', 'main']);
176  $this->mockFileProcessor->expects($this->any())->method('getErrorMessages')->will($this->returnValue(['error occured']));
177  $this->fileController->_set('fileProcessor', $this->mockFileProcessor);
178  $result = $this->fileController->processAjaxRequest($this->request, $this->response);
179  $this->assertEquals(500, $result->getStatusCode());
180  }
181 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)