TYPO3 CMS  TYPO3_7-6
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 
25 {
30  {
31  $pageRenderer = $this->getMock(\TYPO3\CMS\Core\Page\PageRenderer::class, ['reset', 'prepareRendering', 'renderJavaScriptAndCss', 'getPreparedMarkerArray', 'getTemplateForPart']);
32  $pageRenderer->expects($this->exactly(3))->method('reset');
33 
34  $pageRenderer->render(PageRenderer::PART_COMPLETE);
35  $pageRenderer->render(PageRenderer::PART_HEADER);
36  $pageRenderer->render(PageRenderer::PART_FOOTER);
37  }
38 
43  public function includingNotAvailableLocalJqueryVersionThrowsException()
44  {
46  $subject = $this->getAccessibleMock(\TYPO3\CMS\Core\Page\PageRenderer::class, ['dummy'], [], '', false);
47  $subject->_set('availableLocalJqueryVersions', ['1.1.1']);
48  $subject->loadJquery('2.2.2');
49  }
50 
55  public function includingJqueryWithNonAlphnumericNamespaceThrowsException()
56  {
58  $subject = $this->getAccessibleMock(\TYPO3\CMS\Core\Page\PageRenderer::class, ['dummy'], [], '', false);
59  $subject->loadJquery(null, null, '12sd.12fsd');
60  $subject->render();
61  }
62 
66  public function addBodyContentAddsContent()
67  {
69  $subject = $this->getAccessibleMock(\TYPO3\CMS\Core\Page\PageRenderer::class, ['dummy'], [], '', false);
70  $expectedReturnValue = 'ABCDE';
71  $subject->addBodyContent('A');
72  $subject->addBodyContent('B');
73  $subject->addBodyContent('C');
74  $subject->addBodyContent('D');
75  $subject->addBodyContent('E');
76  $out = $subject->getBodyContent();
77  $this->assertEquals($expectedReturnValue, $out);
78  }
79 
83  public function addInlineLanguageLabelFileSetsInlineLanguageLabelFiles()
84  {
86  $subject = $this->getAccessibleMock(\TYPO3\CMS\Core\Page\PageRenderer::class, ['dummy'], [], '', false);
87  $fileReference = $this->getUniqueId('file_');
88  $selectionPrefix = $this->getUniqueId('prefix_');
89  $stripFromSelectionName = $this->getUniqueId('strip_');
90  $errorMode = 0;
91 
92  $expectedInlineLanguageLabelFile = [
93  'fileRef' => $fileReference,
94  'selectionPrefix' => $selectionPrefix,
95  'stripFromSelectionName' => $stripFromSelectionName,
96  'errorMode' => $errorMode
97  ];
98 
99  $subject->addInlineLanguageLabelFile($fileReference, $selectionPrefix, $stripFromSelectionName, $errorMode);
100  $actualResult = $subject->getInlineLanguageLabelFiles();
101 
102  $this->assertSame($expectedInlineLanguageLabelFile, array_pop($actualResult));
103  }
104 
108  public function addInlineLanguageLabelFileSetsTwoDifferentInlineLanguageLabelFiles()
109  {
111  $subject = $this->getAccessibleMock(\TYPO3\CMS\Core\Page\PageRenderer::class, ['dummy'], [], '', false);
112  $fileReference1 = $this->getUniqueId('file1_');
113  $selectionPrefix1 = $this->getUniqueId('prefix1_');
114  $stripFromSelectionName1 = $this->getUniqueId('strip1_');
115  $errorMode1 = 0;
116  $expectedInlineLanguageLabelFile1 = [
117  'fileRef' => $fileReference1,
118  'selectionPrefix' => $selectionPrefix1,
119  'stripFromSelectionName' => $stripFromSelectionName1,
120  'errorMode' => $errorMode1
121  ];
122  $fileReference2 = $this->getUniqueId('file2_');
123  $selectionPrefix2 = $this->getUniqueId('prefix2_');
124  $stripFromSelectionName2 = $this->getUniqueId('strip2_');
125  $errorMode2 = 0;
126  $expectedInlineLanguageLabelFile2 = [
127  'fileRef' => $fileReference2,
128  'selectionPrefix' => $selectionPrefix2,
129  'stripFromSelectionName' => $stripFromSelectionName2,
130  'errorMode' => $errorMode2
131  ];
132 
133  $subject->addInlineLanguageLabelFile($fileReference1, $selectionPrefix1, $stripFromSelectionName1, $errorMode1);
134  $subject->addInlineLanguageLabelFile($fileReference2, $selectionPrefix2, $stripFromSelectionName2, $errorMode2);
135  $actualResult = $subject->getInlineLanguageLabelFiles();
136 
137  $this->assertSame($expectedInlineLanguageLabelFile2, array_pop($actualResult));
138  $this->assertSame($expectedInlineLanguageLabelFile1, array_pop($actualResult));
139  }
140 
144  public function addInlineLanguageLabelFileDoesNotSetSameLanguageFileTwice()
145  {
147  $subject = $this->getAccessibleMock(\TYPO3\CMS\Core\Page\PageRenderer::class, ['dummy'], [], '', false);
148  $fileReference = $this->getUniqueId('file2_');
149  $selectionPrefix = $this->getUniqueId('prefix2_');
150  $stripFromSelectionName = $this->getUniqueId('strip2_');
151  $errorMode = 0;
152 
153  $subject->addInlineLanguageLabelFile($fileReference, $selectionPrefix, $stripFromSelectionName, $errorMode);
154  $subject->addInlineLanguageLabelFile($fileReference, $selectionPrefix, $stripFromSelectionName, $errorMode);
155  $this->assertSame(1, count($subject->getInlineLanguageLabelFiles()));
156  }
157 
162  public function includeLanguageFileForInlineThrowsExceptionIfLangIsNotSet()
163  {
165  $subject = $this->getAccessibleMock(\TYPO3\CMS\Core\Page\PageRenderer::class, ['dummy'], [], '', false);
166  $subject->_set('charSet', 'utf-8');
167  $subject->_call('includeLanguageFileForInline', 'someLLFile.xml');
168  }
169 
174  public function includeLanguageFileForInlineThrowsExceptionIfCharSetIsNotSet()
175  {
177  $subject = $this->getAccessibleMock(\TYPO3\CMS\Core\Page\PageRenderer::class, ['dummy'], [], '', false);
178  $subject->_set('lang', 'default');
179  $subject->_call('includeLanguageFileForInline', 'someLLFile.xml');
180  }
181 
185  public function includeLanguageFileForInlineDoesNotAddToInlineLanguageLabelsIfFileCouldNotBeRead()
186  {
188  $subject = $this->getAccessibleMock(\TYPO3\CMS\Core\Page\PageRenderer::class, ['readLLfile'], [], '', false);
189  $subject->_set('lang', 'default');
190  $subject->_set('charSet', 'utf-8');
191  $subject->_set('inlineLanguageLabels', []);
192  $subject->method('readLLfile')->willReturn(false);
193  $subject->_call('includeLanguageFileForInline', 'someLLFile.xml');
194  $this->assertEquals([], $subject->_get('inlineLanguageLabels'));
195  }
196 
201  {
202  $llFileContent = [
203  'default' => [
204  'inline_label_first_Key' => 'first',
205  'inline_label_second_Key' => 'second',
206  'thirdKey' => 'third'
207  ]
208  ];
209  return [
210  'No processing' => [
211  $llFileContent,
212  '',
213  '',
214  $llFileContent['default']
215  ],
216  'Respect $selectionPrefix' => [
217  $llFileContent,
218  'inline_',
219  '',
220  [
221  'inline_label_first_Key' => 'first',
222  'inline_label_second_Key' => 'second'
223  ]
224  ],
225  'Respect $stripFromSelectionName' => [
226  $llFileContent,
227  '',
228  'inline_',
229  [
230  'label_first_Key' => 'first',
231  'label_second_Key' => 'second',
232  'thirdKey' => 'third'
233  ]
234  ],
235  'Respect $selectionPrefix and $stripFromSelectionName' => [
236  $llFileContent,
237  'inline_',
238  'inline_label_',
239  [
240  'first_Key' => 'first',
241  'second_Key' => 'second'
242  ]
243  ],
244  ];
245  }
246 
251  public function includeLanguageFileForInlineAddsProcessesLabelsToInlineLanguageLabels($llFileContent, $selectionPrefix, $stripFromSelectionName, $expectation)
252  {
254  $subject = $this->getAccessibleMock(\TYPO3\CMS\Core\Page\PageRenderer::class, ['readLLfile'], [], '', false);
255  $subject->_set('lang', 'default');
256  $subject->_set('charSet', 'utf-8');
257  $subject->_set('inlineLanguageLabels', []);
258  $subject->method('readLLfile')->willReturn($llFileContent);
259  $subject->_call('includeLanguageFileForInline', 'someLLFile.xml', $selectionPrefix, $stripFromSelectionName);
260  $this->assertEquals($expectation, $subject->_get('inlineLanguageLabels'));
261  }
262 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)