‪TYPO3CMS  11.5
BackendModuleControllerTest.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 
26 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
27 
28 class ‪BackendModuleControllerTest extends FunctionalTestCase
29 {
33  protected ‪$initializeDatabase = false;
34 
35  protected int ‪$oldErrorReporting;
36 
37  public function ‪setUp(): void
38  {
39  parent::setUp();
40  // @todo: The install tool session handler is hardcoded within install tool.
41  // FileSessionHandler calls session_save_path() which basically can
42  // be done exactly once per process. After that it throws warnings.
43  // We can't mitigate this until the install tool session handler is
44  // refactored and enables us to add a mock here.
45  // To not disable the tests, we for now suppress warnings in this test.
46  // Even though the phpunit error handler is before the native PHP handler,
47  // phpunit currently ignores the warning as well: if (!($errorNumber & error_reporting())) {
48  $this->oldErrorReporting = error_reporting(E_ALL & ~E_WARNING);
49  }
50 
51  public function ‪tearDown(): void
52  {
53  error_reporting($this->oldErrorReporting);
54  }
55 
62  public function ‪environmentContextIsRespectedTest(string $module): void
63  {
64  $subject = new ‪BackendModuleController(
65  $this->get(UriBuilder::class),
66  $this->get(ModuleTemplateFactory::class)
67  );
68  $action = $module . 'Action';
69 
70  self::assertIsCallable([$subject, $action]);
71 
72  // Ensure we are not in development context
73  self::assertFalse(‪Environment::getContext()->isDevelopment());
74 
75  // Sudo mode is required
76  self::assertEquals(403, $subject->{$action}()->getStatusCode());
77 
78  // Initialize environment with development context
80  new ApplicationContext('Development'),
87  ‪Environment::getBackendPath() . '/index.php',
88  ‪Environment::isWindows() ? 'WINDOWS' : 'UNIX'
89  );
90 
91  // Authorized redirect to the admin tool is performed
92  // sudo mode is not required (due to development context)
93  ‪$GLOBALS['BE_USER'] = new BackendUserAuthentication();
94  // using anonymous user session, which is fine for this test case
95  ‪$GLOBALS['BE_USER']->initializeUserSessionManager();
96  ‪$GLOBALS['BE_USER']->user = ['uid' => 1];
97 
98  $response = $subject->{$action}();
99  self::assertEquals(303, $response->getStatusCode());
100  self::assertNotEmpty($response->getHeader('location'));
101  self::assertStringContainsString(
102  'typo3/install.php?install[controller]=' . $module . '&install[context]=backend',
103  $response->getHeaderLine('location')
104  );
105  }
106 
107  public function environmentContextIsRespectedTestDataProvider(): \Generator
108  {
109  yield 'maintenance module' => ['maintenance'];
110  yield 'settings module' => ['settings'];
111  yield 'upgrade module' => ['upgrade'];
112  yield 'environment module' => ['environment'];
113  }
114 }
‪TYPO3\CMS\Install\Tests\Functional\Controller\BackendModuleControllerTest\tearDown
‪tearDown()
Definition: BackendModuleControllerTest.php:50
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static string getPublicPath()
Definition: Environment.php:206
‪TYPO3\CMS\Core\Core\ApplicationContext
Definition: ApplicationContext.php:39
‪TYPO3\CMS\Backend\Template\ModuleTemplateFactory
Definition: ModuleTemplateFactory.php:29
‪TYPO3\CMS\Install\Tests\Functional\Controller\BackendModuleControllerTest\$initializeDatabase
‪bool $initializeDatabase
Definition: BackendModuleControllerTest.php:32
‪TYPO3\CMS\Install\Tests\Functional\Controller\BackendModuleControllerTest\setUp
‪setUp()
Definition: BackendModuleControllerTest.php:36
‪TYPO3\CMS\Core\Core\Environment\isWindows
‪static bool isWindows()
Definition: Environment.php:318
‪TYPO3\CMS\Install\Tests\Functional\Controller\BackendModuleControllerTest\environmentContextIsRespectedTest
‪environmentContextIsRespectedTest(string $module)
Definition: BackendModuleControllerTest.php:61
‪TYPO3\CMS\Install\Tests\Functional\Controller\BackendModuleControllerTest\environmentContextIsRespectedTestDataProvider
‪environmentContextIsRespectedTestDataProvider()
Definition: BackendModuleControllerTest.php:106
‪TYPO3\CMS\Core\Core\Environment\getContext
‪static ApplicationContext getContext()
Definition: Environment.php:141
‪TYPO3\CMS\Core\Core\Environment\getProjectPath
‪static string getProjectPath()
Definition: Environment.php:177
‪TYPO3\CMS\Install\Tests\Functional\Controller
Definition: BackendModuleControllerTest.php:18
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:40
‪TYPO3\CMS\Install\Tests\Functional\Controller\BackendModuleControllerTest\$oldErrorReporting
‪int $oldErrorReporting
Definition: BackendModuleControllerTest.php:34
‪TYPO3\CMS\Core\Core\Environment\initialize
‪static initialize(ApplicationContext $context, bool $cli, bool $composerMode, string $projectPath, string $publicPath, string $varPath, string $configPath, string $currentScript, string $os)
Definition: Environment.php:111
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Core\Environment\getBackendPath
‪static string getBackendPath()
Definition: Environment.php:276
‪TYPO3\CMS\Core\Core\Environment\isComposerMode
‪static bool isComposerMode()
Definition: Environment.php:152
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:43
‪TYPO3\CMS\Install\Tests\Functional\Controller\BackendModuleControllerTest
Definition: BackendModuleControllerTest.php:29
‪TYPO3\CMS\Core\Core\Environment\getConfigPath
‪static string getConfigPath()
Definition: Environment.php:236
‪TYPO3\CMS\Core\Core\Environment\getVarPath
‪static string getVarPath()
Definition: Environment.php:218
‪TYPO3\CMS\Install\Controller\BackendModuleController
Definition: BackendModuleController.php:49