‪TYPO3CMS  ‪main
ManagementControllerTest.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\TestingFramework\Core\Functional\FunctionalTestCase;
32 
33 final class ‪ManagementControllerTest extends FunctionalTestCase
34 {
35  protected array ‪$coreExtensionsToLoad = ['redirects'];
38 
39  protected 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  $this->subject = GeneralUtility::makeInstance(ManagementController::class);
47  $this->normalizedParams = new ‪NormalizedParams([], [], '', '');
48  }
49 
50  #[Test]
52  {
53  $request = (new ‪ServerRequest('https://www.example.com/', 'GET'))
54  ->withAttribute('applicationType', ‪SystemEnvironmentBuilder::REQUESTTYPE_BE);
55  $request = $request
56  ->withAttribute('normalizedParams', $this->normalizedParams)
57  ->withAttribute('route', new ‪Route('path', ['packageName' => 'typo3/cms-redirects']));
58  ‪$GLOBALS['TYPO3_REQUEST'] = $request;
59 
60  $setHosts = ['*', 'example.com'];
61 
63  $container = $this->get('service_container');
64  $container->set(
65  'modify-redirect-management-controller-view-data-event',
66  static function (‪ModifyRedirectManagementControllerViewDataEvent $event) use (
67  &$modifyRedirectManagementControllerViewDataEvent,
68  $setHosts
69  ): void {
70  $modifyRedirectManagementControllerViewDataEvent = $event;
71  $event->‪setHosts($setHosts);
72  }
73  );
74 
75  $eventListener = $container->get(ListenerProvider::class);
76  $eventListener->addListener(ModifyRedirectManagementControllerViewDataEvent::class, 'modify-redirect-management-controller-view-data-event');
77 
78  $this->subject->handleRequest($request);
79 
80  self::assertInstanceOf(ModifyRedirectManagementControllerViewDataEvent::class, $modifyRedirectManagementControllerViewDataEvent);
81  self::assertSame($setHosts, $modifyRedirectManagementControllerViewDataEvent->getHosts());
82  }
83 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Redirects\Tests\Functional\Controller
Definition: ManagementControllerTest.php:18
‪TYPO3\CMS\Redirects\Tests\Functional\Controller\ManagementControllerTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: ManagementControllerTest.php:35
‪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\Redirects\Tests\Functional\Controller\ManagementControllerTest\setUp
‪setUp()
Definition: ManagementControllerTest.php:39
‪TYPO3\CMS\Redirects\Event\ModifyRedirectManagementControllerViewDataEvent\setHosts
‪setHosts(array $hosts)
Definition: ModifyRedirectManagementControllerViewDataEvent.php:95
‪TYPO3\CMS\Redirects\Tests\Functional\Controller\ManagementControllerTest\$normalizedParams
‪NormalizedParams $normalizedParams
Definition: ManagementControllerTest.php:37
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪TYPO3\CMS\Redirects\Tests\Functional\Controller\ManagementControllerTest\$subject
‪ManagementController $subject
Definition: ManagementControllerTest.php:36
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Redirects\Event\ModifyRedirectManagementControllerViewDataEvent
Definition: ModifyRedirectManagementControllerViewDataEvent.php:31
‪TYPO3\CMS\Redirects\Controller\ManagementController
Definition: ManagementController.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\EventDispatcher\ListenerProvider
Definition: ListenerProvider.php:30
‪TYPO3\CMS\Redirects\Tests\Functional\Controller\ManagementControllerTest\modifyRedirectManagementControllerViewDataEventIsTriggered
‪modifyRedirectManagementControllerViewDataEventIsTriggered()
Definition: ManagementControllerTest.php:51
‪TYPO3\CMS\Redirects\Tests\Functional\Controller\ManagementControllerTest
Definition: ManagementControllerTest.php:34
‪TYPO3\CMS\Core\Http\NormalizedParams
Definition: NormalizedParams.php:38