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