‪TYPO3CMS  9.5
ProcessedFileTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪ProcessedFileTest extends UnitTestCase
28 {
32  protected ‪$resetSingletonInstances = true;
33 
37  protected ‪$folderMock;
38 
42  protected ‪$storageMock;
43 
47  protected ‪$databaseRow = [];
48 
52  protected function ‪setUp()
53  {
54  $this->storageMock = $this->createMock(ResourceStorage::class);
55  $this->storageMock->expects($this->any())->method('getUid')->will($this->returnValue(5));
56 
57  $this->folderMock = $this->createMock(Folder::class);
58  $this->folderMock->expects($this->any())->method('getStorage')->willReturn($this->storageMock);
59 
60  $this->storageMock->expects($this->any())->method('getProcessingFolder')->willReturn($this->folderMock);
61 
62  $this->databaseRow = [
63  'uid' => '1234567',
64  'identifier' => 'dummy.txt',
65  'name' => $this->getUniqueId('dummy_'),
66  'storage' => $this->storageMock->getUid(),
67  'configuration' => null,
68  'originalfilesha1' => null,
69  ];
70  }
71 
77  protected function ‪getFileFixture($dbRow = null, ‪$storageMock = null)
78  {
79  return new ‪File($dbRow ?: $this->databaseRow, ‪$storageMock ?: $this->storageMock);
80  }
81 
87  protected function ‪getProcessedFileFixture($dbRow = null, $originalFile = null)
88  {
89  if ($originalFile === null) {
90  $originalFile = $this->‪getFileFixture();
91  }
92  return new ProcessedFile($originalFile, 'dummy', [], $dbRow ?: $this->databaseRow);
93  }
94 
99  {
100  $processedFileObject = $this->‪getProcessedFileFixture();
101  $this->assertSame($this->databaseRow, $processedFileObject->getProperties());
102  }
103 
107  public function ‪deletingProcessedFileRemovesFile()
108  {
109  $this->storageMock->expects($this->once())->method('deleteFile');
110  $processedDatabaseRow = ‪$this->databaseRow;
111  $processedDatabaseRow['identifier'] = 'processed_dummy.txt';
112  $processedFile = $this->‪getProcessedFileFixture($processedDatabaseRow);
113  $processedFile->delete(true);
114  }
115 
120  {
121  $this->storageMock->expects($this->never())->method('deleteFile');
122  $processedDatabaseRow = ‪$this->databaseRow;
123  $processedDatabaseRow['identifier'] = null;
124  $processedFile = $this->‪getProcessedFileFixture($processedDatabaseRow);
125  $processedFile->delete(true);
126  }
127 }
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\$storageMock
‪PHPUnit_Framework_MockObject_MockObject ResourceStorage $storageMock
Definition: ProcessedFileTest.php:39
‪TYPO3\CMS\Core\Tests\Unit\Resource
Definition: AbstractFileTest.php:3
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\getProcessedFileFixture
‪ProcessedFile getProcessedFileFixture($dbRow=null, $originalFile=null)
Definition: ProcessedFileTest.php:83
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\propertiesOfProcessedFileAreSetFromDatabaseRow
‪propertiesOfProcessedFileAreSetFromDatabaseRow()
Definition: ProcessedFileTest.php:94
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\setUp
‪setUp()
Definition: ProcessedFileTest.php:48
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: ProcessedFileTest.php:31
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\$databaseRow
‪array $databaseRow
Definition: ProcessedFileTest.php:43
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest
Definition: ProcessedFileTest.php:28
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:34
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:23
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\deletingProcessedFileThatUsesOriginalFileDoesNotRemoveFile
‪deletingProcessedFileThatUsesOriginalFileDoesNotRemoveFile()
Definition: ProcessedFileTest.php:115
‪TYPO3\CMS\Core\Resource\ProcessedFile
Definition: ProcessedFile.php:42
‪TYPO3\CMS\Core\Resource\ResourceStorage
Definition: ResourceStorage.php:74
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\$folderMock
‪PHPUnit_Framework_MockObject_MockObject Folder $folderMock
Definition: ProcessedFileTest.php:35
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\deletingProcessedFileRemovesFile
‪deletingProcessedFileRemovesFile()
Definition: ProcessedFileTest.php:103
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\getFileFixture
‪File getFileFixture($dbRow=null, $storageMock=null)
Definition: ProcessedFileTest.php:73