‪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 
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
28 final class ‪ResourceFactoryTest extends UnitTestCase
29 {
30  protected bool ‪$resetSingletonInstances = true;
31 
32  protected bool ‪$backupEnvironment = true;
33 
37  protected ‪$subject;
38 
39  protected array ‪$filesCreated = [];
40 
41  protected function ‪setUp(): void
42  {
43  parent::setUp();
44  $this->subject = $this->getAccessibleMock(ResourceFactory::class, null, [], '', false);
45  }
46 
50  protected function ‪tearDown(): void
51  {
52  foreach ($this->filesCreated as $file) {
53  unlink($file);
54  }
55  parent::tearDown();
56  }
57 
62  {
63  $mockedMount = $this->createMock(ResourceStorage::class);
64  $path = ‪StringUtility::getUniqueId('path_');
65  $name = ‪StringUtility::getUniqueId('name_');
66  $folderObject = $this->subject->createFolderObject($mockedMount, $path, $name);
67  self::assertSame($mockedMount, $folderObject->getStorage());
68  self::assertEquals($path, $folderObject->getIdentifier());
69  self::assertEquals($name, $folderObject->getName());
70  }
71 
72  /***********************************
73  * File Handling
74  ***********************************/
75 
80  {
81  ‪$subject = $this->getAccessibleMock(
82  ResourceFactory::class,
83  ['getFolderObjectFromCombinedIdentifier'],
84  [],
85  '',
86  false
87  );
89  ->expects(self::once())
90  ->method('getFolderObjectFromCombinedIdentifier')
91  ->with('typo3');
93  }
94 
99  {
100  ‪$subject = $this->getAccessibleMock(
101  ResourceFactory::class,
102  ['getFolderObjectFromCombinedIdentifier'],
103  [],
104  '',
105  false
106  );
108  ->expects(self::once())
109  ->method('getFolderObjectFromCombinedIdentifier')
110  ->with('typo3');
112  }
113 
118  {
119  $this->subject = $this->getAccessibleMock(ResourceFactory::class, ['getFileObjectFromCombinedIdentifier'], [], '', false);
120  $filename = 'typo3temp/var/tests/4711.txt';
121  $this->subject->expects(self::once())
122  ->method('getFileObjectFromCombinedIdentifier')
123  ->with($filename);
124  // Create and prepare test file
126  $this->filesCreated[] = ‪Environment::getPublicPath() . '/' . $filename;
127  $this->subject->retrieveFileOrFolderObject($filename);
128  }
129 
134  {
137  true,
138  true,
140  ‪Environment::getPublicPath() . '/typo3temp/public',
144  ‪Environment::isWindows() ? 'WINDOWS' : 'UNIX'
145  );
146 
148 
149  $this->subject = $this->getAccessibleMock(ResourceFactory::class, ['getFileObjectFromCombinedIdentifier'], [], '', false);
150  $filename = 'typo3temp/var/tests/4711.txt';
151  $this->subject->expects(self::once())
152  ->method('getFileObjectFromCombinedIdentifier')
153  ->with($filename);
154  // Create and prepare test file
156  $this->filesCreated[] = ‪Environment::getPublicPath() . '/' . $filename;
157  $this->subject->retrieveFileOrFolderObject($filename);
158  }
159 
164  {
167  true,
168  true,
170  ‪Environment::getPublicPath() . '/typo3temp/public',
174  ‪Environment::isWindows() ? 'WINDOWS' : 'UNIX'
175  );
176  $this->subject = $this->getAccessibleMock(ResourceFactory::class, ['getFileObjectFromCombinedIdentifier'], [], '', false);
177  $this->subject->expects(self::once())
178  ->method('getFileObjectFromCombinedIdentifier')
179  ->with('_assets/d25de869aebcd01495d2fe67ad5b0e25/Icons/Extension.svg');
180  // Create and prepare test file
181  $this->subject->retrieveFileOrFolderObject('EXT:core/Resources/Public/Icons/Extension.svg');
182  }
183 
188  {
191  true,
192  true,
194  ‪Environment::getPublicPath() . '/typo3temp/public',
198  ‪Environment::isWindows() ? 'WINDOWS' : 'UNIX'
199  );
200  $this->subject = $this->getAccessibleMock(ResourceFactory::class, ['getFileObjectFromCombinedIdentifier'], [], '', false);
201  $this->expectException(ResourceDoesNotExistException::class);
202  $this->subject->retrieveFileOrFolderObject('EXT:core/Resources/Private/Templates/PageRenderer.html');
203  }
204 }
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceFactoryTest\$subject
‪ResourceFactory $subject
Definition: ResourceFactoryTest.php:36
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceFactoryTest\retrieveFileOrFolderObjectReturnsFileIfPathIsGiven
‪retrieveFileOrFolderObjectReturnsFileIfPathIsGiven()
Definition: ResourceFactoryTest.php:116
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceFactoryTest\createFolderCreatesObjectWithCorrectArguments
‪createFolderCreatesObjectWithCorrectArguments()
Definition: ResourceFactoryTest.php:60
‪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:30
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceFactoryTest\retrieveFileOrFolderObjectThrowsExceptionFromPrivateExtensionResourceWhenExtensionIsNotPublic
‪retrieveFileOrFolderObjectThrowsExceptionFromPrivateExtensionResourceWhenExtensionIsNotPublic()
Definition: ResourceFactoryTest.php:186
‪TYPO3\CMS\Core\Core\Environment\getCurrentScript
‪static getCurrentScript()
Definition: Environment.php:220
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceFactoryTest\retrieveFileOrFolderObjectCallsGetFolderObjectFromCombinedIdentifierWithRelativePath
‪retrieveFileOrFolderObjectCallsGetFolderObjectFromCombinedIdentifierWithRelativePath()
Definition: ResourceFactoryTest.php:78
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceFactoryTest\retrieveFileOrFolderObjectCallsGetFolderObjectFromCombinedIdentifierWithAbsolutePath
‪retrieveFileOrFolderObjectCallsGetFolderObjectFromCombinedIdentifierWithAbsolutePath()
Definition: ResourceFactoryTest.php:97
‪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:29
‪TYPO3\CMS\Core\Core\Environment\getProjectPath
‪static string getProjectPath()
Definition: Environment.php:160
‪TYPO3\CMS\Core\Utility\GeneralUtility\mkdir_deep
‪static mkdir_deep($directory)
Definition: GeneralUtility.php:1638
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:41
‪TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException
Definition: ResourceDoesNotExistException.php:24
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceFactoryTest\retrieveFileOrFolderObjectReturnsFileFromPublicFolderWhenProjectRootIsNotPublic
‪retrieveFileOrFolderObjectReturnsFileFromPublicFolderWhenProjectRootIsNotPublic()
Definition: ResourceFactoryTest.php:132
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceFactoryTest\setUp
‪setUp()
Definition: ResourceFactoryTest.php:40
‪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:49
‪TYPO3\CMS\Core\Resource\ResourceStorage
Definition: ResourceStorage.php:127
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceFactoryTest\$filesCreated
‪array $filesCreated
Definition: ResourceFactoryTest.php:38
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:24
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceFactoryTest\retrieveFileOrFolderObjectReturnsFileFromPublicExtensionResourceWhenExtensionIsNotPublic
‪retrieveFileOrFolderObjectReturnsFileFromPublicExtensionResourceWhenExtensionIsNotPublic()
Definition: ResourceFactoryTest.php:162
‪TYPO3\CMS\Core\Core\Environment\getContext
‪static getContext()
Definition: Environment.php:128
‪TYPO3\CMS\Core\Resource\ResourceFactory\retrieveFileOrFolderObject
‪File Folder null retrieveFileOrFolderObject($input)
Definition: ResourceFactory.php:274
‪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:32
‪TYPO3\CMS\Core\Utility\GeneralUtility\writeFileToTypo3tempDir
‪static string null writeFileToTypo3tempDir($filepath, $content)
Definition: GeneralUtility.php:1544
‪TYPO3\CMS\Core\Core\Environment\isWindows
‪static isWindows()
Definition: Environment.php:276