‪TYPO3CMS  10.4
PageRendererTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪PageRendererTest extends UnitTestCase
27 {
32  {
33  $this->resetSingletonInstances = true;
34  $tsfe = $this->prophesize(TypoScriptFrontendController::class);
35 
36  $pageRenderer = $this->getMockBuilder(PageRenderer::class)
37  ->setMethods(['reset', 'prepareRendering', 'renderJavaScriptAndCss', 'getPreparedMarkerArray', 'getTemplateForPart', 'getTypoScriptFrontendController'])
38  ->getMock();
39  $pageRenderer->expects(self::any())->method('getTypoScriptFrontendController')->willReturn($tsfe->reveal());
40  $pageRenderer->expects(self::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 
50  public function ‪addBodyContentAddsContent()
51  {
53  $subject = $this->getAccessibleMock(PageRenderer::class, ['dummy'], [], '', false);
54  $expectedReturnValue = 'ABCDE';
55  $subject->addBodyContent('A');
56  $subject->addBodyContent('B');
57  $subject->addBodyContent('C');
58  $subject->addBodyContent('D');
59  $subject->addBodyContent('E');
60  $out = $subject->getBodyContent();
61  self::assertEquals($expectedReturnValue, $out);
62  }
63 
68  {
70  $subject = $this->getAccessibleMock(PageRenderer::class, ['dummy'], [], '', false);
71  $fileReference = ‪StringUtility::getUniqueId('file_');
72  $selectionPrefix = ‪StringUtility::getUniqueId('prefix_');
73  $stripFromSelectionName = ‪StringUtility::getUniqueId('strip_');
74 
75  $expectedInlineLanguageLabelFile = [
76  'fileRef' => $fileReference,
77  'selectionPrefix' => $selectionPrefix,
78  'stripFromSelectionName' => $stripFromSelectionName
79  ];
80 
81  $subject->addInlineLanguageLabelFile($fileReference, $selectionPrefix, $stripFromSelectionName);
82  $actualResult = $subject->getInlineLanguageLabelFiles();
83 
84  self::assertSame($expectedInlineLanguageLabelFile, array_pop($actualResult));
85  }
86 
91  {
93  $subject = $this->getAccessibleMock(PageRenderer::class, ['dummy'], [], '', false);
94  $fileReference1 = ‪StringUtility::getUniqueId('file1_');
95  $selectionPrefix1 = ‪StringUtility::getUniqueId('prefix1_');
96  $stripFromSelectionName1 = ‪StringUtility::getUniqueId('strip1_');
97  $expectedInlineLanguageLabelFile1 = [
98  'fileRef' => $fileReference1,
99  'selectionPrefix' => $selectionPrefix1,
100  'stripFromSelectionName' => $stripFromSelectionName1
101  ];
102  $fileReference2 = ‪StringUtility::getUniqueId('file2_');
103  $selectionPrefix2 = ‪StringUtility::getUniqueId('prefix2_');
104  $stripFromSelectionName2 = ‪StringUtility::getUniqueId('strip2_');
105  $expectedInlineLanguageLabelFile2 = [
106  'fileRef' => $fileReference2,
107  'selectionPrefix' => $selectionPrefix2,
108  'stripFromSelectionName' => $stripFromSelectionName2
109  ];
110 
111  $subject->addInlineLanguageLabelFile($fileReference1, $selectionPrefix1, $stripFromSelectionName1);
112  $subject->addInlineLanguageLabelFile($fileReference2, $selectionPrefix2, $stripFromSelectionName2);
113  $actualResult = $subject->getInlineLanguageLabelFiles();
114 
115  self::assertSame($expectedInlineLanguageLabelFile2, array_pop($actualResult));
116  self::assertSame($expectedInlineLanguageLabelFile1, array_pop($actualResult));
117  }
118 
123  {
125  $subject = $this->getAccessibleMock(PageRenderer::class, ['dummy'], [], '', false);
126  $fileReference = ‪StringUtility::getUniqueId('file2_');
127  $selectionPrefix = ‪StringUtility::getUniqueId('prefix2_');
128  $stripFromSelectionName = ‪StringUtility::getUniqueId('strip2_');
129 
130  $subject->addInlineLanguageLabelFile($fileReference, $selectionPrefix, $stripFromSelectionName);
131  $subject->addInlineLanguageLabelFile($fileReference, $selectionPrefix, $stripFromSelectionName);
132  self::assertSame(1, count($subject->getInlineLanguageLabelFiles()));
133  }
134 
139  {
140  $this->expectException(\RuntimeException::class);
141  $this->expectExceptionCode(1284906026);
142 
144  $subject = $this->getAccessibleMock(PageRenderer::class, ['dummy'], [], '', false);
145  $subject->_set('charSet', 'utf-8');
146  $subject->_call('includeLanguageFileForInline', 'someLLFile.xml');
147  }
148 
153  {
154  $this->expectException(\RuntimeException::class);
155  $this->expectExceptionCode(1284906026);
156 
158  $subject = $this->getAccessibleMock(PageRenderer::class, ['dummy'], [], '', false);
159  $subject->_set('lang', 'default');
160  $subject->_call('includeLanguageFileForInline', 'someLLFile.xml');
161  }
162 
167  {
169  $subject = $this->getAccessibleMock(PageRenderer::class, ['readLLfile'], [], '', false);
170  $subject->_set('lang', 'default');
171  $subject->_set('charSet', 'utf-8');
172  $subject->_set('inlineLanguageLabels', []);
173  $subject->method('readLLfile')->willReturn(false);
174  $subject->_call('includeLanguageFileForInline', 'someLLFile.xml');
175  self::assertEquals([], $subject->_get('inlineLanguageLabels'));
176  }
177 
182  {
183  $llFileContent = [
184  'default' => [
185  'inline_label_first_Key' => 'first',
186  'inline_label_second_Key' => 'second',
187  'thirdKey' => 'third'
188  ]
189  ];
190  return [
191  'No processing' => [
192  $llFileContent,
193  '',
194  '',
195  $llFileContent['default']
196  ],
197  'Respect $selectionPrefix' => [
198  $llFileContent,
199  'inline_',
200  '',
201  [
202  'inline_label_first_Key' => 'first',
203  'inline_label_second_Key' => 'second'
204  ]
205  ],
206  'Respect $stripFromSelectionName' => [
207  $llFileContent,
208  '',
209  'inline_',
210  [
211  'label_first_Key' => 'first',
212  'label_second_Key' => 'second',
213  'thirdKey' => 'third'
214  ]
215  ],
216  'Respect $selectionPrefix and $stripFromSelectionName' => [
217  $llFileContent,
218  'inline_',
219  'inline_label_',
220  [
221  'first_Key' => 'first',
222  'second_Key' => 'second'
223  ]
224  ],
225  ];
226  }
227 
232  public function ‪includeLanguageFileForInlineAddsProcessesLabelsToInlineLanguageLabels($llFileContent, $selectionPrefix, $stripFromSelectionName, $expectation)
233  {
235  $subject = $this->getAccessibleMock(PageRenderer::class, ['readLLfile'], [], '', false);
236  $subject->_set('lang', 'default');
237  $subject->_set('charSet', 'utf-8');
238  $subject->_set('inlineLanguageLabels', []);
239  $subject->method('readLLfile')->willReturn($llFileContent);
240  $subject->_call('includeLanguageFileForInline', 'someLLFile.xml', $selectionPrefix, $stripFromSelectionName);
241  self::assertEquals($expectation, $subject->_get('inlineLanguageLabels'));
242  }
243 
247  public function ‪getAddedMetaTag()
248  {
249  $this->resetSingletonInstances = true;
251  $subject = $this->getAccessibleMock(PageRenderer::class, ['whatDoesThisDo']);
252  $subject->setMetaTag('nAme', 'Author', 'foobar');
253  $actualResult = $subject->getMetaTag('naMe', 'AUTHOR');
254  $expectedResult = [
255  'type' => 'name',
256  'name' => 'author',
257  'content' => 'foobar'
258  ];
259  self::assertSame($expectedResult, $actualResult);
260  }
261 
265  public function ‪overrideMetaTag()
266  {
267  $this->resetSingletonInstances = true;
269  $subject = $this->getAccessibleMock(PageRenderer::class, ['whatDoesThisDo']);
270  $subject->setMetaTag('nAme', 'Author', 'Axel Foley');
271  $subject->setMetaTag('nAme', 'Author', 'foobar');
272  $actualResult = $subject->getMetaTag('naMe', 'AUTHOR');
273  $expectedResult = [
274  'type' => 'name',
275  'name' => 'author',
276  'content' => 'foobar'
277  ];
278  self::assertSame($expectedResult, $actualResult);
279  }
280 
284  public function ‪unsetAddedMetaTag()
285  {
286  $this->resetSingletonInstances = true;
288  $subject = $this->getAccessibleMock(PageRenderer::class, ['whatDoesThisDo']);
289  $subject->setMetaTag('nAme', 'Author', 'foobar');
290  $subject->removeMetaTag('naMe', 'AUTHOR');
291  $actualResult = $subject->getMetaTag('naMe', 'AUTHOR');
292  $expectedResult = [];
293  self::assertSame($expectedResult, $actualResult);
294  }
295 
300  {
301  $subject = $this->getAccessibleMock(PageRenderer::class, ['dummy'], [], '', false);
302  $inlineLanguageLabels = [];
303  $subject->_set('inlineLanguageLabels', $inlineLanguageLabels);
304  $actual = $subject->_call('parseLanguageLabelsForJavaScript');
305  self::assertEmpty($actual);
306  }
307 
312  {
313  $subject = $this->getAccessibleMock(PageRenderer::class, ['dummy'], [], '', false);
314  $inlineLanguageLabels = [
315  'key' => 'label',
316  'foo' => 'bar',
317  'husel' => [
318  [
319  'source' => 'pusel',
320  ]
321  ],
322  'hello' => [
323  [
324  'source' => 'world',
325  'target' => 'welt',
326  ]
327  ],
328  ];
329  $subject->_set('inlineLanguageLabels', $inlineLanguageLabels);
330  $expected = [
331  'key' => 'label',
332  'foo' => 'bar',
333  'husel' => 'pusel',
334  'hello' => 'welt',
335  ];
336  $actual = $subject->_call('parseLanguageLabelsForJavaScript');
337  self::assertSame($expected, $actual);
338  }
339 }
‪TYPO3\CMS\Core\Tests\Unit\Page
Definition: AssetCollectorTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\renderMethodCallsResetInAnyCase
‪renderMethodCallsResetInAnyCase()
Definition: PageRendererTest.php:31
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest
Definition: PageRendererTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\addInlineLanguageLabelFileSetsInlineLanguageLabelFiles
‪addInlineLanguageLabelFileSetsInlineLanguageLabelFiles()
Definition: PageRendererTest.php:67
‪TYPO3\CMS\Core\Page\PageRenderer\PART_COMPLETE
‪const PART_COMPLETE
Definition: PageRenderer.php:44
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\addInlineLanguageLabelFileSetsTwoDifferentInlineLanguageLabelFiles
‪addInlineLanguageLabelFileSetsTwoDifferentInlineLanguageLabelFiles()
Definition: PageRendererTest.php:90
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\unsetAddedMetaTag
‪unsetAddedMetaTag()
Definition: PageRendererTest.php:284
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\addBodyContentAddsContent
‪addBodyContentAddsContent()
Definition: PageRendererTest.php:50
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\includeLanguageFileForInlineThrowsExceptionIfCharSetIsNotSet
‪includeLanguageFileForInlineThrowsExceptionIfCharSetIsNotSet()
Definition: PageRendererTest.php:152
‪TYPO3\CMS\Core\Page\PageRenderer
Definition: PageRenderer.php:42
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\addInlineLanguageLabelFileDoesNotSetSameLanguageFileTwice
‪addInlineLanguageLabelFileDoesNotSetSameLanguageFileTwice()
Definition: PageRendererTest.php:122
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\getAddedMetaTag
‪getAddedMetaTag()
Definition: PageRendererTest.php:247
‪TYPO3\CMS\Core\Page\PageRenderer\PART_FOOTER
‪const PART_FOOTER
Definition: PageRenderer.php:46
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\parseLanguageLabelsForJavaScriptReturnsFlatArray
‪parseLanguageLabelsForJavaScriptReturnsFlatArray()
Definition: PageRendererTest.php:311
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\includeLanguageFileForInlineDoesNotAddToInlineLanguageLabelsIfFileCouldNotBeRead
‪includeLanguageFileForInlineDoesNotAddToInlineLanguageLabelsIfFileCouldNotBeRead()
Definition: PageRendererTest.php:166
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static string getUniqueId($prefix='')
Definition: StringUtility.php:92
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:98
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\includeLanguageFileForInlineThrowsExceptionIfLangIsNotSet
‪includeLanguageFileForInlineThrowsExceptionIfLangIsNotSet()
Definition: PageRendererTest.php:138
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\overrideMetaTag
‪overrideMetaTag()
Definition: PageRendererTest.php:265
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\parseLanguageLabelsForJavaScriptReturnsEmptyStringIfEmpty
‪parseLanguageLabelsForJavaScriptReturnsEmptyStringIfEmpty()
Definition: PageRendererTest.php:299
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\includeLanguageFileForInlineAddsProcessesLabelsToInlineLanguageLabels
‪includeLanguageFileForInlineAddsProcessesLabelsToInlineLanguageLabels($llFileContent, $selectionPrefix, $stripFromSelectionName, $expectation)
Definition: PageRendererTest.php:232
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:22
‪TYPO3\CMS\Core\Page\PageRenderer\PART_HEADER
‪const PART_HEADER
Definition: PageRenderer.php:45
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\includeLanguageFileForInlineAddsProcessesLabelsToInlineLanguageLabelsProvider
‪array includeLanguageFileForInlineAddsProcessesLabelsToInlineLanguageLabelsProvider()
Definition: PageRendererTest.php:181