‪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 
22 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
23 
24 final class ‪WebServerConfigurationFileServiceTest extends FunctionalTestCase
25 {
26  protected bool ‪$initializeDatabase = false;
27 
39  string $webServer,
40  string $configurationFile,
41  bool $shouldBeChanged = false,
42  array $addedParts = [],
43  array $removedParts = []
44  ): void {
45  $_SERVER['SERVER_SOFTWARE'] = $webServer;
46  $filename = ‪Environment::getPublicPath() . '/' . ($webServer === 'Apache' ? '.htaccess' : 'web.config');
47 
48  file_put_contents($filename, file_get_contents(__DIR__ . '/../Fixtures/' . $configurationFile));
49 
50  $changed = (new ‪WebServerConfigurationFileService())->addWebServerSpecificBackendRoutingRewriteRules();
51 
52  self::assertEquals($shouldBeChanged, $changed);
53 
54  if ($shouldBeChanged) {
55  $newFileContent = file_get_contents($filename);
56  // Check if updated file contains parts
57  foreach ($addedParts as $part) {
58  self::assertStringContainsString($part, $newFileContent);
59  }
60  // Check if updated file does not contain parts
61  foreach ($removedParts as $part) {
62  self::assertStringNotContainsString($part, $newFileContent);
63  }
64  }
65 
66  unlink($filename);
67  }
68 
69  public static function ‪webServerConfigurationIsChangedDataProvider(): \Generator
70  {
71  yield '.htaccess with custom configuration - will not be changed' => [
72  'Apache',
73  '.htaccess_custom_config',
74  ];
75  yield '.htaccess with wrong order - will not be changed' => [
76  'Apache',
77  '.htaccess_wrong_order',
78  ];
79  yield '.htaccess already updated - will not be changed' => [
80  'Apache',
81  '.htaccess_already_updated',
82  ];
83  yield '.htaccess without custom configuration - will be changed' => [
84  'Apache',
85  '.htaccess_valid',
86  true,
87  [
88  'TYPO3 automated migration',
89  '# If the file/symlink/directory does not exist but is below /typo3/, redirect to the TYPO3 Backend entry point.',
90  'RewriteRule ^typo3/(.*)$ %{ENV:CWD}typo3/index.php [QSA,L]',
91  ],
92  [
93  'Stop rewrite processing, if we are in the typo3/ directory',
94  'RewriteRule ^(?:typo3/|',
95  ],
96  ];
97  yield 'web.config with custom configuration - will not be changed' => [
98  'Microsoft-IIS',
99  'web.config_custom_config',
100  ];
101  yield 'web.config with wrong order - will not be changed' => [
102  'Microsoft-IIS',
103  'web.config_wrong_order',
104  ];
105  yield 'web.config already updated - will not be changed' => [
106  'Microsoft-IIS',
107  'web.config_already_updated',
108  ];
109  yield 'web.config without custom configuration - will be changed' => [
110  'Microsoft-IIS',
111  'web.config_valid',
112  true,
113  [
114  'TYPO3 automated migration',
115  'TYPO3 - If the file/directory does not exist but is below /typo3/, redirect to the TYPO3 Backend entry point.',
116  '<action type="Rewrite" url="typo3/index.php" appendQueryString="true" />',
117  ],
118  [
119  '<match url="^/(typo3|',
120  ],
121  ];
122  }
123 }
‪TYPO3\CMS\Install\Tests\Functional\Service\WebServerConfigurationFileServiceTest\webServerConfigurationIsChangedDataProvider
‪static webServerConfigurationIsChangedDataProvider()
Definition: WebServerConfigurationFileServiceTest.php:69
‪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:26
‪TYPO3\CMS\Install\Tests\Functional\Service\WebServerConfigurationFileServiceTest\addWebServerSpecificBackendRoutingRewriteRulesTest
‪addWebServerSpecificBackendRoutingRewriteRulesTest(string $webServer, string $configurationFile, bool $shouldBeChanged=false, array $addedParts=[], array $removedParts=[])
Definition: WebServerConfigurationFileServiceTest.php:38
‪TYPO3\CMS\Install\Service\WebServerConfigurationFileService
Definition: WebServerConfigurationFileService.php:28
‪TYPO3\CMS\Install\Tests\Functional\Service\WebServerConfigurationFileServiceTest
Definition: WebServerConfigurationFileServiceTest.php:25
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Install\Tests\Functional\Service
Definition: EnableFileServiceTest.php:18