‪TYPO3CMS  ‪main
BrowseLinksControllerTest.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;
31 use TYPO3\CMS\RteCKEditor\Controller\BrowseLinksController;
32 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
33 
34 final class ‪BrowseLinksControllerTest extends FunctionalTestCase
35 {
36  protected array ‪$coreExtensionsToLoad = [
37  'rte_ckeditor',
38  ];
39 
40  public function ‪setUp(): void
41  {
42  parent::setUp();
43  $this->importCSVDataSet(__DIR__ . '/../../Fixtures/be_users.csv');
44  $backendUser = $this->setUpBackendUser(1);
45  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($backendUser);
46  }
47 
48  #[Test]
49  public function ‪linkEventsAreTriggered(): void
50  {
52  $container = $this->get('service_container');
53 
54  $state = [
55  'modify-link-handl-listener' => null,
56  'after-backend-page-render-listener' => null,
57  ];
58 
59  // Dummy listeners that just record that the event existed.
60  $container->set(
61  'modify-link-handler-listener',
62  static function (‪ModifyLinkHandlersEvent $event) use (&$state) {
63  $state['modify-link-handler-listener'] = $event;
64  }
65  );
66  $container->set(
67  'modify-allowed-items-listener',
68  static function (‪ModifyAllowedItemsEvent $event) use (&$state) {
69  $state['modify-allowed-items-listener'] = $event;
70  }
71  );
72 
73  $eventListener = GeneralUtility::makeInstance(ListenerProvider::class);
74  $eventListener->addListener(ModifyLinkHandlersEvent::class, 'modify-link-handler-listener');
75  $eventListener->addListener(ModifyAllowedItemsEvent::class, 'modify-allowed-items-listener');
76 
77  $request = (new ‪ServerRequest())
78  ->withAttribute('applicationType', ‪SystemEnvironmentBuilder::REQUESTTYPE_BE)
79  ->withAttribute('route', new ‪Route('/main', [
80  'packageName' => 'typo3/cms-rte-ckeditor',
81  '_identifier' => 'main',
82  ]))
83  ->withQueryParams([
84  'editorId' => 'cke_1',
85  'contentsLanguage' => 'en',
86  'P' => [
87  'table' => 'tt_content',
88  'uid' => '1',
89  'fieldName' => 'bodytext',
90  'recordType' => 'text',
91  'pid' => '1',
92  'richtextConfigurationName' => '',
93  ],
94  ]);
95  $request = $request->withAttribute('normalizedParams', ‪NormalizedParams::createFromRequest($request));
96 
97  $subject = $this->get(BrowseLinksController::class);
98 
99  $subject->mainAction($request);
100 
101  self::assertInstanceOf(ModifyLinkHandlersEvent::class, $state['modify-link-handler-listener']);
102  self::assertInstanceOf(ModifyAllowedItemsEvent::class, $state['modify-allowed-items-listener']);
103  }
104 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\RteCKEditor\Tests\Functional\RecordList\Controller
Definition: BrowseLinksControllerTest.php:18
‪TYPO3\CMS\RteCKEditor\Tests\Functional\RecordList\Controller\BrowseLinksControllerTest\setUp
‪setUp()
Definition: BrowseLinksControllerTest.php:40
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder
Definition: SystemEnvironmentBuilder.php:41
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder\REQUESTTYPE_BE
‪const REQUESTTYPE_BE
Definition: SystemEnvironmentBuilder.php:45
‪TYPO3\CMS\Backend\Routing\Route
Definition: Route.php:24
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪TYPO3\CMS\RteCKEditor\Tests\Functional\RecordList\Controller\BrowseLinksControllerTest
Definition: BrowseLinksControllerTest.php:35
‪TYPO3\CMS\Backend\Controller\Event\ModifyAllowedItemsEvent
Definition: ModifyAllowedItemsEvent.php:24
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\RteCKEditor\Tests\Functional\RecordList\Controller\BrowseLinksControllerTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: BrowseLinksControllerTest.php:36
‪TYPO3\CMS\Core\EventDispatcher\ListenerProvider
Definition: ListenerProvider.php:30
‪TYPO3\CMS\Core\Http\NormalizedParams\createFromRequest
‪static static createFromRequest(ServerRequestInterface $request, array $systemConfiguration=null)
Definition: NormalizedParams.php:840
‪TYPO3\CMS\RteCKEditor\Tests\Functional\RecordList\Controller\BrowseLinksControllerTest\linkEventsAreTriggered
‪linkEventsAreTriggered()
Definition: BrowseLinksControllerTest.php:49
‪TYPO3\CMS\Core\Http\NormalizedParams
Definition: NormalizedParams.php:38