[BUGFIX] TSFE->altPageTitle can not be set in extensions
[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 * Copyright notice
6 *
7 * (c) 2009-2013 Oliver Klee (typo3-coding@oliverklee.de)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * Testcase for TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
28 *
29 * @author Oliver Klee <typo3-coding@oliverklee.de>
30 */
31 class TypoScriptFrontendControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
32
33 /**
34 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
35 */
36 private $fixture;
37
38 public function setUp() {
39 $this->fixture = $this->getAccessibleMock('\\TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array('dummy'), array(), '', FALSE);
40 $this->fixture->TYPO3_CONF_VARS = $GLOBALS['TYPO3_CONF_VARS'];
41 $this->fixture->TYPO3_CONF_VARS['SYS']['encryptionKey'] = '170928423746123078941623042360abceb12341234231';
42 }
43
44 public function tearDown() {
45 unset($this->fixture);
46 }
47
48 ////////////////////////////////
49 // Tests concerning rendering content
50 ////////////////////////////////
51 /**
52 * @test
53 */
54 public function headerAndFooterMarkersAreReplacedDuringIntProcessing() {
55 $GLOBALS['TSFE'] = $this->setupTsfeMockForHeaderFooterReplacementCheck();
56 $GLOBALS['TSFE']->INTincScript();
57 $this->assertContains('headerData', $GLOBALS['TSFE']->content);
58 $this->assertContains('footerData', $GLOBALS['TSFE']->content);
59 }
60
61 /**
62 * This is the callback that mimics a USER_INT extension
63 */
64 public function INTincScript_processCallback() {
65 $GLOBALS['TSFE']->additionalHeaderData[] = 'headerData';
66 $GLOBALS['TSFE']->additionalFooterData[] = 'footerData';
67 }
68
69 /**
70 * Setup a \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController object only for testing the header and footer
71 * replacement during USER_INT rendering
72 *
73 * @return \PHPUnit_Framework_MockObject_MockObject
74 */
75 protected function setupTsfeMockForHeaderFooterReplacementCheck() {
76 /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $tsfe */
77 $tsfe = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', 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
92 ////////////////////////////////
93 // Tests concerning codeString
94 ////////////////////////////////
95 /**
96 * @test
97 */
98 public function codeStringForNonEmptyStringReturns10CharacterHashAndCodedString() {
99 $this->assertRegExp('/^[0-9a-f]{10}:[a-zA-Z0-9+=\\/]+$/', $this->fixture->codeString('Hello world!'));
100 }
101
102 /**
103 * @test
104 */
105 public function decodingCodedStringReturnsOriginalString() {
106 $clearText = 'Hello world!';
107 $this->assertEquals($clearText, $this->fixture->codeString($this->fixture->codeString($clearText), TRUE));
108 }
109
110 //////////////////////
111 // Tests concerning sL
112 //////////////////////
113 /**
114 * @test
115 */
116 public function localizationReturnsUnchangedStringIfNotLocallangLabel() {
117 $string = uniqid();
118 $this->assertEquals($string, $this->fixture->sL($string));
119 }
120
121 //////////////////////////////////////////
122 // Tests concerning roundTripCryptString
123 //////////////////////////////////////////
124 /**
125 * @test
126 */
127 public function roundTripCryptStringCreatesStringWithSameLengthAsInputString() {
128 $clearText = 'Hello world!';
129 $this->assertEquals(strlen($clearText), strlen($this->fixture->_callRef('roundTripCryptString', $clearText)));
130 }
131
132 /**
133 * @test
134 */
135 public function roundTripCryptStringCreatesResultDifferentFromInputString() {
136 $clearText = 'Hello world!';
137 $this->assertNotEquals($clearText, $this->fixture->_callRef('roundTripCryptString', $clearText));
138 }
139
140 /**
141 * @test
142 */
143 public function roundTripCryptStringAppliedTwoTimesReturnsOriginalString() {
144 $clearText = 'Hello world!';
145 $refValue = $this->fixture->_callRef('roundTripCryptString', $clearText);
146 $this->assertEquals($clearText, $this->fixture->_callRef('roundTripCryptString', $refValue));
147 }
148
149 /**
150 * @test
151 */
152 public function isModifyPageIdTestCalled() {
153 $GLOBALS['TT'] = $this->getMock('TYPO3\\CMS\Core\\TimeTracker\\TimeTracker');
154 $this->fixture = $this->getMock(
155 '\\TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController',
156 array(
157 'initUserGroups',
158 'setSysPageWhereClause',
159 'checkAndSetAlias',
160 'findDomainRecord',
161 'getPageAndRootlineWithDomain'
162 ),
163 array(),
164 '',
165 FALSE
166 );
167 $this->fixture->page = array();
168
169 $pageRepository = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
170 \TYPO3\CMS\Core\Utility\GeneralUtility::addInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository', $pageRepository);
171
172 $initialId = rand(1, 500);
173 $expectedId = $initialId + 42;
174 $this->fixture->id = $initialId;
175
176 $this->fixture->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['modifyPageId'][] = function($params, $frontendController) {
177 return $params['id'] + 42;
178 };
179
180 $this->fixture->fetch_the_id();
181 $this->assertSame($expectedId, $this->fixture->id);
182 }
183
184 }