[BUGFIX] Namespace: EXT: indexed_search
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Tests / Unit / FrontendTest.php
1 <?php
2 namespace TYPO3\CMS\Frontend\Tests\Unit;
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 the "tslib_fe" class in the TYPO3 Core.
28 *
29 * @package TYPO3
30 * @subpackage tslib
31 * @author Oliver Klee <typo3-coding@oliverklee.de>
32 */
33 class FrontendTest extends tx_phpunit_testcase {
34
35 /**
36 * Enable backup of global and system variables
37 *
38 * @var boolean
39 */
40 protected $backupGlobals = TRUE;
41
42 /**
43 * Exclude TYPO3_DB from backup/ restore of $GLOBALS
44 * because resource types cannot be handled during serializing
45 *
46 * @var array
47 */
48 protected $backupGlobalsBlacklist = array('TYPO3_DB');
49
50 /**
51 * @var \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
52 */
53 private $fixture;
54
55 public function setUp() {
56 // This creates an instance of the class without calling the
57 // original constructor.
58 $className = uniqid('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController');
59 eval((((((((('class ' . $className) . ' extends TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController {') . 'public function ') . $className) . '() {}') . 'public function roundTripCryptString($string) {') . 'return parent::roundTripCryptString($string);') . '}') . '}');
60 $this->fixture = new $className();
61 $this->fixture->TYPO3_CONF_VARS = $GLOBALS['TYPO3_CONF_VARS'];
62 $this->fixture->TYPO3_CONF_VARS['SYS']['encryptionKey'] = '170928423746123078941623042360abceb12341234231';
63 }
64
65 public function tearDown() {
66 unset($this->fixture);
67 }
68
69 ////////////////////////////////
70 // Tests concerning rendering content
71 ////////////////////////////////
72 /**
73 * @test
74 */
75 public function headerAndFooterMarkersAreReplacedDuringIntProcessing() {
76 $GLOBALS['TSFE'] = $this->setupTsfeMockForHeaderFooterReplacementCheck();
77 $GLOBALS['TSFE']->INTincScript();
78 $this->assertContains('headerData', $GLOBALS['TSFE']->content);
79 $this->assertContains('footerData', $GLOBALS['TSFE']->content);
80 }
81
82 /**
83 * This is the callback that mimics a USER_INT extension
84 */
85 public function INTincScript_processCallback() {
86 $GLOBALS['TSFE']->additionalHeaderData[] = 'headerData';
87 $GLOBALS['TSFE']->additionalFooterData[] = 'footerData';
88 }
89
90 /**
91 * Setup a tslib_fe object only for testing the header and footer
92 * replacement during USER_INT rendering
93 *
94 * @return PHPUnit_Framework_MockObject_MockObject
95 */
96 protected function setupTsfeMockForHeaderFooterReplacementCheck() {
97 $tsfe = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(
98 'INTincScript_process',
99 'INTincScript_includeLibs',
100 'INTincScript_loadJSCode',
101 'setAbsRefPrefix'
102 ), array(), '', FALSE);
103 $tsfe->expects($this->once())->method('INTincScript_process')->will($this->returnCallback(array($this, 'INTincScript_processCallback')));
104 $tsfe->content = file_get_contents(__DIR__ . '/../fixtures/renderedPage.html');
105 $tsfe->config['INTincScript_ext']['divKey'] = '679b52796e75d474ccbbed486b6837ab';
106 $tsfe->config['INTincScript'] = array('INT_SCRIPT.679b52796e75d474ccbbed486b6837ab' => array());
107 $GLOBALS['TT'] = new \t3lib_timeTrackNull();
108 return $tsfe;
109 }
110
111 ////////////////////////////////
112 // Tests concerning codeString
113 ////////////////////////////////
114 /**
115 * @test
116 */
117 public function codeStringForNonEmptyStringReturns10CharacterHashAndCodedString() {
118 $this->assertRegExp('/^[0-9a-f]{10}:[a-zA-Z0-9+=\\/]+$/', $this->fixture->codeString('Hello world!'));
119 }
120
121 /**
122 * @test
123 */
124 public function decodingCodedStringReturnsOriginalString() {
125 $clearText = 'Hello world!';
126 $this->assertEquals($clearText, $this->fixture->codeString($this->fixture->codeString($clearText), TRUE));
127 }
128
129 //////////////////////
130 // Tests concerning sL
131 //////////////////////
132 /**
133 * @test
134 */
135 public function localizationReturnsUnchangedStringIfNotLocallangLabel() {
136 $string = uniqid();
137 $this->assertEquals($string, $this->fixture->sL($string));
138 }
139
140 //////////////////////////////////////////
141 // Tests concerning roundTripCryptString
142 //////////////////////////////////////////
143 /**
144 * @test
145 */
146 public function roundTripCryptStringCreatesStringWithSameLengthAsInputString() {
147 $clearText = 'Hello world!';
148 $this->assertEquals(strlen($clearText), strlen($this->fixture->roundTripCryptString($clearText)));
149 }
150
151 /**
152 * @test
153 */
154 public function roundTripCryptStringCreatesResultDifferentFromInputString() {
155 $clearText = 'Hello world!';
156 $this->assertNotEquals($clearText, $this->fixture->roundTripCryptString($clearText));
157 }
158
159 /**
160 * @test
161 */
162 public function roundTripCryptStringAppliedTwoTimesReturnsOriginalString() {
163 $clearText = 'Hello world!';
164 $this->assertEquals($clearText, $this->fixture->roundTripCryptString($this->fixture->roundTripCryptString($clearText)));
165 }
166
167 }
168
169
170 ?>