‪TYPO3CMS  9.5
LegacyDomainResolverTest.php
Go to the documentation of this file.
1 <?php
2 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 
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
24 class ‪LegacyDomainResolverTest extends UnitTestCase
25 {
29  protected ‪$subject;
30 
31  protected ‪$resetSingletonInstances = true;
32 
33  protected ‪$backupEnvironment = true;
34 
35  protected function ‪setUp()
36  {
37  parent::setUp();
38  $this->subject = $this->getAccessibleMock(LegacyDomainResolver::class, ['dummy'], [], '', false);
39  }
40 
49  {
50  return [
51  'same domains' => [
52  'typo3.org',
53  'typo3.org',
54  '/index.php',
55  true,
56  ],
57  'same domains with subdomain' => [
58  'www.typo3.org',
59  'www.typo3.org',
60  '/index.php',
61  true,
62  ],
63  'different domains' => [
64  'foo.bar',
65  'typo3.org',
66  '/index.php',
67  false,
68  ],
69  'domain record with script name' => [
70  'typo3.org',
71  'typo3.org/foo/bar',
72  '/foo/bar/index.php',
73  true,
74  ],
75  'domain record with wrong script name' => [
76  'typo3.org',
77  'typo3.org/foo/bar',
78  '/bar/foo/index.php',
79  false,
80  ],
81  ];
82  }
83 
92  public function ‪domainNameMatchesCurrentRequest(string $currentDomain, string $domainRecord, string $scriptName, bool $expectedResult)
93  {
94  $_SERVER['HTTP_HOST'] = $currentDomain;
95  $_SERVER['SCRIPT_NAME'] = $scriptName;
97  $normalizedParams = new NormalizedParams($_SERVER, [], ‪Environment::getCurrentScript(), ‪Environment::getPublicPath());
98  $request = $request->withAttribute('normalizedParams', $normalizedParams);
99  $this->assertEquals($expectedResult, $this->subject->_call('domainNameMatchesCurrentRequest', $domainRecord, $request));
100  }
101 }
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static string getPublicPath()
Definition: Environment.php:153
‪TYPO3\CMS\Core\Core\Environment\getCurrentScript
‪static string getCurrentScript()
Definition: Environment.php:193
‪TYPO3\CMS\Frontend\Tests\Unit\Compatibility
Definition: LegacyDomainResolverTest.php:3
‪TYPO3\CMS\Frontend\Compatibility\LegacyDomainResolver
Definition: LegacyDomainResolver.php:37
‪TYPO3\CMS\Core\Http\ServerRequestFactory
Definition: ServerRequestFactory.php:28
‪TYPO3\CMS\Frontend\Tests\Unit\Compatibility\LegacyDomainResolverTest\$resetSingletonInstances
‪$resetSingletonInstances
Definition: LegacyDomainResolverTest.php:30
‪TYPO3\CMS\Frontend\Tests\Unit\Compatibility\LegacyDomainResolverTest\domainNameMatchesCurrentRequest
‪domainNameMatchesCurrentRequest(string $currentDomain, string $domainRecord, string $scriptName, bool $expectedResult)
Definition: LegacyDomainResolverTest.php:91
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:39
‪TYPO3\CMS\Frontend\Tests\Unit\Compatibility\LegacyDomainResolverTest\domainNameMatchesCurrentRequestDataProvider
‪array domainNameMatchesCurrentRequestDataProvider()
Definition: LegacyDomainResolverTest.php:47
‪TYPO3\CMS\Frontend\Tests\Unit\Compatibility\LegacyDomainResolverTest\$subject
‪PHPUnit_Framework_MockObject_MockObject TYPO3 TestingFramework Core AccessibleObjectInterface LegacyDomainResolver $subject
Definition: LegacyDomainResolverTest.php:28
‪TYPO3\CMS\Frontend\Tests\Unit\Compatibility\LegacyDomainResolverTest
Definition: LegacyDomainResolverTest.php:25
‪TYPO3\CMS\Frontend\Tests\Unit\Compatibility\LegacyDomainResolverTest\$backupEnvironment
‪$backupEnvironment
Definition: LegacyDomainResolverTest.php:32
‪TYPO3\CMS\Core\Http\NormalizedParams
Definition: NormalizedParams.php:32
‪TYPO3\CMS\Core\Http\ServerRequestFactory\fromGlobals
‪static ServerRequest fromGlobals()
Definition: ServerRequestFactory.php:36
‪TYPO3\CMS\Frontend\Tests\Unit\Compatibility\LegacyDomainResolverTest\setUp
‪setUp()
Definition: LegacyDomainResolverTest.php:34