4c5b7d702555128b1b8daadf1292273a20a39461
[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 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16 /**
17 * Testcase for TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
18 *
19 * @author Oliver Klee <typo3-coding@oliverklee.de>
20 */
21 class TypoScriptFrontendControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
22
23 /**
24 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
25 */
26 protected $fixture;
27
28 public function setUp() {
29 $this->fixture = $this->getAccessibleMock('\\TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array('dummy'), array(), '', FALSE);
30 $this->fixture->TYPO3_CONF_VARS = $GLOBALS['TYPO3_CONF_VARS'];
31 $this->fixture->TYPO3_CONF_VARS['SYS']['encryptionKey'] = '170928423746123078941623042360abceb12341234231';
32 }
33
34 ////////////////////////////////
35 // Tests concerning rendering content
36 ////////////////////////////////
37 /**
38 * @test
39 */
40 public function headerAndFooterMarkersAreReplacedDuringIntProcessing() {
41 $GLOBALS['TSFE'] = $this->setupTsfeMockForHeaderFooterReplacementCheck();
42 $GLOBALS['TSFE']->INTincScript();
43 $this->assertContains('headerData', $GLOBALS['TSFE']->content);
44 $this->assertContains('footerData', $GLOBALS['TSFE']->content);
45 }
46
47 /**
48 * This is the callback that mimics a USER_INT extension
49 */
50 public function INTincScript_processCallback() {
51 $GLOBALS['TSFE']->additionalHeaderData[] = 'headerData';
52 $GLOBALS['TSFE']->additionalFooterData[] = 'footerData';
53 }
54
55 /**
56 * Setup a \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController object only for testing the header and footer
57 * replacement during USER_INT rendering
58 *
59 * @return \PHPUnit_Framework_MockObject_MockObject
60 */
61 protected function setupTsfeMockForHeaderFooterReplacementCheck() {
62 /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $tsfe */
63 $tsfe = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(
64 'INTincScript_process',
65 'INTincScript_includeLibs',
66 'INTincScript_loadJSCode',
67 'setAbsRefPrefix',
68 'regeneratePageTitle'
69 ), array(), '', FALSE);
70 $tsfe->expects($this->exactly(2))->method('INTincScript_process')->will($this->returnCallback(array($this, 'INTincScript_processCallback')));
71 $tsfe->content = file_get_contents(__DIR__ . '/Fixtures/renderedPage.html');
72 $tsfe->config['INTincScript_ext']['divKey'] = '679b52796e75d474ccbbed486b6837ab';
73 $tsfe->config['INTincScript'] = array('INT_SCRIPT.679b52796e75d474ccbbed486b6837ab' => array());
74 $GLOBALS['TT'] = new \TYPO3\CMS\Core\TimeTracker\NullTimeTracker();
75 return $tsfe;
76 }
77
78 ////////////////////////////////
79 // Tests concerning codeString
80 ////////////////////////////////
81 /**
82 * @test
83 */
84 public function codeStringForNonEmptyStringReturns10CharacterHashAndCodedString() {
85 $this->assertRegExp('/^[0-9a-f]{10}:[a-zA-Z0-9+=\\/]+$/', $this->fixture->codeString('Hello world!'));
86 }
87
88 /**
89 * @test
90 */
91 public function decodingCodedStringReturnsOriginalString() {
92 $clearText = 'Hello world!';
93 $this->assertEquals($clearText, $this->fixture->codeString($this->fixture->codeString($clearText), TRUE));
94 }
95
96 //////////////////////
97 // Tests concerning sL
98 //////////////////////
99 /**
100 * @test
101 */
102 public function localizationReturnsUnchangedStringIfNotLocallangLabel() {
103 $string = uniqid();
104 $this->assertEquals($string, $this->fixture->sL($string));
105 }
106
107 //////////////////////////////////////////
108 // Tests concerning roundTripCryptString
109 //////////////////////////////////////////
110 /**
111 * @test
112 */
113 public function roundTripCryptStringCreatesStringWithSameLengthAsInputString() {
114 $clearText = 'Hello world!';
115 $this->assertEquals(strlen($clearText), strlen($this->fixture->_callRef('roundTripCryptString', $clearText)));
116 }
117
118 /**
119 * @test
120 */
121 public function roundTripCryptStringCreatesResultDifferentFromInputString() {
122 $clearText = 'Hello world!';
123 $this->assertNotEquals($clearText, $this->fixture->_callRef('roundTripCryptString', $clearText));
124 }
125
126 /**
127 * @test
128 */
129 public function roundTripCryptStringAppliedTwoTimesReturnsOriginalString() {
130 $clearText = 'Hello world!';
131 $refValue = $this->fixture->_callRef('roundTripCryptString', $clearText);
132 $this->assertEquals($clearText, $this->fixture->_callRef('roundTripCryptString', $refValue));
133 }
134 }