‪TYPO3CMS  ‪main
WebServerConfigurationFileServiceTest.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;
24 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
25 
26 final class ‪WebServerConfigurationFileServiceTest extends FunctionalTestCase
27 {
28  protected bool ‪$initializeDatabase = false;
29 
37  #[DataProvider('webServerConfigurationIsChangedDataProvider')]
38  #[Test]
40  string $webServer,
41  string $configurationFile,
42  bool $shouldBeChanged = false,
43  array $addedParts = [],
44  array $removedParts = []
45  ): void {
46  ‪$_SERVER['SERVER_SOFTWARE'] = $webServer;
47  $filename = ‪Environment::getPublicPath() . '/' . ($webServer === 'Apache' ? '.htaccess' : 'web.config');
48 
49  file_put_contents($filename, file_get_contents(__DIR__ . '/../Fixtures/' . $configurationFile));
50 
51  $changed = (new ‪WebServerConfigurationFileService())->addWebServerSpecificBackendRoutingRewriteRules();
52 
53  self::assertEquals($shouldBeChanged, $changed);
54 
55  if ($shouldBeChanged) {
56  $newFileContent = file_get_contents($filename);
57  // Check if updated file contains parts
58  foreach ($addedParts as $part) {
59  self::assertStringContainsString($part, $newFileContent);
60  }
61  // Check if updated file does not contain parts
62  foreach ($removedParts as $part) {
63  self::assertStringNotContainsString($part, $newFileContent);
64  }
65  }
66 
67  unlink($filename);
68  }
69 
70  public static function ‪webServerConfigurationIsChangedDataProvider(): \Generator
71  {
72  yield '.htaccess already updated - will not be changed' => [
73  'Apache',
74  '.htaccess_already_updated',
75  ];
76  yield 'outdated .htaccess - will be changed' => [
77  'Apache',
78  '.htaccess_outdated',
79  true,
80  [
81  '# Stop rewrite processing, if we are in any known directory',
82  'RewriteRule ^typo3/(.*)$ %{ENV:CWD}index.php [QSA,L]',
83  ],
84  [
85  '# Stop rewrite processing, if we are in any other known directory',
86  'RewriteRule ^typo3/(.*)$ %{ENV:CWD}typo3/index.php [QSA,L]',
87  ],
88  ];
89  yield 'web.config already updated - will not be changed' => [
90  'Microsoft-IIS',
91  'web.config_already_updated',
92  ];
93  yield 'outdated web.config - will be changed' => [
94  'Microsoft-IIS',
95  'web.config_outdated',
96  true,
97  [
98  '<action type="Rewrite" url="index.php" appendQueryString="true" />',
99  ],
100  [
101  '<action type="Rewrite" url="typo3/index.php" appendQueryString="true" />',
102  ],
103  ];
104  }
105 }
‪TYPO3\CMS\Install\Tests\Functional\Service\WebServerConfigurationFileServiceTest\webServerConfigurationIsChangedDataProvider
‪static webServerConfigurationIsChangedDataProvider()
Definition: WebServerConfigurationFileServiceTest.php:70
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static getPublicPath()
Definition: Environment.php:187
‪TYPO3\CMS\Install\Tests\Functional\Service\WebServerConfigurationFileServiceTest\$initializeDatabase
‪bool $initializeDatabase
Definition: WebServerConfigurationFileServiceTest.php:28
‪TYPO3\CMS\Install\Tests\Functional\Service\WebServerConfigurationFileServiceTest\addWebServerSpecificBackendRoutingRewriteRulesTest
‪addWebServerSpecificBackendRoutingRewriteRulesTest(string $webServer, string $configurationFile, bool $shouldBeChanged=false, array $addedParts=[], array $removedParts=[])
Definition: WebServerConfigurationFileServiceTest.php:39
‪TYPO3\CMS\Install\Service\WebServerConfigurationFileService
Definition: WebServerConfigurationFileService.php:28
‪$_SERVER
‪$_SERVER['TYPO3_DEPRECATED_ENTRYPOINT']
Definition: legacy-backend.php:20
‪TYPO3\CMS\Install\Tests\Functional\Service\WebServerConfigurationFileServiceTest
Definition: WebServerConfigurationFileServiceTest.php:27
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Install\Tests\Functional\Service
Definition: EnableFileServiceTest.php:18