‪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 
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
25 class ‪PathUtilityPublicPathsTest extends UnitTestCase
26 {
27  protected bool ‪$backupEnvironment = true;
28 
29  protected array ‪$serverBackup;
30 
31  protected function ‪setUp(): void
32  {
33  $this->serverBackup = $_SERVER;
34  parent::setUp();
35  }
36 
37  protected function ‪tearDown(): void
38  {
39  $_SERVER = ‪$this->serverBackup;
40  parent::tearDown();
41  }
42 
46  protected static function ‪simulateWebRequest(string $publicDir, string $subDirectory = '/'): void
47  {
48  $_SERVER['HTTP_HOST'] = 'localhost';
49  $_SERVER['SCRIPT_NAME'] = $subDirectory . 'index.php';
50 
53  false,
54  true,
56  $publicDir,
59  $publicDir . '/index.php',
60  ‪Environment::isWindows() ? 'WINDOWS' : 'UNIX'
61  );
62  }
63 
64  protected static function ‪simulateTraditionalWebRequest(): void
65  {
67  }
68 
69  protected static function ‪simulateTraditionalWebRequestInSubDirectory(string $subDirectory = '/subDir/'): void
70  {
72  }
73 
75  {
76  return [
77  'private assets are resolved to absolute url' => [
78  'EXT:core/Resources/Private/Font/nimbus.ttf',
79  '/typo3/sysext/core/Resources/Private/Font/nimbus.ttf',
81  ],
82  'private assets are resolved to absolute url with sub directory prefixed' => [
83  'EXT:core/Resources/Private/Font/nimbus.ttf',
84  '/cms/typo3/sysext/core/Resources/Private/Font/nimbus.ttf',
86  ],
87  ];
88  }
89 
95  public function ‪getPublicResourceWebPathResolvesUrlsCorrectly(string $pathReference, string $expectedUrl, callable $setup): void
96  {
97  $setup();
98  self::assertSame(
99  $expectedUrl,
101  );
102  }
103 }
‪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:46
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\PathUtilityPublicPathsTest\$serverBackup
‪array $serverBackup
Definition: PathUtilityPublicPathsTest.php:29
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\PathUtilityPublicPathsTest\$backupEnvironment
‪bool $backupEnvironment
Definition: PathUtilityPublicPathsTest.php:27
‪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:74
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\PathUtilityPublicPathsTest\setUp
‪setUp()
Definition: PathUtilityPublicPathsTest.php:31
‪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:64
‪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:37
‪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:24
‪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
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\PathUtilityPublicPathsTest\simulateTraditionalWebRequestInSubDirectory
‪static simulateTraditionalWebRequestInSubDirectory(string $subDirectory='/subDir/')
Definition: PathUtilityPublicPathsTest.php:69
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\PathUtilityPublicPathsTest
Definition: PathUtilityPublicPathsTest.php:26
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\PathUtilityPublicPathsTest\getPublicResourceWebPathResolvesUrlsCorrectly
‪getPublicResourceWebPathResolvesUrlsCorrectly(string $pathReference, string $expectedUrl, callable $setup)
Definition: PathUtilityPublicPathsTest.php:95
‪TYPO3\CMS\Core\Core\Environment\getContext
‪static getContext()
Definition: Environment.php:128
‪TYPO3\CMS\Core\Core\Environment\isWindows
‪static isWindows()
Definition: Environment.php:287