‪TYPO3CMS  ‪main
PathUtilityPublicPathsTest.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\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
27 final class ‪PathUtilityPublicPathsTest extends UnitTestCase
28 {
29  protected bool ‪$backupEnvironment = true;
30 
31  protected array ‪$serverBackup;
32 
33  protected function ‪setUp(): void
34  {
35  $this->serverBackup = ‪$_SERVER;
36  parent::setUp();
37  }
38 
39  protected function ‪tearDown(): void
40  {
42  parent::tearDown();
43  }
44 
48  protected static function ‪simulateWebRequest(string $publicDir, string $subDirectory = '/'): void
49  {
50  ‪$_SERVER['HTTP_HOST'] = 'localhost';
51  ‪$_SERVER['SCRIPT_NAME'] = $subDirectory . 'index.php';
52 
55  false,
56  true,
58  $publicDir,
61  $publicDir . '/index.php',
62  ‪Environment::isWindows() ? 'WINDOWS' : 'UNIX'
63  );
64  }
65 
66  protected static function ‪simulateTraditionalWebRequest(): void
67  {
69  }
70 
71  protected static function ‪simulateTraditionalWebRequestInSubDirectory(string $subDirectory = '/subDir/'): void
72  {
74  }
75 
77  {
78  return [
79  'private assets are resolved to absolute url' => [
80  'EXT:core/Resources/Private/Font/nimbus.ttf',
81  '/typo3/sysext/core/Resources/Private/Font/nimbus.ttf',
83  ],
84  'private assets are resolved to absolute url with sub directory prefixed' => [
85  'EXT:core/Resources/Private/Font/nimbus.ttf',
86  '/cms/typo3/sysext/core/Resources/Private/Font/nimbus.ttf',
88  ],
89  ];
90  }
91 
95  #[DataProvider('getPublicResourceWebPathResolvesUrlsCorrectlyDataProvider')]
96  #[Test]
97  public function ‪getPublicResourceWebPathResolvesUrlsCorrectly(string $pathReference, string $expectedUrl, callable $setup): void
98  {
99  $setup();
100  self::assertSame(
101  $expectedUrl,
103  );
104  }
105 }
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:27
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\PathUtilityPublicPathsTest\simulateWebRequest
‪static simulateWebRequest(string $publicDir, string $subDirectory='/')
Definition: PathUtilityPublicPathsTest.php:48
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\PathUtilityPublicPathsTest\$serverBackup
‪array $serverBackup
Definition: PathUtilityPublicPathsTest.php:31
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\PathUtilityPublicPathsTest\$backupEnvironment
‪bool $backupEnvironment
Definition: PathUtilityPublicPathsTest.php:29
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static getPublicPath()
Definition: Environment.php:187
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\PathUtilityPublicPathsTest\getPublicResourceWebPathResolvesUrlsCorrectlyDataProvider
‪static getPublicResourceWebPathResolvesUrlsCorrectlyDataProvider()
Definition: PathUtilityPublicPathsTest.php:76
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\PathUtilityPublicPathsTest\setUp
‪setUp()
Definition: PathUtilityPublicPathsTest.php:33
‪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\UnitDeprecated\Utility\PathUtilityPublicPathsTest\simulateTraditionalWebRequest
‪static simulateTraditionalWebRequest()
Definition: PathUtilityPublicPathsTest.php:66
‪TYPO3\CMS\Core\Core\Environment\getProjectPath
‪static string getProjectPath()
Definition: Environment.php:160
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\PathUtilityPublicPathsTest\tearDown
‪tearDown()
Definition: PathUtilityPublicPathsTest.php:39
‪TYPO3\CMS\Core\Utility\PathUtility\getPublicResourceWebPath
‪static getPublicResourceWebPath(string $resourcePath, bool $prefixWithSitePath=true)
Definition: PathUtility.php:97
‪TYPO3\CMS\Core\Resource\Exception\InvalidFileException
Definition: InvalidFileException.php:23
‪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\UnitDeprecated\Utility
Definition: GeneralUtilityTest.php:18
‪$_SERVER
‪$_SERVER['TYPO3_DEPRECATED_ENTRYPOINT']
Definition: legacy-backend.php:20
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\PathUtilityPublicPathsTest\simulateTraditionalWebRequestInSubDirectory
‪static simulateTraditionalWebRequestInSubDirectory(string $subDirectory='/subDir/')
Definition: PathUtilityPublicPathsTest.php:71
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\PathUtilityPublicPathsTest
Definition: PathUtilityPublicPathsTest.php:28
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\PathUtilityPublicPathsTest\getPublicResourceWebPathResolvesUrlsCorrectly
‪getPublicResourceWebPathResolvesUrlsCorrectly(string $pathReference, string $expectedUrl, callable $setup)
Definition: PathUtilityPublicPathsTest.php:97
‪TYPO3\CMS\Core\Core\Environment\getContext
‪static getContext()
Definition: Environment.php:128
‪TYPO3\CMS\Core\Core\Environment\isWindows
‪static isWindows()
Definition: Environment.php:276