‪TYPO3CMS  9.5
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 
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20 
24 class ‪PageRendererTest extends UnitTestCase
25 {
30  {
31  $this->resetSingletonInstances = true;
32  $tsfe = $this->prophesize(TypoScriptFrontendController::class);
33 
34  $pageRenderer = $this->getMockBuilder(PageRenderer::class)
35  ->setMethods(['reset', 'prepareRendering', 'renderJavaScriptAndCss', 'getPreparedMarkerArray', 'getTemplateForPart', 'getTypoScriptFrontendController'])
36  ->getMock();
37  $pageRenderer->expects($this->any())->method('getTypoScriptFrontendController')->willReturn($tsfe->reveal());
38  $pageRenderer->expects($this->exactly(3))->method('reset');
39 
40  $pageRenderer->render(‪PageRenderer::PART_COMPLETE);
41  $pageRenderer->render(‪PageRenderer::PART_HEADER);
42  $pageRenderer->render(‪PageRenderer::PART_FOOTER);
43  }
44 
48  public function ‪addBodyContentAddsContent()
49  {
51  $subject = $this->getAccessibleMock(PageRenderer::class, ['dummy'], [], '', false);
52  $expectedReturnValue = 'ABCDE';
53  $subject->addBodyContent('A');
54  $subject->addBodyContent('B');
55  $subject->addBodyContent('C');
56  $subject->addBodyContent('D');
57  $subject->addBodyContent('E');
58  $out = $subject->getBodyContent();
59  $this->assertEquals($expectedReturnValue, $out);
60  }
61 
66  {
68  $subject = $this->getAccessibleMock(PageRenderer::class, ['dummy'], [], '', false);
69  $fileReference = $this->getUniqueId('file_');
70  $selectionPrefix = $this->getUniqueId('prefix_');
71  $stripFromSelectionName = $this->getUniqueId('strip_');
72 
73  $expectedInlineLanguageLabelFile = [
74  'fileRef' => $fileReference,
75  'selectionPrefix' => $selectionPrefix,
76  'stripFromSelectionName' => $stripFromSelectionName
77  ];
78 
79  $subject->addInlineLanguageLabelFile($fileReference, $selectionPrefix, $stripFromSelectionName);
80  $actualResult = $subject->getInlineLanguageLabelFiles();
81 
82  $this->assertSame($expectedInlineLanguageLabelFile, array_pop($actualResult));
83  }
84 
89  {
91  $subject = $this->getAccessibleMock(PageRenderer::class, ['dummy'], [], '', false);
92  $fileReference1 = $this->getUniqueId('file1_');
93  $selectionPrefix1 = $this->getUniqueId('prefix1_');
94  $stripFromSelectionName1 = $this->getUniqueId('strip1_');
95  $expectedInlineLanguageLabelFile1 = [
96  'fileRef' => $fileReference1,
97  'selectionPrefix' => $selectionPrefix1,
98  'stripFromSelectionName' => $stripFromSelectionName1
99  ];
100  $fileReference2 = $this->getUniqueId('file2_');
101  $selectionPrefix2 = $this->getUniqueId('prefix2_');
102  $stripFromSelectionName2 = $this->getUniqueId('strip2_');
103  $expectedInlineLanguageLabelFile2 = [
104  'fileRef' => $fileReference2,
105  'selectionPrefix' => $selectionPrefix2,
106  'stripFromSelectionName' => $stripFromSelectionName2
107  ];
108 
109  $subject->addInlineLanguageLabelFile($fileReference1, $selectionPrefix1, $stripFromSelectionName1);
110  $subject->addInlineLanguageLabelFile($fileReference2, $selectionPrefix2, $stripFromSelectionName2);
111  $actualResult = $subject->getInlineLanguageLabelFiles();
112 
113  $this->assertSame($expectedInlineLanguageLabelFile2, array_pop($actualResult));
114  $this->assertSame($expectedInlineLanguageLabelFile1, array_pop($actualResult));
115  }
116 
121  {
123  $subject = $this->getAccessibleMock(PageRenderer::class, ['dummy'], [], '', false);
124  $fileReference = $this->getUniqueId('file2_');
125  $selectionPrefix = $this->getUniqueId('prefix2_');
126  $stripFromSelectionName = $this->getUniqueId('strip2_');
127 
128  $subject->addInlineLanguageLabelFile($fileReference, $selectionPrefix, $stripFromSelectionName);
129  $subject->addInlineLanguageLabelFile($fileReference, $selectionPrefix, $stripFromSelectionName);
130  $this->assertSame(1, count($subject->getInlineLanguageLabelFiles()));
131  }
132 
137  {
138  $this->expectException(\RuntimeException::class);
139  $this->expectExceptionCode(1284906026);
140 
142  $subject = $this->getAccessibleMock(PageRenderer::class, ['dummy'], [], '', false);
143  $subject->_set('charSet', 'utf-8');
144  $subject->_call('includeLanguageFileForInline', 'someLLFile.xml');
145  }
146 
151  {
152  $this->expectException(\RuntimeException::class);
153  $this->expectExceptionCode(1284906026);
154 
156  $subject = $this->getAccessibleMock(PageRenderer::class, ['dummy'], [], '', false);
157  $subject->_set('lang', 'default');
158  $subject->_call('includeLanguageFileForInline', 'someLLFile.xml');
159  }
160 
165  {
167  $subject = $this->getAccessibleMock(PageRenderer::class, ['readLLfile'], [], '', false);
168  $subject->_set('lang', 'default');
169  $subject->_set('charSet', 'utf-8');
170  $subject->_set('inlineLanguageLabels', []);
171  $subject->method('readLLfile')->willReturn(false);
172  $subject->_call('includeLanguageFileForInline', 'someLLFile.xml');
173  $this->assertEquals([], $subject->_get('inlineLanguageLabels'));
174  }
175 
180  {
181  $llFileContent = [
182  'default' => [
183  'inline_label_first_Key' => 'first',
184  'inline_label_second_Key' => 'second',
185  'thirdKey' => 'third'
186  ]
187  ];
188  return [
189  'No processing' => [
190  $llFileContent,
191  '',
192  '',
193  $llFileContent['default']
194  ],
195  'Respect $selectionPrefix' => [
196  $llFileContent,
197  'inline_',
198  '',
199  [
200  'inline_label_first_Key' => 'first',
201  'inline_label_second_Key' => 'second'
202  ]
203  ],
204  'Respect $stripFromSelectionName' => [
205  $llFileContent,
206  '',
207  'inline_',
208  [
209  'label_first_Key' => 'first',
210  'label_second_Key' => 'second',
211  'thirdKey' => 'third'
212  ]
213  ],
214  'Respect $selectionPrefix and $stripFromSelectionName' => [
215  $llFileContent,
216  'inline_',
217  'inline_label_',
218  [
219  'first_Key' => 'first',
220  'second_Key' => 'second'
221  ]
222  ],
223  ];
224  }
225 
230  public function ‪includeLanguageFileForInlineAddsProcessesLabelsToInlineLanguageLabels($llFileContent, $selectionPrefix, $stripFromSelectionName, $expectation)
231  {
233  $subject = $this->getAccessibleMock(PageRenderer::class, ['readLLfile'], [], '', false);
234  $subject->_set('lang', 'default');
235  $subject->_set('charSet', 'utf-8');
236  $subject->_set('inlineLanguageLabels', []);
237  $subject->method('readLLfile')->willReturn($llFileContent);
238  $subject->_call('includeLanguageFileForInline', 'someLLFile.xml', $selectionPrefix, $stripFromSelectionName);
239  $this->assertEquals($expectation, $subject->_get('inlineLanguageLabels'));
240  }
241 
245  public function ‪getAddedMetaTag()
246  {
247  $this->resetSingletonInstances = true;
249  $subject = $this->getAccessibleMock(PageRenderer::class, ['whatDoesThisDo']);
250  $subject->setMetaTag('nAme', 'Author', 'foobar');
251  $actualResult = $subject->getMetaTag('naMe', 'AUTHOR');
252  $expectedResult = [
253  'type' => 'name',
254  'name' => 'author',
255  'content' => 'foobar'
256  ];
257  $this->assertSame($expectedResult, $actualResult);
258  }
259 
263  public function ‪overrideMetaTag()
264  {
265  $this->resetSingletonInstances = true;
267  $subject = $this->getAccessibleMock(PageRenderer::class, ['whatDoesThisDo']);
268  $subject->setMetaTag('nAme', 'Author', 'Axel Foley');
269  $subject->setMetaTag('nAme', 'Author', 'foobar');
270  $actualResult = $subject->getMetaTag('naMe', 'AUTHOR');
271  $expectedResult = [
272  'type' => 'name',
273  'name' => 'author',
274  'content' => 'foobar'
275  ];
276  $this->assertSame($expectedResult, $actualResult);
277  }
278 
282  public function ‪unsetAddedMetaTag()
283  {
284  $this->resetSingletonInstances = true;
286  $subject = $this->getAccessibleMock(PageRenderer::class, ['whatDoesThisDo']);
287  $subject->setMetaTag('nAme', 'Author', 'foobar');
288  $subject->removeMetaTag('naMe', 'AUTHOR');
289  $actualResult = $subject->getMetaTag('naMe', 'AUTHOR');
290  $expectedResult = [];
291  $this->assertSame($expectedResult, $actualResult);
292  }
293 
298  {
299  $subject = $this->getAccessibleMock(PageRenderer::class, ['dummy'], [], '', false);
300  $inlineLanguageLabels = [];
301  $subject->_set('inlineLanguageLabels', $inlineLanguageLabels);
302  $actual = $subject->_call('parseLanguageLabelsForJavaScript');
303  $this->assertEmpty($actual);
304  }
305 
310  {
311  $subject = $this->getAccessibleMock(PageRenderer::class, ['dummy'], [], '', false);
312  $inlineLanguageLabels = [
313  'key' => 'label',
314  'foo' => 'bar',
315  'husel' => [
316  [
317  'source' => 'pusel',
318  ]
319  ],
320  'hello' => [
321  [
322  'source' => 'world',
323  'target' => 'welt',
324  ]
325  ],
326  ];
327  $subject->_set('inlineLanguageLabels', $inlineLanguageLabels);
328  $expected = [
329  'key' => 'label',
330  'foo' => 'bar',
331  'husel' => 'pusel',
332  'hello' => 'welt',
333  ];
334  $actual = $subject->_call('parseLanguageLabelsForJavaScript');
335  $this->assertSame($expected, $actual);
336  }
337 }
‪TYPO3\CMS\Core\Tests\Unit\Page
Definition: PageRendererTest.php:2
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\renderMethodCallsResetInAnyCase
‪renderMethodCallsResetInAnyCase()
Definition: PageRendererTest.php:29
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest
Definition: PageRendererTest.php:25
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\addInlineLanguageLabelFileSetsInlineLanguageLabelFiles
‪addInlineLanguageLabelFileSetsInlineLanguageLabelFiles()
Definition: PageRendererTest.php:65
‪TYPO3\CMS\Core\Page\PageRenderer\PART_COMPLETE
‪const PART_COMPLETE
Definition: PageRenderer.php:37
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\addInlineLanguageLabelFileSetsTwoDifferentInlineLanguageLabelFiles
‪addInlineLanguageLabelFileSetsTwoDifferentInlineLanguageLabelFiles()
Definition: PageRendererTest.php:88
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\unsetAddedMetaTag
‪unsetAddedMetaTag()
Definition: PageRendererTest.php:282
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\addBodyContentAddsContent
‪addBodyContentAddsContent()
Definition: PageRendererTest.php:48
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\includeLanguageFileForInlineThrowsExceptionIfCharSetIsNotSet
‪includeLanguageFileForInlineThrowsExceptionIfCharSetIsNotSet()
Definition: PageRendererTest.php:150
‪TYPO3\CMS\Core\Page\PageRenderer
Definition: PageRenderer.php:35
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\addInlineLanguageLabelFileDoesNotSetSameLanguageFileTwice
‪addInlineLanguageLabelFileDoesNotSetSameLanguageFileTwice()
Definition: PageRendererTest.php:120
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\getAddedMetaTag
‪getAddedMetaTag()
Definition: PageRendererTest.php:245
‪TYPO3\CMS\Core\Page\PageRenderer\PART_FOOTER
‪const PART_FOOTER
Definition: PageRenderer.php:39
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\parseLanguageLabelsForJavaScriptReturnsFlatArray
‪parseLanguageLabelsForJavaScriptReturnsFlatArray()
Definition: PageRendererTest.php:309
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\includeLanguageFileForInlineDoesNotAddToInlineLanguageLabelsIfFileCouldNotBeRead
‪includeLanguageFileForInlineDoesNotAddToInlineLanguageLabelsIfFileCouldNotBeRead()
Definition: PageRendererTest.php:164
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:97
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\includeLanguageFileForInlineThrowsExceptionIfLangIsNotSet
‪includeLanguageFileForInlineThrowsExceptionIfLangIsNotSet()
Definition: PageRendererTest.php:136
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\overrideMetaTag
‪overrideMetaTag()
Definition: PageRendererTest.php:263
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\parseLanguageLabelsForJavaScriptReturnsEmptyStringIfEmpty
‪parseLanguageLabelsForJavaScriptReturnsEmptyStringIfEmpty()
Definition: PageRendererTest.php:297
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\includeLanguageFileForInlineAddsProcessesLabelsToInlineLanguageLabels
‪includeLanguageFileForInlineAddsProcessesLabelsToInlineLanguageLabels($llFileContent, $selectionPrefix, $stripFromSelectionName, $expectation)
Definition: PageRendererTest.php:230
‪TYPO3\CMS\Core\Page\PageRenderer\PART_HEADER
‪const PART_HEADER
Definition: PageRenderer.php:38
‪TYPO3\CMS\Core\Tests\Unit\Page\PageRendererTest\includeLanguageFileForInlineAddsProcessesLabelsToInlineLanguageLabelsProvider
‪array includeLanguageFileForInlineAddsProcessesLabelsToInlineLanguageLabelsProvider()
Definition: PageRendererTest.php:179