[BUGFIX] Add missing namespace parts
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Tests / Unit / Controller / TypoScriptFrontendControllerTest.php
1 <?php
2 namespace TYPO3\CMS\Frontend\Tests\Unit\Controller;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
19 use TYPO3\CMS\Frontend\Page\PageRepository;
20
21 /**
22 * Testcase for TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
23 */
24 class TypoScriptFrontendControllerTest extends \TYPO3\Components\TestingFramework\Core\Unit\UnitTestCase
25 {
26 /**
27 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\Components\TestingFramework\Core\AccessibleObjectInterface|TypoScriptFrontendController
28 */
29 protected $subject;
30
31 protected function setUp()
32 {
33 GeneralUtility::flushInternalRuntimeCaches();
34 $this->subject = $this->getAccessibleMock(TypoScriptFrontendController::class, ['dummy'], [], '', false);
35 $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = '170928423746123078941623042360abceb12341234231';
36
37 $pageRepository = $this->getMockBuilder(PageRepository::class)->getMock();
38 $this->subject->sys_page = $pageRepository;
39 }
40
41 /**
42 * Tests concerning rendering content
43 */
44
45 /**
46 * @test
47 */
48 public function headerAndFooterMarkersAreReplacedDuringIntProcessing()
49 {
50 $GLOBALS['TSFE'] = $this->setupTsfeMockForHeaderFooterReplacementCheck();
51 $GLOBALS['TSFE']->INTincScript();
52 $this->assertContains('headerData', $GLOBALS['TSFE']->content);
53 $this->assertContains('footerData', $GLOBALS['TSFE']->content);
54 }
55
56 /**
57 * This is the callback that mimics a USER_INT extension
58 */
59 public function INTincScript_processCallback()
60 {
61 $GLOBALS['TSFE']->additionalHeaderData[] = 'headerData';
62 $GLOBALS['TSFE']->additionalFooterData[] = 'footerData';
63 }
64
65 /**
66 * Setup a \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController object only for testing the header and footer
67 * replacement during USER_INT rendering
68 *
69 * @return \PHPUnit_Framework_MockObject_MockObject|TypoScriptFrontendController
70 */
71 protected function setupTsfeMockForHeaderFooterReplacementCheck()
72 {
73 /** @var \PHPUnit_Framework_MockObject_MockObject|TypoScriptFrontendController $tsfe */
74 $tsfe = $this->getMockBuilder(TypoScriptFrontendController::class)
75 ->setMethods([
76 'INTincScript_process',
77 'INTincScript_loadJSCode',
78 'setAbsRefPrefix',
79 'regeneratePageTitle'
80 ])->disableOriginalConstructor()
81 ->getMock();
82 $tsfe->expects($this->exactly(2))->method('INTincScript_process')->will($this->returnCallback([$this, 'INTincScript_processCallback']));
83 $tsfe->content = file_get_contents(__DIR__ . '/Fixtures/renderedPage.html');
84 $config = [
85 'INTincScript_ext' => [
86 'divKey' => '679b52796e75d474ccbbed486b6837ab',
87 ],
88 'INTincScript' => [
89 'INT_SCRIPT.679b52796e75d474ccbbed486b6837ab' => [],
90 ]
91 ];
92 $tsfe->config = $config;
93
94 return $tsfe;
95 }
96
97 /**
98 * Tests concerning sL
99 */
100
101 /**
102 * @test
103 */
104 public function localizationReturnsUnchangedStringIfNotLocallangLabel()
105 {
106 $string = $this->getUniqueId();
107 $this->assertEquals($string, $this->subject->sL($string));
108 }
109
110 /**
111 * Tests concerning getSysDomainCache
112 */
113
114 /**
115 * @return array
116 */
117 public function getSysDomainCacheDataProvider()
118 {
119 return [
120 'typo3.org' => [
121 'typo3.org',
122 ],
123 'foo.bar' => [
124 'foo.bar',
125 ],
126 'example.com' => [
127 'example.com',
128 ],
129 ];
130 }
131
132 /**
133 * Tests concerning domainNameMatchesCurrentRequest
134 */
135
136 /**
137 * @return array
138 */
139 public function domainNameMatchesCurrentRequestDataProvider()
140 {
141 return [
142 'same domains' => [
143 'typo3.org',
144 'typo3.org',
145 '/index.php',
146 true,
147 ],
148 'same domains with subdomain' => [
149 'www.typo3.org',
150 'www.typo3.org',
151 '/index.php',
152 true,
153 ],
154 'different domains' => [
155 'foo.bar',
156 'typo3.org',
157 '/index.php',
158 false,
159 ],
160 'domain record with script name' => [
161 'typo3.org',
162 'typo3.org/foo/bar',
163 '/foo/bar/index.php',
164 true,
165 ],
166 'domain record with wrong script name' => [
167 'typo3.org',
168 'typo3.org/foo/bar',
169 '/bar/foo/index.php',
170 false,
171 ],
172 ];
173 }
174
175 /**
176 * @param string $currentDomain
177 * @param string $domainRecord
178 * @param string $scriptName
179 * @param bool $expectedResult
180 * @test
181 * @dataProvider domainNameMatchesCurrentRequestDataProvider
182 */
183 public function domainNameMatchesCurrentRequest($currentDomain, $domainRecord, $scriptName, $expectedResult)
184 {
185 $_SERVER['HTTP_HOST'] = $currentDomain;
186 $_SERVER['SCRIPT_NAME'] = $scriptName;
187 $this->assertEquals($expectedResult, $this->subject->domainNameMatchesCurrentRequest($domainRecord));
188 }
189
190 /**
191 * @return array
192 */
193 public function baseUrlWrapHandlesDifferentUrlsDataProvider()
194 {
195 return [
196 'without base url' => [
197 '',
198 'fileadmin/user_uploads/image.jpg',
199 'fileadmin/user_uploads/image.jpg'
200 ],
201 'with base url' => [
202 'http://www.google.com/',
203 'fileadmin/user_uploads/image.jpg',
204 'http://www.google.com/fileadmin/user_uploads/image.jpg'
205 ],
206 'without base url but with url prepended with a forward slash' => [
207 '',
208 '/fileadmin/user_uploads/image.jpg',
209 '/fileadmin/user_uploads/image.jpg',
210 ],
211 'with base url but with url prepended with a forward slash' => [
212 'http://www.google.com/',
213 '/fileadmin/user_uploads/image.jpg',
214 '/fileadmin/user_uploads/image.jpg',
215 ],
216 ];
217 }
218
219 /**
220 * @dataProvider baseUrlWrapHandlesDifferentUrlsDataProvider
221 * @test
222 * @param string $baseUrl
223 * @param string $url
224 * @param string $expected
225 */
226 public function baseUrlWrapHandlesDifferentUrls($baseUrl, $url, $expected)
227 {
228 $this->subject->baseUrl = $baseUrl;
229 $this->assertSame($expected, $this->subject->baseUrlWrap($url));
230 }
231 }