TYPO3 CMS  TYPO3_8-7
PageRendererTest.php
Go to the documentation of this file.
1 <?php
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 
18 
24 class PageRendererTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
25 {
30  {
31  $pageRenderer = $this->getMockBuilder(\TYPO3\CMS\Core\Page\PageRenderer::class)
32  ->setMethods(['reset', 'prepareRendering', 'renderJavaScriptAndCss', 'getPreparedMarkerArray', 'getTemplateForPart'])
33  ->getMock();
34  $pageRenderer->expects($this->exactly(3))->method('reset');
35 
36  $pageRenderer->render(PageRenderer::PART_COMPLETE);
37  $pageRenderer->render(PageRenderer::PART_HEADER);
38  $pageRenderer->render(PageRenderer::PART_FOOTER);
39  }
40 
44  public function includingNotAvailableLocalJqueryVersionThrowsException()
45  {
46  $this->expectException(\UnexpectedValueException::class);
47  $this->expectExceptionCode(1341505305);
48 
50  $subject = $this->getAccessibleMock(\TYPO3\CMS\Core\Page\PageRenderer::class, ['dummy'], [], '', false);
51  $subject->_set('availableLocalJqueryVersions', ['1.1.1']);
52  $subject->loadJquery('2.2.2');
53  }
54 
58  public function includingJqueryWithNonAlphnumericNamespaceThrowsException()
59  {
60  $this->expectException(\UnexpectedValueException::class);
61  $this->expectExceptionCode(1341571604);
62 
64  $subject = $this->getAccessibleMock(\TYPO3\CMS\Core\Page\PageRenderer::class, ['dummy'], [], '', false);
65  $subject->loadJquery(null, null, '12sd.12fsd');
66  $subject->render();
67  }
68 
72  public function addBodyContentAddsContent()
73  {
75  $subject = $this->getAccessibleMock(\TYPO3\CMS\Core\Page\PageRenderer::class, ['dummy'], [], '', false);
76  $expectedReturnValue = 'ABCDE';
77  $subject->addBodyContent('A');
78  $subject->addBodyContent('B');
79  $subject->addBodyContent('C');
80  $subject->addBodyContent('D');
81  $subject->addBodyContent('E');
82  $out = $subject->getBodyContent();
83  $this->assertEquals($expectedReturnValue, $out);
84  }
85 
89  public function addInlineLanguageLabelFileSetsInlineLanguageLabelFiles()
90  {
92  $subject = $this->getAccessibleMock(\TYPO3\CMS\Core\Page\PageRenderer::class, ['dummy'], [], '', false);
93  $fileReference = $this->getUniqueId('file_');
94  $selectionPrefix = $this->getUniqueId('prefix_');
95  $stripFromSelectionName = $this->getUniqueId('strip_');
96  $errorMode = 0;
97 
98  $expectedInlineLanguageLabelFile = [
99  'fileRef' => $fileReference,
100  'selectionPrefix' => $selectionPrefix,
101  'stripFromSelectionName' => $stripFromSelectionName,
102  'errorMode' => $errorMode
103  ];
104 
105  $subject->addInlineLanguageLabelFile($fileReference, $selectionPrefix, $stripFromSelectionName, $errorMode);
106  $actualResult = $subject->getInlineLanguageLabelFiles();
107 
108  $this->assertSame($expectedInlineLanguageLabelFile, array_pop($actualResult));
109  }
110 
114  public function addInlineLanguageLabelFileSetsTwoDifferentInlineLanguageLabelFiles()
115  {
117  $subject = $this->getAccessibleMock(\TYPO3\CMS\Core\Page\PageRenderer::class, ['dummy'], [], '', false);
118  $fileReference1 = $this->getUniqueId('file1_');
119  $selectionPrefix1 = $this->getUniqueId('prefix1_');
120  $stripFromSelectionName1 = $this->getUniqueId('strip1_');
121  $errorMode1 = 0;
122  $expectedInlineLanguageLabelFile1 = [
123  'fileRef' => $fileReference1,
124  'selectionPrefix' => $selectionPrefix1,
125  'stripFromSelectionName' => $stripFromSelectionName1,
126  'errorMode' => $errorMode1
127  ];
128  $fileReference2 = $this->getUniqueId('file2_');
129  $selectionPrefix2 = $this->getUniqueId('prefix2_');
130  $stripFromSelectionName2 = $this->getUniqueId('strip2_');
131  $errorMode2 = 0;
132  $expectedInlineLanguageLabelFile2 = [
133  'fileRef' => $fileReference2,
134  'selectionPrefix' => $selectionPrefix2,
135  'stripFromSelectionName' => $stripFromSelectionName2,
136  'errorMode' => $errorMode2
137  ];
138 
139  $subject->addInlineLanguageLabelFile($fileReference1, $selectionPrefix1, $stripFromSelectionName1, $errorMode1);
140  $subject->addInlineLanguageLabelFile($fileReference2, $selectionPrefix2, $stripFromSelectionName2, $errorMode2);
141  $actualResult = $subject->getInlineLanguageLabelFiles();
142 
143  $this->assertSame($expectedInlineLanguageLabelFile2, array_pop($actualResult));
144  $this->assertSame($expectedInlineLanguageLabelFile1, array_pop($actualResult));
145  }
146 
150  public function addInlineLanguageLabelFileDoesNotSetSameLanguageFileTwice()
151  {
153  $subject = $this->getAccessibleMock(\TYPO3\CMS\Core\Page\PageRenderer::class, ['dummy'], [], '', false);
154  $fileReference = $this->getUniqueId('file2_');
155  $selectionPrefix = $this->getUniqueId('prefix2_');
156  $stripFromSelectionName = $this->getUniqueId('strip2_');
157  $errorMode = 0;
158 
159  $subject->addInlineLanguageLabelFile($fileReference, $selectionPrefix, $stripFromSelectionName, $errorMode);
160  $subject->addInlineLanguageLabelFile($fileReference, $selectionPrefix, $stripFromSelectionName, $errorMode);
161  $this->assertSame(1, count($subject->getInlineLanguageLabelFiles()));
162  }
163 
167  public function includeLanguageFileForInlineThrowsExceptionIfLangIsNotSet()
168  {
169  $this->expectException(\RuntimeException::class);
170  $this->expectExceptionCode(1284906026);
171 
173  $subject = $this->getAccessibleMock(\TYPO3\CMS\Core\Page\PageRenderer::class, ['dummy'], [], '', false);
174  $subject->_set('charSet', 'utf-8');
175  $subject->_call('includeLanguageFileForInline', 'someLLFile.xml');
176  }
177 
181  public function includeLanguageFileForInlineThrowsExceptionIfCharSetIsNotSet()
182  {
183  $this->expectException(\RuntimeException::class);
184  $this->expectExceptionCode(1284906026);
185 
187  $subject = $this->getAccessibleMock(\TYPO3\CMS\Core\Page\PageRenderer::class, ['dummy'], [], '', false);
188  $subject->_set('lang', 'default');
189  $subject->_call('includeLanguageFileForInline', 'someLLFile.xml');
190  }
191 
195  public function includeLanguageFileForInlineDoesNotAddToInlineLanguageLabelsIfFileCouldNotBeRead()
196  {
198  $subject = $this->getAccessibleMock(\TYPO3\CMS\Core\Page\PageRenderer::class, ['readLLfile'], [], '', false);
199  $subject->_set('lang', 'default');
200  $subject->_set('charSet', 'utf-8');
201  $subject->_set('inlineLanguageLabels', []);
202  $subject->method('readLLfile')->willReturn(false);
203  $subject->_call('includeLanguageFileForInline', 'someLLFile.xml');
204  $this->assertEquals([], $subject->_get('inlineLanguageLabels'));
205  }
206 
211  {
212  $llFileContent = [
213  'default' => [
214  'inline_label_first_Key' => 'first',
215  'inline_label_second_Key' => 'second',
216  'thirdKey' => 'third'
217  ]
218  ];
219  return [
220  'No processing' => [
221  $llFileContent,
222  '',
223  '',
224  $llFileContent['default']
225  ],
226  'Respect $selectionPrefix' => [
227  $llFileContent,
228  'inline_',
229  '',
230  [
231  'inline_label_first_Key' => 'first',
232  'inline_label_second_Key' => 'second'
233  ]
234  ],
235  'Respect $stripFromSelectionName' => [
236  $llFileContent,
237  '',
238  'inline_',
239  [
240  'label_first_Key' => 'first',
241  'label_second_Key' => 'second',
242  'thirdKey' => 'third'
243  ]
244  ],
245  'Respect $selectionPrefix and $stripFromSelectionName' => [
246  $llFileContent,
247  'inline_',
248  'inline_label_',
249  [
250  'first_Key' => 'first',
251  'second_Key' => 'second'
252  ]
253  ],
254  ];
255  }
256 
261  public function includeLanguageFileForInlineAddsProcessesLabelsToInlineLanguageLabels($llFileContent, $selectionPrefix, $stripFromSelectionName, $expectation)
262  {
264  $subject = $this->getAccessibleMock(\TYPO3\CMS\Core\Page\PageRenderer::class, ['readLLfile'], [], '', false);
265  $subject->_set('lang', 'default');
266  $subject->_set('charSet', 'utf-8');
267  $subject->_set('inlineLanguageLabels', []);
268  $subject->method('readLLfile')->willReturn($llFileContent);
269  $subject->_call('includeLanguageFileForInline', 'someLLFile.xml', $selectionPrefix, $stripFromSelectionName);
270  $this->assertEquals($expectation, $subject->_get('inlineLanguageLabels'));
271  }
272 }