[BUGFIX] Allow processed folders in different storage
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Resource / ProcessedFileTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Resource;
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\Resource\ProcessedFile;
18 use TYPO3\CMS\Core\Resource\ResourceStorage;
19 use TYPO3\CMS\Core\Resource\File;
20 use TYPO3\CMS\Core\Resource\Folder;
21
22 /**
23 * Testcase for the ProcessedFile class of the TYPO3 FAL
24 */
25 class ProcessedFileTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
26
27 /**
28 * @var \PHPUnit_Framework_MockObject_MockObject|Folder
29 */
30 protected $folderMock;
31
32 /**
33 * @var \PHPUnit_Framework_MockObject_MockObject|ResourceStorage
34 */
35 protected $storageMock;
36
37 /**
38 * @var array
39 */
40 protected $databaseRow = array();
41
42 /**
43 * @throws \PHPUnit_Framework_Exception
44 */
45 protected function setUp() {
46 $this->storageMock = $this->getMock(ResourceStorage::class, array(), array(), '', FALSE);
47 $this->storageMock->expects($this->any())->method('getUid')->will($this->returnValue(5));
48
49 $this->folderMock = $this->getMock(Folder::class, array(), array(), '', FALSE);
50 $this->folderMock->expects($this->any())->method('getStorage')->willReturn($this->storageMock);
51
52 $this->storageMock->expects($this->any())->method('getProcessingFolder')->willReturn($this->folderMock);
53
54 $this->databaseRow = array(
55 'uid' => '1234567',
56 'identifier' => 'dummy.txt',
57 'name' => $this->getUniqueId('dummy_'),
58 'storage' => $this->storageMock->getUid(),
59 );
60 }
61
62 /**
63 * @param array $dbRow
64 * @param ResourceStorage $storageMock
65 * @return File
66 */
67 protected function getFileFixture($dbRow = NULL, $storageMock = NULL) {
68 return new File($dbRow ?: $this->databaseRow, $storageMock ?: $this->storageMock);
69 }
70
71 /**
72 * @param array $dbRow
73 * @param File $originalFile
74 * @return ProcessedFile
75 */
76 protected function getProcessedFileFixture($dbRow = NULL, $originalFile = NULL) {
77 if ($originalFile === NULL) {
78 $originalFile = $this->getFileFixture();
79 }
80 return new ProcessedFile($originalFile, 'dummy', array(), $dbRow ?: $this->databaseRow);
81 }
82
83 /**
84 * @test
85 */
86 public function propertiesOfProcessedFileAreSetFromDatabaseRow() {
87 $processedFileObject = $this->getProcessedFileFixture();
88 $this->assertSame($this->databaseRow, $processedFileObject->getProperties());
89 }
90
91 /**
92 * @test
93 */
94 public function deletingProcessedFileRemovesFile() {
95 $this->storageMock->expects($this->once())->method('deleteFile');
96 $processedDatabaseRow = $this->databaseRow;
97 $processedDatabaseRow['identifier'] = 'processed_dummy.txt';
98 $processedFile = $this->getProcessedFileFixture($processedDatabaseRow);
99 $processedFile->delete(TRUE);
100 }
101
102 /**
103 * @test
104 */
105 public function deletingProcessedFileThatUsesOriginalFileDoesNotRemoveFile() {
106 $this->storageMock->expects($this->never())->method('deleteFile');
107 $processedDatabaseRow = $this->databaseRow;
108 $processedDatabaseRow['identifier'] = NULL;
109 $processedFile = $this->getProcessedFileFixture($processedDatabaseRow);
110 $processedFile->delete(TRUE);
111 }
112 }