[TASK] Clarify reset in page renderer comment
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Page / PageRendererTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Page;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009-2013 Steffen Kamper (info@sk-typo3.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 use TYPO3\CMS\Core\Page\PageRenderer;
27
28 /**
29 * Unit test case
30 *
31 * @see According functional test case
32 */
33 class PageRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
34
35 /**
36 * @test
37 */
38 public function renderMethodCallsResetInAnyCase() {
39 $pageRenderer = $this->getMock('TYPO3\\CMS\\Core\\Page\\PageRenderer', array('reset', 'prepareRendering', 'renderJavaScriptAndCss', 'getPreparedMarkerArray', 'getTemplateForPart'));
40 $pageRenderer->expects($this->exactly(3))->method('reset');
41
42 $pageRenderer->render(PageRenderer::PART_COMPLETE);
43 $pageRenderer->render(PageRenderer::PART_HEADER);
44 $pageRenderer->render(PageRenderer::PART_FOOTER);
45 }
46
47 /**
48 * @expectedException \UnexpectedValueException
49 * @test
50 */
51 public function includingNotAvailableLocalJqueryVersionThrowsException() {
52 /** @var \TYPO3\CMS\Core\Page\PageRenderer|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $subject */
53 $subject = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Page\\PageRenderer', array('dummy'), array(), '', FALSE);
54 $subject->_set('availableLocalJqueryVersions', array('1.1.1'));
55 $subject->loadJquery('2.2.2');
56 }
57
58 /**
59 * @expectedException \UnexpectedValueException
60 * @test
61 */
62 public function includingJqueryWithNonAlphnumericNamespaceThrowsException() {
63 /** @var \TYPO3\CMS\Core\Page\PageRenderer|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $subject */
64 $subject = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Page\\PageRenderer', array('dummy'), array(), '', FALSE);
65 $subject->loadJquery(NULL, NULL, '12sd.12fsd');
66 $subject->render();
67 }
68
69 /**
70 * @test
71 */
72 public function addBodyContentAddsContent() {
73 /** @var \TYPO3\CMS\Core\Page\PageRenderer|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $subject */
74 $subject = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Page\\PageRenderer', array('dummy'), array(), '', FALSE);
75 $expectedReturnValue = 'ABCDE';
76 $subject->addBodyContent('A');
77 $subject->addBodyContent('B');
78 $subject->addBodyContent('C');
79 $subject->addBodyContent('D');
80 $subject->addBodyContent('E');
81 $out = $subject->getBodyContent();
82 $this->assertEquals($expectedReturnValue, $out);
83 }
84
85 /**
86 * @test
87 */
88 public function addInlineLanguageLabelFileSetsInlineLanguageLabelFiles() {
89 /** @var \TYPO3\CMS\Core\Page\PageRenderer|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $subject */
90 $subject = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Page\\PageRenderer', array('dummy'), array(), '', FALSE);
91 $fileReference = uniqid('file_');
92 $selectionPrefix = uniqid('prefix_');
93 $stripFromSelectionName = uniqid('strip_');
94 $errorMode = 0;
95
96 $expectedInlineLanguageLabelFile = array(
97 'fileRef' => $fileReference,
98 'selectionPrefix' => $selectionPrefix,
99 'stripFromSelectionName' => $stripFromSelectionName,
100 'errorMode' => $errorMode
101 );
102
103 $subject->addInlineLanguageLabelFile($fileReference, $selectionPrefix, $stripFromSelectionName, $errorMode);
104 $actualResult = $subject->getInlineLanguageLabelFiles();
105
106 $this->assertSame($expectedInlineLanguageLabelFile, array_pop($actualResult));
107 }
108
109 /**
110 * @test
111 */
112 public function addInlineLanguageLabelFileSetsTwoDifferentInlineLanguageLabelFiles() {
113 /** @var \TYPO3\CMS\Core\Page\PageRenderer|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $subject */
114 $subject = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Page\\PageRenderer', array('dummy'), array(), '', FALSE);
115 $fileReference1 = uniqid('file1_');
116 $selectionPrefix1 = uniqid('prefix1_');
117 $stripFromSelectionName1 = uniqid('strip1_');
118 $errorMode1 = 0;
119 $expectedInlineLanguageLabelFile1 = array(
120 'fileRef' => $fileReference1,
121 'selectionPrefix' => $selectionPrefix1,
122 'stripFromSelectionName' => $stripFromSelectionName1,
123 'errorMode' => $errorMode1
124 );
125 $fileReference2 = uniqid('file2_');
126 $selectionPrefix2 = uniqid('prefix2_');
127 $stripFromSelectionName2 = uniqid('strip2_');
128 $errorMode2 = 0;
129 $expectedInlineLanguageLabelFile2 = array(
130 'fileRef' => $fileReference2,
131 'selectionPrefix' => $selectionPrefix2,
132 'stripFromSelectionName' => $stripFromSelectionName2,
133 'errorMode' => $errorMode2
134 );
135
136 $subject->addInlineLanguageLabelFile($fileReference1, $selectionPrefix1, $stripFromSelectionName1, $errorMode1);
137 $subject->addInlineLanguageLabelFile($fileReference2, $selectionPrefix2, $stripFromSelectionName2, $errorMode2);
138 $actualResult = $subject->getInlineLanguageLabelFiles();
139
140 $this->assertSame($expectedInlineLanguageLabelFile2, array_pop($actualResult));
141 $this->assertSame($expectedInlineLanguageLabelFile1, array_pop($actualResult));
142 }
143
144 /**
145 * @test
146 */
147 public function addInlineLanguageLabelFileDoesNotSetSameLanguageFileTwice() {
148 /** @var \TYPO3\CMS\Core\Page\PageRenderer|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $subject */
149 $subject = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Page\\PageRenderer', array('dummy'), array(), '', FALSE);
150 $fileReference = uniqid('file2_');
151 $selectionPrefix = uniqid('prefix2_');
152 $stripFromSelectionName = uniqid('strip2_');
153 $errorMode = 0;
154
155 $subject->addInlineLanguageLabelFile($fileReference, $selectionPrefix, $stripFromSelectionName, $errorMode);
156 $subject->addInlineLanguageLabelFile($fileReference, $selectionPrefix, $stripFromSelectionName, $errorMode);
157 $this->assertSame(1, count($subject->getInlineLanguageLabelFiles()));
158 }
159 }