‪TYPO3CMS  10.4
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 
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
30 class ‪ProcessedFileTest extends UnitTestCase
31 {
35  protected ‪$resetSingletonInstances = true;
36 
40  protected ‪$folderMock;
41 
45  protected ‪$storageMock;
46 
50  protected ‪$databaseRow = [];
51 
55  protected function ‪setUp(): void
56  {
57  parent::setUp();
58  $this->storageMock = $this->createMock(ResourceStorage::class);
59  $this->storageMock->expects(self::any())->method('getUid')->willReturn(5);
60 
61  $this->folderMock = $this->createMock(Folder::class);
62  $this->folderMock->expects(self::any())->method('getStorage')->willReturn($this->storageMock);
63 
64  $this->storageMock->expects(self::any())->method('getProcessingFolder')->willReturn($this->folderMock);
65 
66  $this->databaseRow = [
67  'uid' => '1234567',
68  'identifier' => 'dummy.txt',
69  'name' => ‪StringUtility::getUniqueId('dummy_'),
70  'storage' => $this->storageMock->getUid(),
71  'configuration' => null,
72  'originalfilesha1' => null,
73  ];
74  }
75 
81  protected function ‪getFileFixture($dbRow = null, ‪$storageMock = null)
82  {
83  return new ‪File($dbRow ?: $this->databaseRow, ‪$storageMock ?: $this->storageMock);
84  }
85 
91  protected function ‪getProcessedFileFixture($dbRow = null, $originalFile = null)
92  {
93  if ($originalFile === null) {
94  $originalFile = $this->‪getFileFixture();
95  }
96  return new ProcessedFile($originalFile, 'dummy', [], $dbRow ?: $this->databaseRow);
97  }
98 
103  {
104  $processedFileObject = $this->‪getProcessedFileFixture();
105  self::assertSame($this->databaseRow, $processedFileObject->getProperties());
106  }
107 
111  public function ‪deletingProcessedFileRemovesFile()
112  {
113  $this->storageMock->expects(self::once())->method('deleteFile');
114  $processedDatabaseRow = ‪$this->databaseRow;
115  $processedDatabaseRow['identifier'] = 'processed_dummy.txt';
116  $processedFile = $this->‪getProcessedFileFixture($processedDatabaseRow);
117  $processedFile->delete(true);
118  }
119 
124  {
125  $this->storageMock->expects(self::never())->method('deleteFile');
126  $processedDatabaseRow = ‪$this->databaseRow;
127  $processedDatabaseRow['identifier'] = null;
128  $processedFile = $this->‪getProcessedFileFixture($processedDatabaseRow);
129  $processedFile->delete(true);
130  }
131 }
‪TYPO3\CMS\Core\Tests\Unit\Resource
Definition: AbstractFileTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\getProcessedFileFixture
‪ProcessedFile getProcessedFileFixture($dbRow=null, $originalFile=null)
Definition: ProcessedFileTest.php:87
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\propertiesOfProcessedFileAreSetFromDatabaseRow
‪propertiesOfProcessedFileAreSetFromDatabaseRow()
Definition: ProcessedFileTest.php:98
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\setUp
‪setUp()
Definition: ProcessedFileTest.php:51
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\$storageMock
‪PHPUnit Framework MockObject MockObject ResourceStorage $storageMock
Definition: ProcessedFileTest.php:42
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: ProcessedFileTest.php:34
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\$folderMock
‪PHPUnit Framework MockObject MockObject Folder $folderMock
Definition: ProcessedFileTest.php:38
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\$databaseRow
‪array $databaseRow
Definition: ProcessedFileTest.php:46
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest
Definition: ProcessedFileTest.php:31
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:37
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:24
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\deletingProcessedFileThatUsesOriginalFileDoesNotRemoveFile
‪deletingProcessedFileThatUsesOriginalFileDoesNotRemoveFile()
Definition: ProcessedFileTest.php:119
‪TYPO3\CMS\Core\Resource\ProcessedFile
Definition: ProcessedFile.php:44
‪TYPO3\CMS\Core\Resource\ResourceStorage
Definition: ResourceStorage.php:122
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static string getUniqueId($prefix='')
Definition: StringUtility.php:92
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\deletingProcessedFileRemovesFile
‪deletingProcessedFileRemovesFile()
Definition: ProcessedFileTest.php:107
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:22
‪TYPO3\CMS\Core\Tests\Unit\Resource\ProcessedFileTest\getFileFixture
‪File getFileFixture($dbRow=null, $storageMock=null)
Definition: ProcessedFileTest.php:77