‪TYPO3CMS  ‪main
BackendControllerTest.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;
34 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
35 
36 final class ‪BackendControllerTest extends FunctionalTestCase
37 {
38  protected array ‪$testExtensionsToLoad = ['workspaces'];
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 ‪backendPageRenderEventIsTriggered(): void
50  {
52  $container = $this->get('service_container');
53 
54  $state = [
55  'after-backend-page-render-listener' => null,
56  ];
57 
58  // Dummy listeners that just record that the event existed.
59  $container->set(
60  'after-backend-page-render-listener',
61  static function (‪AfterBackendPageRenderEvent $event) use (&$state) {
62  $state['after-backend-page-render-listener'] = $event;
63  }
64  );
65 
66  $eventListener = GeneralUtility::makeInstance(ListenerProvider::class);
67  $eventListener->addListener(AfterBackendPageRenderEvent::class, 'after-backend-page-render-listener');
68 
69  $request = (new ‪ServerRequest('https://example.com/typo3/main'))
70  ->withAttribute('applicationType', ‪SystemEnvironmentBuilder::REQUESTTYPE_BE)
71  ->withAttribute('route', new ‪Route('/main', ['packageName' => 'typo3/cms-backend', '_identifier' => 'main']));
72 
73  ‪$GLOBALS['TYPO3_REQUEST'] = $request;
74  $subject = $this->get(BackendController::class);
75  $subject->mainAction($request);
76 
77  self::assertInstanceOf(AfterBackendPageRenderEvent::class, $state['after-backend-page-render-listener']);
78  }
79 
80  #[Test]
82  {
83  // Set workspace to disable the site configuration module
84  ‪$GLOBALS['BE_USER']->workspace = 1;
85 
86  $request = (new ‪ServerRequest('https://example.com/typo3/main'))
87  ->withAttribute('applicationType', ‪SystemEnvironmentBuilder::REQUESTTYPE_BE)
88  ->withQueryParams(['redirect' => 'site_configuration'])
89  ->withAttribute('route', new ‪Route('/main', ['packageName' => 'typo3/cms-backend', '_identifier' => 'main']));
90 
91  ‪$GLOBALS['TYPO3_REQUEST'] = $request;
92  $this->get(BackendController::class)->mainAction($request);
93 
94  $flashMessage = $this->get(FlashMessageService::class)
95  ->getMessageQueueByIdentifier(‪FlashMessageQueue::NOTIFICATION_QUEUE)
96  ->getAllMessages()[0] ?? null;
97 
98  self::assertInstanceOf(FlashMessage::class, $flashMessage);
99  self::assertEquals('No module access', $flashMessage->getTitle());
100  self::assertEquals(ContextualFeedbackSeverity::INFO, $flashMessage->getSeverity());
101  }
102 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Backend\Tests\Functional\Controller\BackendControllerTest\backendPageRenderEventIsTriggered
‪backendPageRenderEventIsTriggered()
Definition: BackendControllerTest.php:49
‪TYPO3\CMS\Backend\Tests\Functional\Controller\BackendControllerTest
Definition: BackendControllerTest.php:37
‪TYPO3\CMS\Backend\Tests\Functional\Controller\BackendControllerTest\$testExtensionsToLoad
‪array $testExtensionsToLoad
Definition: BackendControllerTest.php:38
‪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\Tests\Functional\Controller\BackendControllerTest\flashMessageIsDispatchedForForcedRedirect
‪flashMessageIsDispatchedForForcedRedirect()
Definition: BackendControllerTest.php:81
‪TYPO3\CMS\Backend\Routing\Route
Definition: Route.php:24
‪TYPO3\CMS\Backend\Controller\Event\AfterBackendPageRenderEvent
Definition: AfterBackendPageRenderEvent.php:29
‪TYPO3\CMS\Core\Type\ContextualFeedbackSeverity
‪ContextualFeedbackSeverity
Definition: ContextualFeedbackSeverity.php:25
‪TYPO3\CMS\Core\Messaging\FlashMessageQueue\NOTIFICATION_QUEUE
‪const NOTIFICATION_QUEUE
Definition: FlashMessageQueue.php:31
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪TYPO3\CMS\Backend\Controller\BackendController
Definition: BackendController.php:61
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:27
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Tests\Functional\Controller\BackendControllerTest\setUp
‪setUp()
Definition: BackendControllerTest.php:40
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\EventDispatcher\ListenerProvider
Definition: ListenerProvider.php:30
‪TYPO3\CMS\Core\Messaging\FlashMessageQueue
Definition: FlashMessageQueue.php:29
‪TYPO3\CMS\Core\Messaging\FlashMessageService
Definition: FlashMessageService.php:27
‪TYPO3\CMS\Backend\Tests\Functional\Controller
Definition: BackendControllerTest.php:18