001f499b6364aec1450431c07413b8fc717d330e
[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 * Enable backup of global and system variables
37 *
38 * @var boolean
39 */
40 protected $backupGlobals = TRUE;
41
42 /**
43 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
44 */
45 private $fixture;
46
47 public function setUp() {
48 $this->fixture = $this->getAccessibleMock('\\TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array('dummy'), array(), '', FALSE);
49 $this->fixture->TYPO3_CONF_VARS = $GLOBALS['TYPO3_CONF_VARS'];
50 $this->fixture->TYPO3_CONF_VARS['SYS']['encryptionKey'] = '170928423746123078941623042360abceb12341234231';
51 }
52
53 public function tearDown() {
54 unset($this->fixture);
55 }
56
57 ////////////////////////////////
58 // Tests concerning rendering content
59 ////////////////////////////////
60 /**
61 * @test
62 */
63 public function headerAndFooterMarkersAreReplacedDuringIntProcessing() {
64 $GLOBALS['TSFE'] = $this->setupTsfeMockForHeaderFooterReplacementCheck();
65 $GLOBALS['TSFE']->INTincScript();
66 $this->assertContains('headerData', $GLOBALS['TSFE']->content);
67 $this->assertContains('footerData', $GLOBALS['TSFE']->content);
68 }
69
70 /**
71 * This is the callback that mimics a USER_INT extension
72 */
73 public function INTincScript_processCallback() {
74 $GLOBALS['TSFE']->additionalHeaderData[] = 'headerData';
75 $GLOBALS['TSFE']->additionalFooterData[] = 'footerData';
76 }
77
78 /**
79 * Setup a tslib_fe object only for testing the header and footer
80 * replacement during USER_INT rendering
81 *
82 * @return \PHPUnit_Framework_MockObject_MockObject
83 */
84 protected function setupTsfeMockForHeaderFooterReplacementCheck() {
85 /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $tsfe */
86 $tsfe = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(
87 'INTincScript_process',
88 'INTincScript_includeLibs',
89 'INTincScript_loadJSCode',
90 'setAbsRefPrefix'
91 ), array(), '', FALSE);
92 $tsfe->expects($this->once())->method('INTincScript_process')->will($this->returnCallback(array($this, 'INTincScript_processCallback')));
93 $tsfe->content = file_get_contents(__DIR__ . '/Fixtures/renderedPage.html');
94 $tsfe->config['INTincScript_ext']['divKey'] = '679b52796e75d474ccbbed486b6837ab';
95 $tsfe->config['INTincScript'] = array('INT_SCRIPT.679b52796e75d474ccbbed486b6837ab' => array());
96 $GLOBALS['TT'] = new \TYPO3\CMS\Core\TimeTracker\NullTimeTracker();
97 return $tsfe;
98 }
99
100 ////////////////////////////////
101 // Tests concerning codeString
102 ////////////////////////////////
103 /**
104 * @test
105 */
106 public function codeStringForNonEmptyStringReturns10CharacterHashAndCodedString() {
107 $this->assertRegExp('/^[0-9a-f]{10}:[a-zA-Z0-9+=\\/]+$/', $this->fixture->codeString('Hello world!'));
108 }
109
110 /**
111 * @test
112 */
113 public function decodingCodedStringReturnsOriginalString() {
114 $clearText = 'Hello world!';
115 $this->assertEquals($clearText, $this->fixture->codeString($this->fixture->codeString($clearText), TRUE));
116 }
117
118 //////////////////////
119 // Tests concerning sL
120 //////////////////////
121 /**
122 * @test
123 */
124 public function localizationReturnsUnchangedStringIfNotLocallangLabel() {
125 $string = uniqid();
126 $this->assertEquals($string, $this->fixture->sL($string));
127 }
128
129 //////////////////////////////////////////
130 // Tests concerning roundTripCryptString
131 //////////////////////////////////////////
132 /**
133 * @test
134 */
135 public function roundTripCryptStringCreatesStringWithSameLengthAsInputString() {
136 $clearText = 'Hello world!';
137 $this->assertEquals(strlen($clearText), strlen($this->fixture->_callRef('roundTripCryptString', $clearText)));
138 }
139
140 /**
141 * @test
142 */
143 public function roundTripCryptStringCreatesResultDifferentFromInputString() {
144 $clearText = 'Hello world!';
145 $this->assertNotEquals($clearText, $this->fixture->_callRef('roundTripCryptString', $clearText));
146 }
147
148 /**
149 * @test
150 */
151 public function roundTripCryptStringAppliedTwoTimesReturnsOriginalString() {
152 $clearText = 'Hello world!';
153 $refValue = $this->fixture->_callRef('roundTripCryptString', $clearText);
154 $this->assertEquals($clearText, $this->fixture->_callRef('roundTripCryptString', $refValue));
155 }
156
157 }
158
159 ?>