[TASK] Use NormalizedParams with simplified arguments
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Tests / Unit / Compatibility / LegacyDomainResolverTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Frontend\Tests\Unit\Compatibility;
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
18 use TYPO3\CMS\Core\Core\Environment;
19 use TYPO3\CMS\Core\Http\NormalizedParams;
20 use TYPO3\CMS\Core\Http\ServerRequestFactory;
21 use TYPO3\CMS\Frontend\Compatibility\LegacyDomainResolver;
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23
24 class LegacyDomainResolverTest extends UnitTestCase
25 {
26 /**
27 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface|LegacyDomainResolver
28 */
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
41 /**
42 * Tests concerning domainNameMatchesCurrentRequest
43 */
44
45 /**
46 * @return array
47 */
48 public function domainNameMatchesCurrentRequestDataProvider()
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
84 /**
85 * @param string $currentDomain
86 * @param string $domainRecord
87 * @param string $scriptName
88 * @param bool $expectedResult
89 * @test
90 * @dataProvider domainNameMatchesCurrentRequestDataProvider
91 */
92 public function domainNameMatchesCurrentRequest(string $currentDomain, string $domainRecord, string $scriptName, bool $expectedResult)
93 {
94 $_SERVER['HTTP_HOST'] = $currentDomain;
95 $_SERVER['SCRIPT_NAME'] = $scriptName;
96 $request = ServerRequestFactory::fromGlobals();
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 }