TYPO3  7.6
FileControllerTest.php
Go to the documentation of this file.
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 
19 
23 class FileControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
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, 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 
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 
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 
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 
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 }