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