TYPO3 CMS  TYPO3_7-6
TypoScriptFrontendControllerTest.php
Go to the documentation of this file.
1 <?php
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 
22 
27 {
31  protected $subject;
32 
33  protected function setUp()
34  {
36  $this->subject = $this->getAccessibleMock(TypoScriptFrontendController::class, ['dummy'], [], '', false);
37  $this->subject->TYPO3_CONF_VARS = $GLOBALS['TYPO3_CONF_VARS'];
38  $this->subject->TYPO3_CONF_VARS['SYS']['encryptionKey'] = '170928423746123078941623042360abceb12341234231';
39 
40  $pageRepository = $this->getMock(PageRepository::class);
41  $this->subject->sys_page = $pageRepository;
42  }
43 
52  {
53  $GLOBALS['TSFE'] = $this->setupTsfeMockForHeaderFooterReplacementCheck();
54  $GLOBALS['TSFE']->INTincScript();
55  $this->assertContains('headerData', $GLOBALS['TSFE']->content);
56  $this->assertContains('footerData', $GLOBALS['TSFE']->content);
57  }
58 
62  public function INTincScript_processCallback()
63  {
64  $GLOBALS['TSFE']->additionalHeaderData[] = 'headerData';
65  $GLOBALS['TSFE']->additionalFooterData[] = 'footerData';
66  }
67 
74  protected function setupTsfeMockForHeaderFooterReplacementCheck()
75  {
77  $tsfe = $this->getMock(TypoScriptFrontendController::class, [
78  'INTincScript_process',
79  'INTincScript_includeLibs',
80  'INTincScript_loadJSCode',
81  'setAbsRefPrefix',
82  'regeneratePageTitle'
83  ], [], '', false);
84  $tsfe->expects($this->exactly(2))->method('INTincScript_process')->will($this->returnCallback([$this, 'INTincScript_processCallback']));
85  $tsfe->content = file_get_contents(__DIR__ . '/Fixtures/renderedPage.html');
86  $config = [
87  'INTincScript_ext' => [
88  'divKey' => '679b52796e75d474ccbbed486b6837ab',
89  ],
90  'INTincScript' => [
91  'INT_SCRIPT.679b52796e75d474ccbbed486b6837ab' => [],
92  ]
93  ];
94  $tsfe->config = $config;
95  $GLOBALS['TT'] = new \TYPO3\CMS\Core\TimeTracker\NullTimeTracker();
96 
97  return $tsfe;
98  }
99 
108  {
109  $string = $this->getUniqueId();
110  $this->assertEquals($string, $this->subject->sL($string));
111  }
112 
121  {
122  return [
123  'typo3.org' => [
124  'typo3.org',
125  ],
126  'foo.bar' => [
127  'foo.bar',
128  ],
129  'example.com' => [
130  'example.com',
131  ],
132  ];
133  }
134 
140  public function getSysDomainCacheReturnsCurrentDomainRecord($currentDomain)
141  {
142  $_SERVER['HTTP_HOST'] = $currentDomain;
143  $domainRecords = [
144  'typo3.org' => [
145  'uid' => '1',
146  'pid' => '1',
147  'domainName' => 'typo3.org',
148  'forced' => 0,
149  ],
150  'foo.bar' => [
151  'uid' => '2',
152  'pid' => '1',
153  'domainName' => 'foo.bar',
154  'forced' => 0,
155  ],
156  'example.com' => [
157  'uid' => '3',
158  'pid' => '1',
159  'domainName' => 'example.com',
160  'forced' => 0,
161  ],
162  ];
163  $GLOBALS['TYPO3_DB'] = $this->getMock(DatabaseConnection::class, ['exec_SELECTgetRows']);
164  $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetRows')->willReturn($domainRecords);
165  GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_runtime')->flush();
166  $expectedResult = [
167  $domainRecords[$currentDomain]['pid'] => $domainRecords[$currentDomain],
168  ];
169  $this->assertEquals($expectedResult, $this->subject->_call('getSysDomainCache'));
170  }
171 
177  public function getSysDomainCacheReturnsForcedDomainRecord($currentDomain)
178  {
179  $_SERVER['HTTP_HOST'] = $currentDomain;
180  $domainRecords = [
181  'typo3.org' => [
182  'uid' => '1',
183  'pid' => '1',
184  'domainName' => 'typo3.org',
185  'forced' => 0,
186  ],
187  'foo.bar' => [
188  'uid' => '2',
189  'pid' => '1',
190  'domainName' => 'foo.bar',
191  'forced' => 1,
192  ],
193  'example.com' => [
194  'uid' => '3',
195  'pid' => '1',
196  'domainName' => 'example.com',
197  'forced' => 0,
198  ],
199  ];
200  $GLOBALS['TYPO3_DB'] = $this->getMock(DatabaseConnection::class, ['exec_SELECTgetRows']);
201  $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetRows')->willReturn($domainRecords);
202  GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_runtime')->flush();
203  $expectedResult = [
204  $domainRecords[$currentDomain]['pid'] => $domainRecords['foo.bar'],
205  ];
206  $this->assertEquals($expectedResult, $this->subject->_call('getSysDomainCache'));
207  }
208 
217  {
218  return [
219  'same domains' => [
220  'typo3.org',
221  'typo3.org',
222  '/index.php',
223  true,
224  ],
225  'same domains with subdomain' => [
226  'www.typo3.org',
227  'www.typo3.org',
228  '/index.php',
229  true,
230  ],
231  'different domains' => [
232  'foo.bar',
233  'typo3.org',
234  '/index.php',
235  false,
236  ],
237  'domain record with script name' => [
238  'typo3.org',
239  'typo3.org/foo/bar',
240  '/foo/bar/index.php',
241  true,
242  ],
243  'domain record with wrong script name' => [
244  'typo3.org',
245  'typo3.org/foo/bar',
246  '/bar/foo/index.php',
247  false,
248  ],
249  ];
250  }
251 
260  public function domainNameMatchesCurrentRequest($currentDomain, $domainRecord, $scriptName, $expectedResult)
261  {
262  $_SERVER['HTTP_HOST'] = $currentDomain;
263  $_SERVER['SCRIPT_NAME'] = $scriptName;
264  $this->assertEquals($expectedResult, $this->subject->domainNameMatchesCurrentRequest($domainRecord));
265  }
266 
271  {
272  return [
273  'without base url' => [
274  '',
275  'fileadmin/user_uploads/image.jpg',
276  'fileadmin/user_uploads/image.jpg'
277  ],
278  'with base url' => [
279  'http://www.google.com/',
280  'fileadmin/user_uploads/image.jpg',
281  'http://www.google.com/fileadmin/user_uploads/image.jpg'
282  ],
283  'without base url but with url prepended with a forward slash' => [
284  '',
285  '/fileadmin/user_uploads/image.jpg',
286  '/fileadmin/user_uploads/image.jpg',
287  ],
288  'with base url but with url prepended with a forward slash' => [
289  'http://www.google.com/',
290  '/fileadmin/user_uploads/image.jpg',
291  '/fileadmin/user_uploads/image.jpg',
292  ],
293  ];
294  }
295 
303  public function baseUrlWrapHandlesDifferentUrls($baseUrl, $url, $expected)
304  {
305  $this->subject->baseUrl = $baseUrl;
306  $this->assertSame($expected, $this->subject->baseUrlWrap($url));
307  }
308 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
domainNameMatchesCurrentRequest($currentDomain, $domainRecord, $scriptName, $expectedResult)