[TASK] Centralize sys_domain resolving
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Tests / UnitDeprecated / Controller / TypoScriptFrontendControllerTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Frontend\Tests\UnitDeprecated\Controller;
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\Utility\GeneralUtility;
19 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
20 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
21
22 /**
23 * Test case
24 */
25 class TypoScriptFrontendControllerTest extends UnitTestCase
26 {
27 /**
28 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface|TypoScriptFrontendController
29 */
30 protected $subject;
31
32 protected function setUp()
33 {
34 parent::setUp();
35 GeneralUtility::flushInternalRuntimeCaches();
36 $this->subject = $this->getAccessibleMock(TypoScriptFrontendController::class, ['dummy'], [], '', false);
37 }
38
39 /**
40 * Tests concerning domainNameMatchesCurrentRequest
41 */
42
43 /**
44 * @return array
45 */
46 public function domainNameMatchesCurrentRequestDataProvider()
47 {
48 return [
49 'same domains' => [
50 'typo3.org',
51 'typo3.org',
52 '/index.php',
53 true,
54 ],
55 'same domains with subdomain' => [
56 'www.typo3.org',
57 'www.typo3.org',
58 '/index.php',
59 true,
60 ],
61 'different domains' => [
62 'foo.bar',
63 'typo3.org',
64 '/index.php',
65 false,
66 ],
67 'domain record with script name' => [
68 'typo3.org',
69 'typo3.org/foo/bar',
70 '/foo/bar/index.php',
71 true,
72 ],
73 'domain record with wrong script name' => [
74 'typo3.org',
75 'typo3.org/foo/bar',
76 '/bar/foo/index.php',
77 false,
78 ],
79 ];
80 }
81
82 /**
83 * @param string $currentDomain
84 * @param string $domainRecord
85 * @param string $scriptName
86 * @param bool $expectedResult
87 * @test
88 * @dataProvider domainNameMatchesCurrentRequestDataProvider
89 */
90 public function domainNameMatchesCurrentRequest($currentDomain, $domainRecord, $scriptName, $expectedResult)
91 {
92 $_SERVER['HTTP_HOST'] = $currentDomain;
93 $_SERVER['SCRIPT_NAME'] = $scriptName;
94 $this->assertEquals($expectedResult, $this->subject->domainNameMatchesCurrentRequest($domainRecord));
95 }
96 }