[BUGFIX] PHP 5.4 unit test warnings
[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-2011 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 * @package TYPO3
30 * @subpackage tslib
31 * @author Oliver Klee <typo3-coding@oliverklee.de>
32 */
33 class TypoScriptFrontendControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
34
35 /**
36 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
37 */
38 private $fixture;
39
40 public function setUp() {
41 $this->fixture = $this->getAccessibleMock('\\TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array('dummy'), array(), '', FALSE);
42 $this->fixture->TYPO3_CONF_VARS = $GLOBALS['TYPO3_CONF_VARS'];
43 $this->fixture->TYPO3_CONF_VARS['SYS']['encryptionKey'] = '170928423746123078941623042360abceb12341234231';
44 }
45
46 public function tearDown() {
47 unset($this->fixture);
48 }
49
50 ////////////////////////////////
51 // Tests concerning rendering content
52 ////////////////////////////////
53 /**
54 * @test
55 */
56 public function headerAndFooterMarkersAreReplacedDuringIntProcessing() {
57 $GLOBALS['TSFE'] = $this->setupTsfeMockForHeaderFooterReplacementCheck();
58 $GLOBALS['TSFE']->INTincScript();
59 $this->assertContains('headerData', $GLOBALS['TSFE']->content);
60 $this->assertContains('footerData', $GLOBALS['TSFE']->content);
61 }
62
63 /**
64 * This is the callback that mimics a USER_INT extension
65 */
66 public function INTincScript_processCallback() {
67 $GLOBALS['TSFE']->additionalHeaderData[] = 'headerData';
68 $GLOBALS['TSFE']->additionalFooterData[] = 'footerData';
69 }
70
71 /**
72 * Setup a tslib_fe object only for testing the header and footer
73 * replacement during USER_INT rendering
74 *
75 * @return \PHPUnit_Framework_MockObject_MockObject
76 */
77 protected function setupTsfeMockForHeaderFooterReplacementCheck() {
78 /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $tsfe */
79 $tsfe = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(
80 'INTincScript_process',
81 'INTincScript_includeLibs',
82 'INTincScript_loadJSCode',
83 'setAbsRefPrefix'
84 ), array(), '', FALSE);
85 $tsfe->expects($this->once())->method('INTincScript_process')->will($this->returnCallback(array($this, 'INTincScript_processCallback')));
86 $tsfe->content = file_get_contents(__DIR__ . '/Fixtures/renderedPage.html');
87 $tsfe->config['INTincScript_ext']['divKey'] = '679b52796e75d474ccbbed486b6837ab';
88 $tsfe->config['INTincScript'] = array('INT_SCRIPT.679b52796e75d474ccbbed486b6837ab' => array());
89 $GLOBALS['TT'] = new \TYPO3\CMS\Core\TimeTracker\NullTimeTracker();
90 return $tsfe;
91 }
92
93 ////////////////////////////////
94 // Tests concerning codeString
95 ////////////////////////////////
96 /**
97 * @test
98 */
99 public function codeStringForNonEmptyStringReturns10CharacterHashAndCodedString() {
100 $this->assertRegExp('/^[0-9a-f]{10}:[a-zA-Z0-9+=\\/]+$/', $this->fixture->codeString('Hello world!'));
101 }
102
103 /**
104 * @test
105 */
106 public function decodingCodedStringReturnsOriginalString() {
107 $clearText = 'Hello world!';
108 $this->assertEquals($clearText, $this->fixture->codeString($this->fixture->codeString($clearText), TRUE));
109 }
110
111 //////////////////////
112 // Tests concerning sL
113 //////////////////////
114 /**
115 * @test
116 */
117 public function localizationReturnsUnchangedStringIfNotLocallangLabel() {
118 $string = uniqid();
119 $this->assertEquals($string, $this->fixture->sL($string));
120 }
121
122 //////////////////////////////////////////
123 // Tests concerning roundTripCryptString
124 //////////////////////////////////////////
125 /**
126 * @test
127 */
128 public function roundTripCryptStringCreatesStringWithSameLengthAsInputString() {
129 $clearText = 'Hello world!';
130 $this->assertEquals(strlen($clearText), strlen($this->fixture->_callRef('roundTripCryptString', $clearText)));
131 }
132
133 /**
134 * @test
135 */
136 public function roundTripCryptStringCreatesResultDifferentFromInputString() {
137 $clearText = 'Hello world!';
138 $this->assertNotEquals($clearText, $this->fixture->_callRef('roundTripCryptString', $clearText));
139 }
140
141 /**
142 * @test
143 */
144 public function roundTripCryptStringAppliedTwoTimesReturnsOriginalString() {
145 $clearText = 'Hello world!';
146 $refValue = $this->fixture->_callRef('roundTripCryptString', $clearText);
147 $this->assertEquals($clearText, $this->fixture->_callRef('roundTripCryptString', $refValue));
148 }
149
150 /**
151 * @test
152 */
153 public function isModifyPageIdTestCalled() {
154 $GLOBALS['TT'] = $this->getMock('TYPO3\\CMS\Core\\TimeTracker\\TimeTracker');
155 $this->fixture = $this->getMock(
156 '\\TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController',
157 array(
158 'initUserGroups',
159 'setSysPageWhereClause',
160 'checkAndSetAlias',
161 'findDomainRecord',
162 'getPageAndRootlineWithDomain'
163 ),
164 array(),
165 '',
166 FALSE
167 );
168 $this->fixture->page = array();
169
170 $pageRepository = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
171 \TYPO3\CMS\Core\Utility\GeneralUtility::addInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository', $pageRepository);
172
173 $initialId = rand(1, 500);
174 $expectedId = $initialId + 42;
175 $this->fixture->id = $initialId;
176
177 $this->fixture->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['modifyPageId'][] = function($params, $frontendController) {
178 return $params['id'] + 42;
179 };
180
181 $this->fixture->fetch_the_id();
182 $this->assertSame($expectedId, $this->fixture->id);
183 }
184
185 }
186
187 ?>