TYPO3  7.6
Unit/Controller/TypoScriptFrontendControllerTest.php
Go to the documentation of this file.
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 
22 
26 class TypoScriptFrontendControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
27 {
31  protected $subject;
32 
33  protected function setUp()
34  {
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';
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, array(
78  'INTincScript_process',
79  'INTincScript_includeLibs',
80  'INTincScript_loadJSCode',
81  'setAbsRefPrefix',
82  'regeneratePageTitle'
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');
86  $tsfe->config['INTincScript_ext']['divKey'] = '679b52796e75d474ccbbed486b6837ab';
87  $tsfe->config['INTincScript'] = array('INT_SCRIPT.679b52796e75d474ccbbed486b6837ab' => array());
88  $GLOBALS['TT'] = new \TYPO3\CMS\Core\TimeTracker\NullTimeTracker();
89  return $tsfe;
90  }
91 
100  {
101  $string = $this->getUniqueId();
102  $this->assertEquals($string, $this->subject->sL($string));
103  }
104 
113  {
114  return array(
115  'typo3.org' => array(
116  'typo3.org',
117  ),
118  'foo.bar' => array(
119  'foo.bar',
120  ),
121  'example.com' => array(
122  'example.com',
123  ),
124  );
125  }
126 
132  public function getSysDomainCacheReturnsCurrentDomainRecord($currentDomain)
133  {
134  $_SERVER['HTTP_HOST'] = $currentDomain;
135  $domainRecords = array(
136  'typo3.org' => array(
137  'uid' => '1',
138  'pid' => '1',
139  'domainName' => 'typo3.org',
140  'forced' => 0,
141  ),
142  'foo.bar' => array(
143  'uid' => '2',
144  'pid' => '1',
145  'domainName' => 'foo.bar',
146  'forced' => 0,
147  ),
148  'example.com' => array(
149  'uid' => '3',
150  'pid' => '1',
151  'domainName' => 'example.com',
152  'forced' => 0,
153  ),
154  );
155  $GLOBALS['TYPO3_DB'] = $this->getMock(DatabaseConnection::class, array('exec_SELECTgetRows'));
156  $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetRows')->willReturn($domainRecords);
157  GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_runtime')->flush();
158  $expectedResult = array(
159  $domainRecords[$currentDomain]['pid'] => $domainRecords[$currentDomain],
160  );
161  $this->assertEquals($expectedResult, $this->subject->_call('getSysDomainCache'));
162  }
163 
169  public function getSysDomainCacheReturnsForcedDomainRecord($currentDomain)
170  {
171  $_SERVER['HTTP_HOST'] = $currentDomain;
172  $domainRecords = array(
173  'typo3.org' => array(
174  'uid' => '1',
175  'pid' => '1',
176  'domainName' => 'typo3.org',
177  'forced' => 0,
178  ),
179  'foo.bar' => array(
180  'uid' => '2',
181  'pid' => '1',
182  'domainName' => 'foo.bar',
183  'forced' => 1,
184  ),
185  'example.com' => array(
186  'uid' => '3',
187  'pid' => '1',
188  'domainName' => 'example.com',
189  'forced' => 0,
190  ),
191  );
192  $GLOBALS['TYPO3_DB'] = $this->getMock(DatabaseConnection::class, array('exec_SELECTgetRows'));
193  $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetRows')->willReturn($domainRecords);
194  GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_runtime')->flush();
195  $expectedResult = array(
196  $domainRecords[$currentDomain]['pid'] => $domainRecords['foo.bar'],
197  );
198  $this->assertEquals($expectedResult, $this->subject->_call('getSysDomainCache'));
199  }
200 
209  {
210  return array(
211  'same domains' => array(
212  'typo3.org',
213  'typo3.org',
214  '/index.php',
215  true,
216  ),
217  'same domains with subdomain' => array(
218  'www.typo3.org',
219  'www.typo3.org',
220  '/index.php',
221  true,
222  ),
223  'different domains' => array(
224  'foo.bar',
225  'typo3.org',
226  '/index.php',
227  false,
228  ),
229  'domain record with script name' => array(
230  'typo3.org',
231  'typo3.org/foo/bar',
232  '/foo/bar/index.php',
233  true,
234  ),
235  'domain record with wrong script name' => array(
236  'typo3.org',
237  'typo3.org/foo/bar',
238  '/bar/foo/index.php',
239  false,
240  ),
241  );
242  }
243 
252  public function domainNameMatchesCurrentRequest($currentDomain, $domainRecord, $scriptName, $expectedResult)
253  {
254  $_SERVER['HTTP_HOST'] = $currentDomain;
255  $_SERVER['SCRIPT_NAME'] = $scriptName;
256  $this->assertEquals($expectedResult, $this->subject->domainNameMatchesCurrentRequest($domainRecord));
257  }
258 }