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