‪TYPO3CMS  ‪main
ContentContentObjectTest.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
20 use PHPUnit\Framework\Attributes\Test;
21 use Symfony\Component\DependencyInjection\Container;
29 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
30 
31 final class ‪ContentContentObjectTest extends FunctionalTestCase
32 {
33  #[Test]
35  {
36  $records = [['uid' => 2004, 'title' => 'my content']];
37  $finalContent = 'my final content';
38  $modifyRecordsAfterFetchingContentEvent = null;
39 
41  $container = $this->get('service_container');
42  $container->set(
43  'modify-records-after-fetching-content-listener',
44  static function (‪ModifyRecordsAfterFetchingContentEvent $event) use (&$modifyRecordsAfterFetchingContentEvent, $records, $finalContent) {
45  $modifyRecordsAfterFetchingContentEvent = $event;
46  $modifyRecordsAfterFetchingContentEvent->‪setRecords($records);
47  $modifyRecordsAfterFetchingContentEvent->setFinalContent($finalContent);
48  }
49  );
50 
51  $eventListener = $container->get(ListenerProvider::class);
52  $eventListener->addListener(ModifyRecordsAfterFetchingContentEvent::class, 'modify-records-after-fetching-content-listener');
53 
54  $typoScriptFrontendController = GeneralUtility::makeInstance(TypoScriptFrontendController::class);
55  $contentObjectRenderer = GeneralUtility::makeInstance(ContentObjectRenderer::class, $typoScriptFrontendController);
56  $pageInformation = new ‪PageInformation();
57  $pageInformation->setId(1);
58  $pageInformation->setContentFromPid(1);
59  $request = (new ‪ServerRequest())->withAttribute('frontend.page.information', $pageInformation);
60  $contentObjectRenderer->setRequest($request);
61  $subject = $contentObjectRenderer->getContentObject('CONTENT');
62  $result = $subject->render(['table' => 'tt_content']);
63  self::assertEquals($finalContent, $result);
64  self::assertInstanceOf(ModifyRecordsAfterFetchingContentEvent::class, $modifyRecordsAfterFetchingContentEvent);
65  self::assertEquals($records, $modifyRecordsAfterFetchingContentEvent->getRecords());
66  self::assertEquals($finalContent, $modifyRecordsAfterFetchingContentEvent->getFinalContent());
67  }
68 }
‪TYPO3\CMS\Frontend\Tests\Functional\ContentObject\ContentContentObjectTest\modifyRecordsAfterFetchingContentEventIsCalled
‪modifyRecordsAfterFetchingContentEventIsCalled()
Definition: ContentContentObjectTest.php:34
‪TYPO3\CMS\Frontend\ContentObject\Event\ModifyRecordsAfterFetchingContentEvent
Definition: ModifyRecordsAfterFetchingContentEvent.php:30
‪TYPO3\CMS\Frontend\ContentObject\Event\ModifyRecordsAfterFetchingContentEvent\setRecords
‪setRecords(array $records)
Definition: ModifyRecordsAfterFetchingContentEvent.php:46
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪TYPO3\CMS\Frontend\Tests\Functional\ContentObject\ContentContentObjectTest
Definition: ContentContentObjectTest.php:32
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:58
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:102
‪TYPO3\CMS\Frontend\Tests\Functional\ContentObject
Definition: ContentContentObjectTest.php:18
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\EventDispatcher\ListenerProvider
Definition: ListenerProvider.php:30
‪TYPO3\CMS\Frontend\Page\PageInformation
Definition: PageInformation.php:28