TYPO3 CMS  TYPO3_6-2
TypoScriptFrontendControllerTest.php
Go to the documentation of this file.
1 <?php
3 
17 
24 
28  protected $fixture;
29 
30  public function setUp() {
31  $this->fixture = $this->getAccessibleMock('\\TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array('dummy'), array(), '', FALSE);
32  $this->fixture->TYPO3_CONF_VARS = $GLOBALS['TYPO3_CONF_VARS'];
33  $this->fixture->TYPO3_CONF_VARS['SYS']['encryptionKey'] = '170928423746123078941623042360abceb12341234231';
34 
35  $pageRepository = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
36  $this->fixture->sys_page = $pageRepository;
37  }
38 
40  // Tests concerning rendering content
42 
46  $GLOBALS['TSFE'] = $this->setupTsfeMockForHeaderFooterReplacementCheck();
47  $GLOBALS['TSFE']->INTincScript();
48  $this->assertContains('headerData', $GLOBALS['TSFE']->content);
49  $this->assertContains('footerData', $GLOBALS['TSFE']->content);
50  }
51 
55  public function INTincScript_processCallback() {
56  $GLOBALS['TSFE']->additionalHeaderData[] = 'headerData';
57  $GLOBALS['TSFE']->additionalFooterData[] = 'footerData';
58  }
59 
66  protected function setupTsfeMockForHeaderFooterReplacementCheck() {
68  $tsfe = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(
69  'INTincScript_process',
70  'INTincScript_includeLibs',
71  'INTincScript_loadJSCode',
72  'setAbsRefPrefix',
73  'regeneratePageTitle'
74  ), array(), '', FALSE);
75  $tsfe->expects($this->exactly(2))->method('INTincScript_process')->will($this->returnCallback(array($this, 'INTincScript_processCallback')));
76  $tsfe->content = file_get_contents(__DIR__ . '/Fixtures/renderedPage.html');
77  $tsfe->config['INTincScript_ext']['divKey'] = '679b52796e75d474ccbbed486b6837ab';
78  $tsfe->config['INTincScript'] = array('INT_SCRIPT.679b52796e75d474ccbbed486b6837ab' => array());
79  $GLOBALS['TT'] = new \TYPO3\CMS\Core\TimeTracker\NullTimeTracker();
80  return $tsfe;
81  }
82 
84  // Tests concerning codeString
86 
90  $this->assertRegExp('/^[0-9a-f]{10}:[a-zA-Z0-9+=\\/]+$/', $this->fixture->codeString('Hello world!'));
91  }
92 
97  $clearText = 'Hello world!';
98  $this->assertEquals($clearText, $this->fixture->codeString($this->fixture->codeString($clearText), TRUE));
99  }
100 
102  // Tests concerning sL
104 
108  $string = $this->getUniqueId();
109  $this->assertEquals($string, $this->fixture->sL($string));
110  }
111 
113  // Tests concerning roundTripCryptString
115 
119  $clearText = 'Hello world!';
120  $this->assertEquals(strlen($clearText), strlen($this->fixture->_callRef('roundTripCryptString', $clearText)));
121  }
122 
127  $clearText = 'Hello world!';
128  $this->assertNotEquals($clearText, $this->fixture->_callRef('roundTripCryptString', $clearText));
129  }
130 
135  $clearText = 'Hello world!';
136  $refValue = $this->fixture->_callRef('roundTripCryptString', $clearText);
137  $this->assertEquals($clearText, $this->fixture->_callRef('roundTripCryptString', $refValue));
138  }
139 
147  public function getSysDomainCacheDataProvider() {
148  return array(
149  'typo3.org' => array(
150  'typo3.org',
151  ),
152  'foo.bar' => array(
153  'foo.bar',
154  ),
155  'example.com' => array(
156  'example.com',
157  ),
158  );
159  }
160 
166  public function getSysDomainCacheReturnsCurrentDomainRecord($currentDomain) {
167  $_SERVER['HTTP_HOST'] = $currentDomain;
168  $domainRecords = array(
169  'typo3.org' => array(
170  'pid' => '1',
171  'domainName' => 'typo3.org',
172  'forced' => 0,
173  ),
174  'foo.bar' => array(
175  'pid' => '1',
176  'domainName' => 'foo.bar',
177  'forced' => 0,
178  ),
179  'example.com' => array(
180  'pid' => '1',
181  'domainName' => 'example.com',
182  'forced' => 0,
183  ),
184  );
185  $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array('exec_SELECTgetRows'));
186  $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetRows')->willReturn($domainRecords);
187  GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_runtime')->flush();
188  $expectedResult = array(
189  $domainRecords[$currentDomain]['pid'] => $domainRecords[$currentDomain],
190  );
191  $this->assertEquals($expectedResult, $this->fixture->_call('getSysDomainCache'));
192  }
193 
199  public function getSysDomainCacheReturnsForcedDomainRecord($currentDomain) {
200  $_SERVER['HTTP_HOST'] = $currentDomain;
201  $domainRecords = array(
202  'typo3.org' => array(
203  'pid' => '1',
204  'domainName' => 'typo3.org',
205  'forced' => 0,
206  ),
207  'foo.bar' => array(
208  'pid' => '1',
209  'domainName' => 'foo.bar',
210  'forced' => 1,
211  ),
212  'example.com' => array(
213  'pid' => '1',
214  'domainName' => 'example.com',
215  'forced' => 0,
216  ),
217  );
218  $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array('exec_SELECTgetRows'));
219  $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetRows')->willReturn($domainRecords);
220  GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_runtime')->flush();
221  $expectedResult = array(
222  $domainRecords[$currentDomain]['pid'] => $domainRecords['foo.bar'],
223  );
224  $this->assertEquals($expectedResult, $this->fixture->_call('getSysDomainCache'));
225  }
226 
235  return array(
236  'same domains' => array(
237  'typo3.org',
238  'typo3.org',
239  '/index.php',
240  TRUE,
241  ),
242  'same domains with subdomain' => array(
243  'www.typo3.org',
244  'www.typo3.org',
245  '/index.php',
246  TRUE,
247  ),
248  'different domains' => array(
249  'foo.bar',
250  'typo3.org',
251  '/index.php',
252  FALSE,
253  ),
254  'domain record with script name' => array(
255  'typo3.org',
256  'typo3.org/foo/bar',
257  '/foo/bar/index.php',
258  TRUE,
259  ),
260  'domain record with wrong script name' => array(
261  'typo3.org',
262  'typo3.org/foo/bar',
263  '/bar/foo/index.php',
264  FALSE,
265  ),
266  );
267  }
268 
277  public function domainNameMatchesCurrentRequest($currentDomain, $domainRecord, $scriptName, $expectedResult) {
278  $_SERVER['HTTP_HOST'] = $currentDomain;
279  $_SERVER['SCRIPT_NAME'] = $scriptName;
280  $this->assertEquals($expectedResult, $this->fixture->domainNameMatchesCurrentRequest($domainRecord));
281  }
282 
283 }
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
domainNameMatchesCurrentRequest($currentDomain, $domainRecord, $scriptName, $expectedResult)