2 namespace TYPO3\CMS\Frontend\Tests\Unit\Controller
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Core\Cache\CacheManager
;
18 use TYPO3\CMS\Core\Database\DatabaseConnection
;
19 use TYPO3\CMS\Core\Utility\GeneralUtility
;
20 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
;
21 use TYPO3\CMS\Frontend\Page\PageRepository
;
24 * Testcase for TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
26 class TypoScriptFrontendControllerTest
extends \TYPO3\CMS\Core\Tests\UnitTestCase
29 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|TypoScriptFrontendController
33 protected function setUp()
35 GeneralUtility
::flushInternalRuntimeCaches();
36 $this->subject
= $this->getAccessibleMock(TypoScriptFrontendController
::class, array('dummy'), array(), '', false
);
37 $this->subject
->TYPO3_CONF_VARS
= $GLOBALS['TYPO3_CONF_VARS'];
38 $this->subject
->TYPO3_CONF_VARS
['SYS']['encryptionKey'] = '170928423746123078941623042360abceb12341234231';
40 $pageRepository = $this->getMock(PageRepository
::class);
41 $this->subject
->sys_page
= $pageRepository;
45 * Tests concerning rendering content
51 public function headerAndFooterMarkersAreReplacedDuringIntProcessing()
53 $GLOBALS['TSFE'] = $this->setupTsfeMockForHeaderFooterReplacementCheck();
54 $GLOBALS['TSFE']->INTincScript();
55 $this->assertContains('headerData', $GLOBALS['TSFE']->content
);
56 $this->assertContains('footerData', $GLOBALS['TSFE']->content
);
60 * This is the callback that mimics a USER_INT extension
62 public function INTincScript_processCallback()
64 $GLOBALS['TSFE']->additionalHeaderData
[] = 'headerData';
65 $GLOBALS['TSFE']->additionalFooterData
[] = 'footerData';
69 * Setup a \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController object only for testing the header and footer
70 * replacement during USER_INT rendering
72 * @return \PHPUnit_Framework_MockObject_MockObject|TypoScriptFrontendController
74 protected function setupTsfeMockForHeaderFooterReplacementCheck()
76 /** @var \PHPUnit_Framework_MockObject_MockObject|TypoScriptFrontendController $tsfe */
77 $tsfe = $this->getMock(TypoScriptFrontendController
::class, array(
78 'INTincScript_process',
79 'INTincScript_includeLibs',
80 'INTincScript_loadJSCode',
83 ), array(), '', false
);
84 $tsfe->expects($this->exactly(2))->method('INTincScript_process')->will($this->returnCallback(array($this, 'INTincScript_processCallback')));
85 $tsfe->content
= file_get_contents(__DIR__
. '/Fixtures/renderedPage.html');
87 'INTincScript_ext' => [
88 'divKey' => '679b52796e75d474ccbbed486b6837ab',
91 'INT_SCRIPT.679b52796e75d474ccbbed486b6837ab' => [],
94 $tsfe->config
= $config;
95 $GLOBALS['TT'] = new \TYPO3\CMS\Core\TimeTracker\
NullTimeTracker();
101 * Tests concerning sL
107 public function localizationReturnsUnchangedStringIfNotLocallangLabel()
109 $string = $this->getUniqueId();
110 $this->assertEquals($string, $this->subject
->sL($string));
114 * Tests concerning getSysDomainCache
120 public function getSysDomainCacheDataProvider()
123 'typo3.org' => array(
129 'example.com' => array(
136 * @param string $currentDomain
138 * @dataProvider getSysDomainCacheDataProvider
140 public function getSysDomainCacheReturnsCurrentDomainRecord($currentDomain)
142 $_SERVER['HTTP_HOST'] = $currentDomain;
143 $domainRecords = array(
144 'typo3.org' => array(
147 'domainName' => 'typo3.org',
153 'domainName' => 'foo.bar',
156 'example.com' => array(
159 'domainName' => 'example.com',
163 $GLOBALS['TYPO3_DB'] = $this->getMock(DatabaseConnection
::class, array('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 = array(
167 $domainRecords[$currentDomain]['pid'] => $domainRecords[$currentDomain],
169 $this->assertEquals($expectedResult, $this->subject
->_call('getSysDomainCache'));
173 * @param string $currentDomain
175 * @dataProvider getSysDomainCacheDataProvider
177 public function getSysDomainCacheReturnsForcedDomainRecord($currentDomain)
179 $_SERVER['HTTP_HOST'] = $currentDomain;
180 $domainRecords = array(
181 'typo3.org' => array(
184 'domainName' => 'typo3.org',
190 'domainName' => 'foo.bar',
193 'example.com' => array(
196 'domainName' => 'example.com',
200 $GLOBALS['TYPO3_DB'] = $this->getMock(DatabaseConnection
::class, array('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 = array(
204 $domainRecords[$currentDomain]['pid'] => $domainRecords['foo.bar'],
206 $this->assertEquals($expectedResult, $this->subject
->_call('getSysDomainCache'));
210 * Tests concerning domainNameMatchesCurrentRequest
216 public function domainNameMatchesCurrentRequestDataProvider()
219 'same domains' => array(
225 'same domains with subdomain' => array(
231 'different domains' => array(
237 'domain record with script name' => array(
240 '/foo/bar/index.php',
243 'domain record with wrong script name' => array(
246 '/bar/foo/index.php',
253 * @param string $currentDomain
254 * @param string $domainRecord
255 * @param string $scriptName
256 * @param bool $expectedResult
258 * @dataProvider domainNameMatchesCurrentRequestDataProvider
260 public function domainNameMatchesCurrentRequest($currentDomain, $domainRecord, $scriptName, $expectedResult)
262 $_SERVER['HTTP_HOST'] = $currentDomain;
263 $_SERVER['SCRIPT_NAME'] = $scriptName;
264 $this->assertEquals($expectedResult, $this->subject
->domainNameMatchesCurrentRequest($domainRecord));
270 public function baseUrlWrapHandlesDifferentUrlsDataProvider()
273 'without base url' => [
275 'fileadmin/user_uploads/image.jpg',
276 'fileadmin/user_uploads/image.jpg'
279 'http://www.google.com/',
280 'fileadmin/user_uploads/image.jpg',
281 'http://www.google.com/fileadmin/user_uploads/image.jpg'
283 'without base url but with url prepended with a forward slash' => [
285 '/fileadmin/user_uploads/image.jpg',
286 '/fileadmin/user_uploads/image.jpg',
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',
297 * @dataProvider baseUrlWrapHandlesDifferentUrlsDataProvider
299 * @param string $baseUrl
301 * @param string $expected
303 public function baseUrlWrapHandlesDifferentUrls($baseUrl, $url, $expected)
305 $this->subject
->baseUrl
= $baseUrl;
306 $this->assertSame($expected, $this->subject
->baseUrlWrap($url));