30e9670553974c69de5911de8e1c7022b0a99547
[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 tslib_fe 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 ), array(), '', FALSE);
83 $tsfe->expects($this->once())->method('INTincScript_process')->will($this->returnCallback(array($this, 'INTincScript_processCallback')));
84 $tsfe->content = file_get_contents(__DIR__ . '/Fixtures/renderedPage.html');
85 $tsfe->config['INTincScript_ext']['divKey'] = '679b52796e75d474ccbbed486b6837ab';
86 $tsfe->config['INTincScript'] = array('INT_SCRIPT.679b52796e75d474ccbbed486b6837ab' => array());
87 $GLOBALS['TT'] = new \TYPO3\CMS\Core\TimeTracker\NullTimeTracker();
88 return $tsfe;
89 }
90
91 ////////////////////////////////
92 // Tests concerning codeString
93 ////////////////////////////////
94 /**
95 * @test
96 */
97 public function codeStringForNonEmptyStringReturns10CharacterHashAndCodedString() {
98 $this->assertRegExp('/^[0-9a-f]{10}:[a-zA-Z0-9+=\\/]+$/', $this->fixture->codeString('Hello world!'));
99 }
100
101 /**
102 * @test
103 */
104 public function decodingCodedStringReturnsOriginalString() {
105 $clearText = 'Hello world!';
106 $this->assertEquals($clearText, $this->fixture->codeString($this->fixture->codeString($clearText), TRUE));
107 }
108
109 //////////////////////
110 // Tests concerning sL
111 //////////////////////
112 /**
113 * @test
114 */
115 public function localizationReturnsUnchangedStringIfNotLocallangLabel() {
116 $string = uniqid();
117 $this->assertEquals($string, $this->fixture->sL($string));
118 }
119
120 //////////////////////////////////////////
121 // Tests concerning roundTripCryptString
122 //////////////////////////////////////////
123 /**
124 * @test
125 */
126 public function roundTripCryptStringCreatesStringWithSameLengthAsInputString() {
127 $clearText = 'Hello world!';
128 $this->assertEquals(strlen($clearText), strlen($this->fixture->_callRef('roundTripCryptString', $clearText)));
129 }
130
131 /**
132 * @test
133 */
134 public function roundTripCryptStringCreatesResultDifferentFromInputString() {
135 $clearText = 'Hello world!';
136 $this->assertNotEquals($clearText, $this->fixture->_callRef('roundTripCryptString', $clearText));
137 }
138
139 /**
140 * @test
141 */
142 public function roundTripCryptStringAppliedTwoTimesReturnsOriginalString() {
143 $clearText = 'Hello world!';
144 $refValue = $this->fixture->_callRef('roundTripCryptString', $clearText);
145 $this->assertEquals($clearText, $this->fixture->_callRef('roundTripCryptString', $refValue));
146 }
147
148 /**
149 * @test
150 */
151 public function isModifyPageIdTestCalled() {
152 $GLOBALS['TT'] = $this->getMock('TYPO3\\CMS\Core\\TimeTracker\\TimeTracker');
153 $this->fixture = $this->getMock(
154 '\\TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController',
155 array(
156 'initUserGroups',
157 'setSysPageWhereClause',
158 'checkAndSetAlias',
159 'findDomainRecord',
160 'getPageAndRootlineWithDomain'
161 ),
162 array(),
163 '',
164 FALSE
165 );
166 $this->fixture->page = array();
167
168 $pageRepository = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
169 \TYPO3\CMS\Core\Utility\GeneralUtility::addInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository', $pageRepository);
170
171 $initialId = rand(1, 500);
172 $expectedId = $initialId + 42;
173 $this->fixture->id = $initialId;
174
175 $this->fixture->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['modifyPageId'][] = function($params, $frontendController) {
176 return $params['id'] + 42;
177 };
178
179 $this->fixture->fetch_the_id();
180 $this->assertSame($expectedId, $this->fixture->id);
181 }
182
183 }
184
185 ?>