94e8c475688f317a5b67a4721df81bbbb75cb702
[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
27 /**
28 * Unit test case
29 *
30 * @see According functional test case
31 */
32 class PageRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
33
34 /**
35 * @expectedException \UnexpectedValueException
36 * @test
37 */
38 public function includingNotAvailableLocalJqueryVersionThrowsException() {
39 /** @var \TYPO3\CMS\Core\Page\PageRenderer|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $subject */
40 $subject = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Page\\PageRenderer', array('dummy'), array(), '', FALSE);
41 $subject->_set('availableLocalJqueryVersions', array('1.1.1'));
42 $subject->loadJquery('2.2.2');
43 }
44
45 /**
46 * @expectedException \UnexpectedValueException
47 * @test
48 */
49 public function includingJqueryWithNonAlphnumericNamespaceThrowsException() {
50 /** @var \TYPO3\CMS\Core\Page\PageRenderer|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $subject */
51 $subject = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Page\\PageRenderer', array('dummy'), array(), '', FALSE);
52 $subject->loadJquery(NULL, NULL, '12sd.12fsd');
53 $subject->render();
54 }
55
56 /**
57 * @test
58 */
59 public function addBodyContentAddsContent() {
60 /** @var \TYPO3\CMS\Core\Page\PageRenderer|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $subject */
61 $subject = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Page\\PageRenderer', array('dummy'), array(), '', FALSE);
62 $expectedReturnValue = 'ABCDE';
63 $subject->addBodyContent('A');
64 $subject->addBodyContent('B');
65 $subject->addBodyContent('C');
66 $subject->addBodyContent('D');
67 $subject->addBodyContent('E');
68 $out = $subject->getBodyContent();
69 $this->assertEquals($expectedReturnValue, $out);
70 }
71
72 /**
73 * @test
74 */
75 public function addInlineLanguageLabelFileSetsInlineLanguageLabelFiles() {
76 /** @var \TYPO3\CMS\Core\Page\PageRenderer|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $subject */
77 $subject = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Page\\PageRenderer', array('dummy'), array(), '', FALSE);
78 $fileReference = uniqid('file_');
79 $selectionPrefix = uniqid('prefix_');
80 $stripFromSelectionName = uniqid('strip_');
81 $errorMode = 0;
82
83 $expectedInlineLanguageLabelFile = array(
84 'fileRef' => $fileReference,
85 'selectionPrefix' => $selectionPrefix,
86 'stripFromSelectionName' => $stripFromSelectionName,
87 'errorMode' => $errorMode
88 );
89
90 $subject->addInlineLanguageLabelFile($fileReference, $selectionPrefix, $stripFromSelectionName, $errorMode);
91 $actualResult = $subject->getInlineLanguageLabelFiles();
92
93 $this->assertSame($expectedInlineLanguageLabelFile, array_pop($actualResult));
94 }
95
96 /**
97 * @test
98 */
99 public function addInlineLanguageLabelFileSetsTwoDifferentInlineLanguageLabelFiles() {
100 /** @var \TYPO3\CMS\Core\Page\PageRenderer|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $subject */
101 $subject = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Page\\PageRenderer', array('dummy'), array(), '', FALSE);
102 $fileReference1 = uniqid('file1_');
103 $selectionPrefix1 = uniqid('prefix1_');
104 $stripFromSelectionName1 = uniqid('strip1_');
105 $errorMode1 = 0;
106 $expectedInlineLanguageLabelFile1 = array(
107 'fileRef' => $fileReference1,
108 'selectionPrefix' => $selectionPrefix1,
109 'stripFromSelectionName' => $stripFromSelectionName1,
110 'errorMode' => $errorMode1
111 );
112 $fileReference2 = uniqid('file2_');
113 $selectionPrefix2 = uniqid('prefix2_');
114 $stripFromSelectionName2 = uniqid('strip2_');
115 $errorMode2 = 0;
116 $expectedInlineLanguageLabelFile2 = array(
117 'fileRef' => $fileReference2,
118 'selectionPrefix' => $selectionPrefix2,
119 'stripFromSelectionName' => $stripFromSelectionName2,
120 'errorMode' => $errorMode2
121 );
122
123 $subject->addInlineLanguageLabelFile($fileReference1, $selectionPrefix1, $stripFromSelectionName1, $errorMode1);
124 $subject->addInlineLanguageLabelFile($fileReference2, $selectionPrefix2, $stripFromSelectionName2, $errorMode2);
125 $actualResult = $subject->getInlineLanguageLabelFiles();
126
127 $this->assertSame($expectedInlineLanguageLabelFile2, array_pop($actualResult));
128 $this->assertSame($expectedInlineLanguageLabelFile1, array_pop($actualResult));
129 }
130
131 /**
132 * @test
133 */
134 public function addInlineLanguageLabelFileDoesNotSetSameLanguageFileTwice() {
135 /** @var \TYPO3\CMS\Core\Page\PageRenderer|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $subject */
136 $subject = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Page\\PageRenderer', array('dummy'), array(), '', FALSE);
137 $fileReference = uniqid('file2_');
138 $selectionPrefix = uniqid('prefix2_');
139 $stripFromSelectionName = uniqid('strip2_');
140 $errorMode = 0;
141
142 $subject->addInlineLanguageLabelFile($fileReference, $selectionPrefix, $stripFromSelectionName, $errorMode);
143 $subject->addInlineLanguageLabelFile($fileReference, $selectionPrefix, $stripFromSelectionName, $errorMode);
144 $this->assertSame(1, count($subject->getInlineLanguageLabelFiles()));
145 }
146 }