‪TYPO3CMS  ‪main
ProcessedFileTest.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
20 use PHPUnit\Framework\Exception;
21 use PHPUnit\Framework\MockObject\MockObject;
27 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
28 
32 final class ‪ProcessedFileTest extends UnitTestCase
33 {
34  protected bool ‪$resetSingletonInstances = true;
35 
36  protected ‪Folder&MockObject ‪$folderMock;
37 
38  protected ‪ResourceStorage&MockObject ‪$storageMock;
39 
40  protected array ‪$databaseRow = [];
41 
45  protected function ‪setUp(): void
46  {
47  parent::setUp();
48  $this->storageMock = $this->createMock(ResourceStorage::class);
49  $this->storageMock->method('getUid')->willReturn(5);
50  $this->storageMock->method('hashFile')->willReturn('');
51  $this->storageMock->method('deleteFile')->willReturn(true);
52 
53  $this->folderMock = $this->createMock(Folder::class);
54  $this->folderMock->method('getStorage')->willReturn($this->storageMock);
55 
56  $this->storageMock->method('getProcessingFolder')->willReturn($this->folderMock);
57 
58  $this->databaseRow = [
59  'uid' => '1234567',
60  'identifier' => 'dummy.txt',
61  'name' => ‪StringUtility::getUniqueId('dummy_'),
62  'storage' => $this->storageMock->getUid(),
63  'configuration' => null,
64  'originalfilesha1' => null,
65  ];
66  }
67 
68  protected function ‪getFileFixture(array $dbRow = null, ‪ResourceStorage ‪$storageMock = null): ‪File
69  {
70  return new ‪File($dbRow ?: $this->databaseRow, ‪$storageMock ?: $this->storageMock);
71  }
72 
73  protected function ‪getProcessedFileFixture(array $dbRow = null, ‪File $originalFile = null): ‪ProcessedFile
74  {
75  if ($originalFile === null) {
76  $originalFile = $this->‪getFileFixture();
77  }
78  return new ‪ProcessedFile($originalFile, 'dummy', [], $dbRow ?: $this->databaseRow);
79  }
80 
85  {
86  $processedFileObject = $this->‪getProcessedFileFixture();
87  self::assertSame($this->databaseRow, $processedFileObject->getProperties());
88  }
89 
93  public function ‪deletingProcessedFileRemovesFile(): void
94  {
95  $this->storageMock->expects(self::once())->method('deleteFile');
96  $processedDatabaseRow = ‪$this->databaseRow;
97  $processedDatabaseRow['identifier'] = 'processed_dummy.txt';
98  $processedFile = $this->‪getProcessedFileFixture($processedDatabaseRow);
99  $processedFile->delete(true);
100  }
101 
106  {
107  $this->storageMock->expects(self::never())->method('deleteFile');
108  $processedDatabaseRow = ‪$this->databaseRow;
109  $processedDatabaseRow['identifier'] = null;
110  $processedFile = $this->‪getProcessedFileFixture($processedDatabaseRow);
111  $processedFile->delete(true);
112  }
113 }
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\getFileFixture
‪getFileFixture(array $dbRow=null, ResourceStorage $storageMock=null)
Definition: ProcessedFileTest.php:68
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\$folderMock
‪Folder &MockObject $folderMock
Definition: ProcessedFileTest.php:36
‪TYPO3\CMS\Core\Tests\Unit\Resource
Definition: AbstractFileTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\propertiesOfProcessedFileAreSetFromDatabaseRow
‪propertiesOfProcessedFileAreSetFromDatabaseRow()
Definition: ProcessedFileTest.php:84
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\setUp
‪setUp()
Definition: ProcessedFileTest.php:45
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\$storageMock
‪ResourceStorage &MockObject $storageMock
Definition: ProcessedFileTest.php:38
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: ProcessedFileTest.php:34
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\$databaseRow
‪array $databaseRow
Definition: ProcessedFileTest.php:40
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest
Definition: ProcessedFileTest.php:33
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:38
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:26
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\deletingProcessedFileThatUsesOriginalFileDoesNotRemoveFile
‪deletingProcessedFileThatUsesOriginalFileDoesNotRemoveFile()
Definition: ProcessedFileTest.php:105
‪TYPO3\CMS\Core\Resource\ProcessedFile
Definition: ProcessedFile.php:47
‪TYPO3\CMS\Core\Resource\ResourceStorage
Definition: ResourceStorage.php:128
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\getProcessedFileFixture
‪getProcessedFileFixture(array $dbRow=null, File $originalFile=null)
Definition: ProcessedFileTest.php:73
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\deletingProcessedFileRemovesFile
‪deletingProcessedFileRemovesFile()
Definition: ProcessedFileTest.php:93
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:24
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static getUniqueId(string $prefix='')
Definition: StringUtility.php:57