[BUGFIX] Add missing namespace parts
[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\File;
18 use TYPO3\CMS\Core\Resource\Folder;
19 use TYPO3\CMS\Core\Resource\ProcessedFile;
20 use TYPO3\CMS\Core\Resource\ResourceStorage;
21
22 /**
23 * Testcase for the ProcessedFile class of the TYPO3 FAL
24 */
25 class ProcessedFileTest extends \TYPO3\Components\TestingFramework\Core\Unit\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 = [];
41
42 /**
43 * @throws \PHPUnit_Framework_Exception
44 */
45 protected function setUp()
46 {
47 $this->storageMock = $this->createMock(ResourceStorage::class);
48 $this->storageMock->expects($this->any())->method('getUid')->will($this->returnValue(5));
49
50 $this->folderMock = $this->createMock(Folder::class);
51 $this->folderMock->expects($this->any())->method('getStorage')->willReturn($this->storageMock);
52
53 $this->storageMock->expects($this->any())->method('getProcessingFolder')->willReturn($this->folderMock);
54
55 $this->databaseRow = [
56 'uid' => '1234567',
57 'identifier' => 'dummy.txt',
58 'name' => $this->getUniqueId('dummy_'),
59 'storage' => $this->storageMock->getUid(),
60 ];
61 }
62
63 /**
64 * @param array $dbRow
65 * @param ResourceStorage $storageMock
66 * @return File
67 */
68 protected function getFileFixture($dbRow = null, $storageMock = null)
69 {
70 return new File($dbRow ?: $this->databaseRow, $storageMock ?: $this->storageMock);
71 }
72
73 /**
74 * @param array $dbRow
75 * @param File $originalFile
76 * @return ProcessedFile
77 */
78 protected function getProcessedFileFixture($dbRow = null, $originalFile = null)
79 {
80 if ($originalFile === null) {
81 $originalFile = $this->getFileFixture();
82 }
83 return new ProcessedFile($originalFile, 'dummy', [], $dbRow ?: $this->databaseRow);
84 }
85
86 /**
87 * @test
88 */
89 public function propertiesOfProcessedFileAreSetFromDatabaseRow()
90 {
91 $processedFileObject = $this->getProcessedFileFixture();
92 $this->assertSame($this->databaseRow, $processedFileObject->getProperties());
93 }
94
95 /**
96 * @test
97 */
98 public function deletingProcessedFileRemovesFile()
99 {
100 $this->storageMock->expects($this->once())->method('deleteFile');
101 $processedDatabaseRow = $this->databaseRow;
102 $processedDatabaseRow['identifier'] = 'processed_dummy.txt';
103 $processedFile = $this->getProcessedFileFixture($processedDatabaseRow);
104 $processedFile->delete(true);
105 }
106
107 /**
108 * @test
109 */
110 public function deletingProcessedFileThatUsesOriginalFileDoesNotRemoveFile()
111 {
112 $this->storageMock->expects($this->never())->method('deleteFile');
113 $processedDatabaseRow = $this->databaseRow;
114 $processedDatabaseRow['identifier'] = null;
115 $processedFile = $this->getProcessedFileFixture($processedDatabaseRow);
116 $processedFile->delete(true);
117 }
118 }