‪TYPO3CMS  ‪main
ResourceFactoryTest.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\Attributes\Test;
27 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
28 
29 final class ‪ResourceFactoryTest extends UnitTestCase
30 {
31  protected bool ‪$resetSingletonInstances = true;
32 
33  protected bool ‪$backupEnvironment = true;
34 
38  protected ‪$subject;
39 
40  protected array ‪$filesCreated = [];
41 
42  protected function ‪setUp(): void
43  {
44  parent::setUp();
45  $this->subject = $this->getAccessibleMock(ResourceFactory::class, null, [], '', false);
46  }
47 
51  protected function ‪tearDown(): void
52  {
53  foreach ($this->filesCreated as $file) {
54  unlink($file);
55  }
56  parent::tearDown();
57  }
58 
59  #[Test]
61  {
62  $mockedMount = $this->createMock(ResourceStorage::class);
63  $path = ‪StringUtility::getUniqueId('path_');
65  $folderObject = $this->subject->createFolderObject($mockedMount, $path, ‪$name);
66  self::assertSame($mockedMount, $folderObject->getStorage());
67  self::assertEquals($path, $folderObject->getIdentifier());
68  self::assertEquals(‪$name, $folderObject->getName());
69  }
70 
71  /***********************************
72  * File Handling
73  ***********************************/
74  #[Test]
76  {
77  ‪$subject = $this->getAccessibleMock(
78  ResourceFactory::class,
79  ['getFolderObjectFromCombinedIdentifier'],
80  [],
81  '',
82  false
83  );
85  ->expects(self::once())
86  ->method('getFolderObjectFromCombinedIdentifier')
87  ->with('typo3');
89  }
90 
91  #[Test]
93  {
94  ‪$subject = $this->getAccessibleMock(
95  ResourceFactory::class,
96  ['getFolderObjectFromCombinedIdentifier'],
97  [],
98  '',
99  false
100  );
102  ->expects(self::once())
103  ->method('getFolderObjectFromCombinedIdentifier')
104  ->with('typo3');
106  }
107 
108  #[Test]
110  {
111  $this->subject = $this->getAccessibleMock(ResourceFactory::class, ['getFileObjectFromCombinedIdentifier'], [], '', false);
112  $filename = 'typo3temp/var/tests/4711.txt';
113  $this->subject->expects(self::once())
114  ->method('getFileObjectFromCombinedIdentifier')
115  ->with($filename);
116  // Create and prepare test file
118  $this->filesCreated[] = ‪Environment::getPublicPath() . '/' . $filename;
119  $this->subject->retrieveFileOrFolderObject($filename);
120  }
121 
122  #[Test]
124  {
127  true,
128  true,
130  ‪Environment::getPublicPath() . '/typo3temp/public',
134  ‪Environment::isWindows() ? 'WINDOWS' : 'UNIX'
135  );
136 
138 
139  $this->subject = $this->getAccessibleMock(ResourceFactory::class, ['getFileObjectFromCombinedIdentifier'], [], '', false);
140  $filename = 'typo3temp/var/tests/4711.txt';
141  $this->subject->expects(self::once())
142  ->method('getFileObjectFromCombinedIdentifier')
143  ->with($filename);
144  // Create and prepare test file
146  $this->filesCreated[] = ‪Environment::getPublicPath() . '/' . $filename;
147  $this->subject->retrieveFileOrFolderObject($filename);
148  }
149 
150  #[Test]
152  {
155  true,
156  true,
158  ‪Environment::getPublicPath() . '/typo3temp/public',
162  ‪Environment::isWindows() ? 'WINDOWS' : 'UNIX'
163  );
164  $this->subject = $this->getAccessibleMock(ResourceFactory::class, ['getFileObjectFromCombinedIdentifier'], [], '', false);
165  $this->subject->expects(self::once())
166  ->method('getFileObjectFromCombinedIdentifier')
167  ->with('_assets/d25de869aebcd01495d2fe67ad5b0e25/Icons/Extension.svg');
168  // Create and prepare test file
169  $this->subject->retrieveFileOrFolderObject('EXT:core/Resources/Public/Icons/Extension.svg');
170  }
171 
172  #[Test]
174  {
177  true,
178  true,
180  ‪Environment::getPublicPath() . '/typo3temp/public',
184  ‪Environment::isWindows() ? 'WINDOWS' : 'UNIX'
185  );
186  $this->subject = $this->getAccessibleMock(ResourceFactory::class, ['getFileObjectFromCombinedIdentifier'], [], '', false);
187  $this->expectException(ResourceDoesNotExistException::class);
188  $this->subject->retrieveFileOrFolderObject('EXT:core/Resources/Private/Templates/PageRenderer.html');
189  }
190 }
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceFactoryTest\$subject
‪ResourceFactory $subject
Definition: ResourceFactoryTest.php:37
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceFactoryTest\retrieveFileOrFolderObjectReturnsFileIfPathIsGiven
‪retrieveFileOrFolderObjectReturnsFileIfPathIsGiven()
Definition: ResourceFactoryTest.php:108
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceFactoryTest\createFolderCreatesObjectWithCorrectArguments
‪createFolderCreatesObjectWithCorrectArguments()
Definition: ResourceFactoryTest.php:59
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static getPublicPath()
Definition: Environment.php:187
‪TYPO3\CMS\Core\Tests\Unit\Resource
Definition: AbstractFileTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceFactoryTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: ResourceFactoryTest.php:31
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceFactoryTest\retrieveFileOrFolderObjectThrowsExceptionFromPrivateExtensionResourceWhenExtensionIsNotPublic
‪retrieveFileOrFolderObjectThrowsExceptionFromPrivateExtensionResourceWhenExtensionIsNotPublic()
Definition: ResourceFactoryTest.php:172
‪TYPO3\CMS\Core\Core\Environment\getCurrentScript
‪static getCurrentScript()
Definition: Environment.php:220
‪TYPO3\CMS\Core\Utility\GeneralUtility\mkdir_deep
‪static mkdir_deep(string $directory)
Definition: GeneralUtility.php:1652
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceFactoryTest\retrieveFileOrFolderObjectCallsGetFolderObjectFromCombinedIdentifierWithRelativePath
‪retrieveFileOrFolderObjectCallsGetFolderObjectFromCombinedIdentifierWithRelativePath()
Definition: ResourceFactoryTest.php:74
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceFactoryTest\retrieveFileOrFolderObjectCallsGetFolderObjectFromCombinedIdentifierWithAbsolutePath
‪retrieveFileOrFolderObjectCallsGetFolderObjectFromCombinedIdentifierWithAbsolutePath()
Definition: ResourceFactoryTest.php:91
‪TYPO3\CMS\Core\Core\Environment\getVarPath
‪static getVarPath()
Definition: Environment.php:197
‪TYPO3\CMS\Core\Core\Environment\getConfigPath
‪static getConfigPath()
Definition: Environment.php:212
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceFactoryTest
Definition: ResourceFactoryTest.php:30
‪TYPO3\CMS\Core\Utility\GeneralUtility\writeFileToTypo3tempDir
‪static string null writeFileToTypo3tempDir(string $filepath, string $content)
Definition: GeneralUtility.php:1559
‪TYPO3\CMS\Core\Core\Environment\getProjectPath
‪static string getProjectPath()
Definition: Environment.php:160
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:42
‪TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException
Definition: ResourceDoesNotExistException.php:23
‪$name
‪$name
Definition: phpIntegrityChecker.php:235
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceFactoryTest\retrieveFileOrFolderObjectReturnsFileFromPublicFolderWhenProjectRootIsNotPublic
‪retrieveFileOrFolderObjectReturnsFileFromPublicFolderWhenProjectRootIsNotPublic()
Definition: ResourceFactoryTest.php:122
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceFactoryTest\setUp
‪setUp()
Definition: ResourceFactoryTest.php:41
‪TYPO3\CMS\Core\Core\Environment\initialize
‪static initialize(ApplicationContext $context, bool $cli, bool $composerMode, string $projectPath, string $publicPath, string $varPath, string $configPath, string $currentScript, string $os)
Definition: Environment.php:100
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceFactoryTest\tearDown
‪tearDown()
Definition: ResourceFactoryTest.php:50
‪TYPO3\CMS\Core\Resource\ResourceStorage
Definition: ResourceStorage.php:129
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceFactoryTest\$filesCreated
‪array $filesCreated
Definition: ResourceFactoryTest.php:39
‪TYPO3\CMS\Core\Resource\ResourceFactory\retrieveFileOrFolderObject
‪ProcessedFile File Folder null retrieveFileOrFolderObject($input)
Definition: ResourceFactory.php:275
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:24
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceFactoryTest\retrieveFileOrFolderObjectReturnsFileFromPublicExtensionResourceWhenExtensionIsNotPublic
‪retrieveFileOrFolderObjectReturnsFileFromPublicExtensionResourceWhenExtensionIsNotPublic()
Definition: ResourceFactoryTest.php:150
‪TYPO3\CMS\Core\Core\Environment\getContext
‪static getContext()
Definition: Environment.php:128
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static getUniqueId(string $prefix='')
Definition: StringUtility.php:57
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceFactoryTest\$backupEnvironment
‪bool $backupEnvironment
Definition: ResourceFactoryTest.php:33
‪TYPO3\CMS\Core\Core\Environment\isWindows
‪static isWindows()
Definition: Environment.php:276