‪TYPO3CMS  9.5
ContentObjectRendererTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
21 use TYPO3\CMS\Core\Package\PackageManager;
47 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
48 
52 class ‪ContentObjectRendererTest extends UnitTestCase
53 {
55 
59  protected ‪$resetSingletonInstances = true;
60 
64  protected ‪$subject;
65 
70 
74  protected ‪$templateServiceMock;
75 
81  protected ‪$contentObjectMap = [
82  'TEXT' => TextContentObject::class,
83  'CASE' => CaseContentObject::class,
84  'COBJ_ARRAY' => ContentObjectArrayContentObject::class,
85  'COA' => ContentObjectArrayContentObject::class,
86  'COA_INT' => ContentObjectArrayInternalContentObject::class,
87  'USER' => UserContentObject::class,
88  'USER_INT' => UserInternalContentObject::class,
89  'FILE' => FileContentObject::class,
90  'FILES' => FilesContentObject::class,
91  'IMAGE' => ImageContentObject::class,
92  'IMG_RESOURCE' => ImageResourceContentObject::class,
93  'CONTENT' => ContentContentObject::class,
94  'RECORDS' => RecordsContentObject::class,
95  'HMENU' => HierarchicalMenuContentObject::class,
96  'CASEFUNC' => CaseContentObject::class,
97  'LOAD_REGISTER' => LoadRegisterContentObject::class,
98  'RESTORE_REGISTER' => RestoreRegisterContentObject::class,
99  'TEMPLATE' => TemplateContentObject::class,
100  'FLUIDTEMPLATE' => FluidTemplateContentObject::class,
101  'SVG' => ScalableVectorGraphicsContentObject::class,
102  'EDITPANEL' => EditPanelContentObject::class
103  ];
104 
108  protected function ‪setUp(): void
109  {
110  ‪$GLOBALS['SIM_ACCESS_TIME'] = 1534278180;
111  $packageManagerMock = $this->getMockBuilder(PackageManager::class)
112  ->disableOriginalConstructor()
113  ->getMock();
114  $this->templateServiceMock =
115  $this->getMockBuilder(TemplateService::class)
116  ->setConstructorArgs([null, $packageManagerMock])
117  ->setMethods(['linkData'])
118  ->getMock();
119  $pageRepositoryMock =
120  $this->getAccessibleMock(PageRepository::class, ['getRawRecord', 'getMountPointInfo']);
121  $this->frontendControllerMock =
122  $this->getAccessibleMock(
123  TypoScriptFrontendController::class,
124  ['sL'],
125  [],
126  '',
127  false
128  );
129  $this->frontendControllerMock->_set('context', GeneralUtility::makeInstance(Context::class));
130  $this->frontendControllerMock->tmpl = ‪$this->templateServiceMock;
131  $this->frontendControllerMock->config = [];
132  $this->frontendControllerMock->page = [];
133  $this->frontendControllerMock->sys_page = $pageRepositoryMock;
135 
136  $this->subject = $this->getAccessibleMock(
137  ContentObjectRenderer::class,
138  ['getResourceFactory', 'getEnvironmentVariable'],
139  [$this->frontendControllerMock]
140  );
141 
142  $logger = $this->prophesize(Logger::class);
143  $this->subject->setLogger($logger->reveal());
144  $this->subject->setContentObjectClassMap($this->contentObjectMap);
145  $this->subject->start([], 'tt_content');
146  }
147 
149  // Test concerning link generation
151 
156  {
157  $fileNameAndPath = ‪Environment::getPublicPath() . '/typo3temp/var/tests/phpunitJumpUrlTestFile with spaces & amps.txt';
158  file_put_contents($fileNameAndPath, 'Some test data');
159  $relativeFileNameAndPath = substr($fileNameAndPath, strlen(‪Environment::getPublicPath()) + 1);
160  $fileName = substr($fileNameAndPath, strlen(‪Environment::getPublicPath() . '/typo3temp/var/tests/'));
161 
162  $expectedLink = str_replace('%2F', '/', rawurlencode($relativeFileNameAndPath));
163  $result = $this->subject->filelink($fileName, ['path' => 'typo3temp/var/tests/'], true);
164  $this->assertEquals('<a href="' . $expectedLink . '">' . $fileName . '</a>', $result);
165 
166  GeneralUtility::unlink_tempfile($fileNameAndPath);
167  }
168 
181  public function ‪stdWrap_addParams(): void
182  {
183  $content = $this->getUniqueId('content');
184  $conf = [
185  'addParams' => $this->getUniqueId('not used'),
186  'addParams.' => [$this->getUniqueId('addParams.')],
187  ];
188  $return = $this->getUniqueId('return');
189  ‪$subject = $this->getMockBuilder(ContentObjectRenderer::class)
190  ->setMethods(['addParams'])->getMock();
192  ->expects($this->once())
193  ->method('addParams')
194  ->with($content, $conf['addParams.'])
195  ->willReturn($return);
196  $this->assertSame(
197  $return,
198  ‪$subject->‪stdWrap_addParams($content, $conf)
199  );
200  }
201 
214  public function ‪stdWrap_filelink(): void
215  {
216  $content = $this->getUniqueId('content');
217  $conf = [
218  'filelink' => $this->getUniqueId('not used'),
219  'filelink.' => [$this->getUniqueId('filelink.')],
220  ];
221  ‪$subject = $this->getMockBuilder(ContentObjectRenderer::class)
222  ->setMethods(['filelink'])->getMock();
223  ‪$subject->expects($this->once())->method('filelink')
224  ->with($content, $conf['filelink.'])->willReturn('return');
225  $this->assertSame(
226  'return',
227  ‪$subject->‪stdWrap_filelink($content, $conf)
228  );
229  }
230 
242  public function ‪stdWrap_filelist(): void
243  {
244  $conf = [
245  'filelist' => $this->getUniqueId('filelist'),
246  'filelist.' => [$this->getUniqueId('not used')],
247  ];
248  ‪$subject = $this->getMockBuilder(ContentObjectRenderer::class)
249  ->setMethods(['filelist'])->getMock();
250  ‪$subject->expects($this->once())->method('filelist')
251  ->with($conf['filelist'])->willReturn('return');
252  $this->assertSame(
253  'return',
254  ‪$subject->‪stdWrap_filelist('discard', $conf)
255  );
256  }
257 
261  public function ‪_parseFuncReturnsCorrectHtmlDataProvider(): array
262  {
263  return [
264  'Text without tag is wrapped with <p> tag' => [
265  'Text without tag',
266  $this->‪getLibParseFunc_RTE(),
267  '<p class="bodytext">Text without tag</p>',
268  ],
269  'Text wrapped with <p> tag remains the same' => [
270  '<p class="myclass">Text with &lt;p&gt; tag</p>',
271  $this->‪getLibParseFunc_RTE(),
272  '<p class="myclass">Text with &lt;p&gt; tag</p>',
273  ],
274  'Text with absolute external link' => [
275  'Text with <link http://example.com/foo/>external link</link>',
276  $this->‪getLibParseFunc_RTE(),
277  '<p class="bodytext">Text with <a href="http://example.com/foo/">external link</a></p>',
278  ],
279  'Empty lines are not duplicated' => [
280  LF,
281  $this->‪getLibParseFunc_RTE(),
282  '<p class="bodytext">&nbsp;</p>',
283  ],
284  'Multiple empty lines with no text' => [
285  LF . LF . LF,
286  $this->‪getLibParseFunc_RTE(),
287  '<p class="bodytext">&nbsp;</p>' . LF . '<p class="bodytext">&nbsp;</p>' . LF . '<p class="bodytext">&nbsp;</p>',
288  ],
289  'Empty lines are not duplicated at the end of content' => [
290  'test' . LF . LF,
291  $this->‪getLibParseFunc_RTE(),
292  '<p class="bodytext">test</p>' . LF . '<p class="bodytext">&nbsp;</p>',
293  ],
294  'Empty lines are not trimmed' => [
295  LF . 'test' . LF,
296  $this->‪getLibParseFunc_RTE(),
297  '<p class="bodytext">&nbsp;</p>' . LF . '<p class="bodytext">test</p>' . LF . '<p class="bodytext">&nbsp;</p>',
298  ],
299  ];
300  }
301 
309  public function ‪stdWrap_parseFuncReturnsParsedHtml($value, $configuration, $expectedResult): void
310  {
311  $this->assertEquals($expectedResult, $this->subject->stdWrap_parseFunc($value, $configuration));
312  }
313 }
‪TYPO3\CMS\Frontend\ContentObject\RestoreRegisterContentObject
Definition: RestoreRegisterContentObject.php:21
‪TYPO3\CMS\Frontend\Tests\UnitDeprecated\ContentObject\ContentObjectRendererTest\stdWrap_filelist
‪stdWrap_filelist()
Definition: ContentObjectRendererTest.php:236
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static string getPublicPath()
Definition: Environment.php:153
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject\ContentObjectRendererTestTrait\getLibParseFunc_RTE
‪array getLibParseFunc_RTE()
Definition: ContentObjectRendererTestTrait.php:28
‪TYPO3\CMS\Frontend\ContentObject\ImageContentObject
Definition: ImageContentObject.php:21
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\stdWrap_filelist
‪string stdWrap_filelist($content='', $conf=[])
Definition: ContentObjectRenderer.php:1836
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject\ContentObjectRendererTestTrait
Definition: ContentObjectRendererTestTrait.php:24
‪TYPO3\CMS\Frontend\ContentObject\HierarchicalMenuContentObject
Definition: HierarchicalMenuContentObject.php:23
‪TYPO3\CMS\Frontend\Tests\UnitDeprecated\ContentObject\ContentObjectRendererTest\filelinkCreatesCorrectUrlForFileWithUrlEncodedSpecialChars
‪filelinkCreatesCorrectUrlForFileWithUrlEncodedSpecialChars()
Definition: ContentObjectRendererTest.php:149
‪TYPO3\CMS\Frontend\ContentObject\FileContentObject
Definition: FileContentObject.php:27
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:49
‪TYPO3\CMS\Frontend\Tests\UnitDeprecated\ContentObject
Definition: ContentObjectRendererTest.php:3
‪TYPO3\CMS\Frontend\ContentObject\UserInternalContentObject
Definition: UserInternalContentObject.php:21
‪TYPO3\CMS\Frontend\ContentObject\TemplateContentObject
Definition: TemplateContentObject.php:25
‪TYPO3\CMS\Frontend\Tests\UnitDeprecated\ContentObject\ContentObjectRendererTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: ContentObjectRendererTest.php:57
‪TYPO3\CMS\Frontend\ContentObject\ScalableVectorGraphicsContentObject
Definition: ScalableVectorGraphicsContentObject.php:24
‪TYPO3\CMS\Frontend\Page\PageRepository
Definition: PageRepository.php:53
‪TYPO3\CMS\Frontend\ContentObject\LoadRegisterContentObject
Definition: LoadRegisterContentObject.php:21
‪TYPO3\CMS\Frontend\ContentObject\UserContentObject
Definition: UserContentObject.php:23
‪TYPO3\CMS\Frontend\ContentObject\ImageResourceContentObject
Definition: ImageResourceContentObject.php:21
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\stdWrap_addParams
‪string stdWrap_addParams($content='', $conf=[])
Definition: ContentObjectRenderer.php:2568
‪TYPO3\CMS\Frontend\ContentObject\EditPanelContentObject
Definition: EditPanelContentObject.php:21
‪TYPO3\CMS\Frontend\Tests\UnitDeprecated\ContentObject\ContentObjectRendererTest\$frontendControllerMock
‪PHPUnit_Framework_MockObject_MockObject TypoScriptFrontendController $frontendControllerMock
Definition: ContentObjectRendererTest.php:65
‪TYPO3\CMS\Frontend\Tests\UnitDeprecated\ContentObject\ContentObjectRendererTest\stdWrap_filelink
‪stdWrap_filelink()
Definition: ContentObjectRendererTest.php:208
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectArrayContentObject
Definition: ContentObjectArrayContentObject.php:24
‪TYPO3\CMS\Frontend\ContentObject\CaseContentObject
Definition: CaseContentObject.php:21
‪TYPO3\CMS\Frontend\ContentObject\FluidTemplateContentObject
Definition: FluidTemplateContentObject.php:30
‪TYPO3\CMS\Core\TypoScript\TemplateService
Definition: TemplateService.php:50
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:97
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Frontend\Tests\UnitDeprecated\ContentObject\ContentObjectRendererTest\_parseFuncReturnsCorrectHtmlDataProvider
‪array _parseFuncReturnsCorrectHtmlDataProvider()
Definition: ContentObjectRendererTest.php:255
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\stdWrap_filelink
‪string stdWrap_filelink($content='', $conf=[])
Definition: ContentObjectRenderer.php:2583
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:39
‪TYPO3\CMS\Core\Log\Logger
Definition: Logger.php:23
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:91
‪TYPO3\CMS\Frontend\Tests\UnitDeprecated\ContentObject\ContentObjectRendererTest\setUp
‪setUp()
Definition: ContentObjectRendererTest.php:102
‪TYPO3\CMS\Frontend\Tests\UnitDeprecated\ContentObject\ContentObjectRendererTest
Definition: ContentObjectRendererTest.php:53
‪TYPO3\CMS\Frontend\ContentObject\TextContentObject
Definition: TextContentObject.php:21
‪TYPO3\CMS\Frontend\ContentObject\RecordsContentObject
Definition: RecordsContentObject.php:27
‪TYPO3\CMS\Frontend\Tests\UnitDeprecated\ContentObject\ContentObjectRendererTest\$contentObjectMap
‪array $contentObjectMap
Definition: ContentObjectRendererTest.php:75
‪TYPO3\CMS\Frontend\ContentObject\FilesContentObject
Definition: FilesContentObject.php:26
‪TYPO3\CMS\Frontend\Tests\UnitDeprecated\ContentObject\ContentObjectRendererTest\$subject
‪PHPUnit_Framework_MockObject_MockObject ContentObjectRenderer $subject
Definition: ContentObjectRendererTest.php:61
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectArrayInternalContentObject
Definition: ContentObjectArrayInternalContentObject.php:25
‪TYPO3\CMS\Frontend\Tests\UnitDeprecated\ContentObject\ContentObjectRendererTest\stdWrap_addParams
‪stdWrap_addParams()
Definition: ContentObjectRendererTest.php:175
‪TYPO3\CMS\Frontend\ContentObject\ContentContentObject
Definition: ContentContentObject.php:25
‪TYPO3\CMS\Frontend\Tests\UnitDeprecated\ContentObject\ContentObjectRendererTest\stdWrap_parseFuncReturnsParsedHtml
‪stdWrap_parseFuncReturnsParsedHtml($value, $configuration, $expectedResult)
Definition: ContentObjectRendererTest.php:303
‪TYPO3\CMS\Frontend\Tests\UnitDeprecated\ContentObject\ContentObjectRendererTest\$templateServiceMock
‪PHPUnit_Framework_MockObject_MockObject TemplateService $templateServiceMock
Definition: ContentObjectRendererTest.php:69