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