‪TYPO3CMS  ‪main
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 
29 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
30 
31 class ‪BackendModuleControllerTest extends FunctionalTestCase
32 {
33  protected bool ‪$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 
60  public function ‪environmentContextIsRespectedTest(string $module): void
61  {
62  $subject = new ‪BackendModuleController(
63  $this->get(UriBuilder::class),
64  $this->get(ModuleTemplateFactory::class)
65  );
66  $action = $module . 'Action';
67 
68  $serverParams = array_replace($_SERVER, ['HTTP_HOST' => 'example.com', 'SCRIPT_NAME' => '/typo3/install.php']);
69  $request = new ‪ServerRequest('http://example.com/typo3/install.php', 'GET', null, [], $serverParams);
70  $request = $request
71  ->withAttribute('applicationType', ‪SystemEnvironmentBuilder::REQUESTTYPE_INSTALL)
72  ->withAttribute('normalizedParams', ‪NormalizedParams::createFromServerParams($serverParams));
73  self::assertIsCallable([$subject, $action]);
74 
75  // Ensure we are not in development context
76  self::assertFalse(‪Environment::getContext()->isDevelopment());
77 
78  // Sudo mode is required
79  self::assertEquals(403, $subject->{$action}($request)->getStatusCode());
80 
81  // Initialize environment with development context
83  new ‪ApplicationContext('Development'),
90  ‪Environment::getPublicPath() . '/index.php',
91  ‪Environment::isWindows() ? 'WINDOWS' : 'UNIX'
92  );
93 
94  // Authorized redirect to the admin tool is performed
95  // sudo mode is not required (due to development context)
96  ‪$GLOBALS['BE_USER'] = new ‪BackendUserAuthentication();
97  // using anonymous user session, which is fine for this test case
98  ‪$GLOBALS['BE_USER']->initializeUserSessionManager();
99  ‪$GLOBALS['BE_USER']->user = ['uid' => 1];
100 
101  $response = $subject->{$action}($request);
102  self::assertEquals(303, $response->getStatusCode());
103  self::assertNotEmpty($response->getHeader('location'));
104  self::assertStringContainsString(
105  'typo3/install.php?install[controller]=' . $module . '&install[context]=backend',
106  rawurldecode($response->getHeaderLine('location'))
107  );
108  }
109 
110  public static function ‪environmentContextIsRespectedTestDataProvider(): \Generator
111  {
112  yield 'maintenance module' => ['maintenance'];
113  yield 'settings module' => ['settings'];
114  yield 'upgrade module' => ['upgrade'];
115  yield 'environment module' => ['environment'];
116  }
117 }
‪TYPO3\CMS\Install\Tests\Functional\Controller\BackendModuleControllerTest\tearDown
‪tearDown()
Definition: BackendModuleControllerTest.php:51
‪TYPO3\CMS\Core\Core\ApplicationContext
Definition: ApplicationContext.php:39
‪TYPO3\CMS\Backend\Template\ModuleTemplateFactory
Definition: ModuleTemplateFactory.php:33
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder
Definition: SystemEnvironmentBuilder.php:41
‪TYPO3\CMS\Core\Core\Environment\isComposerMode
‪static isComposerMode()
Definition: Environment.php:137
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static getPublicPath()
Definition: Environment.php:187
‪TYPO3\CMS\Install\Tests\Functional\Controller\BackendModuleControllerTest\$initializeDatabase
‪bool $initializeDatabase
Definition: BackendModuleControllerTest.php:33
‪TYPO3\CMS\Install\Tests\Functional\Controller\BackendModuleControllerTest\setUp
‪setUp()
Definition: BackendModuleControllerTest.php:37
‪TYPO3\CMS\Install\Tests\Functional\Controller\BackendModuleControllerTest\environmentContextIsRespectedTest
‪environmentContextIsRespectedTest(string $module)
Definition: BackendModuleControllerTest.php:60
‪TYPO3\CMS\Core\Core\Environment\getVarPath
‪static getVarPath()
Definition: Environment.php:197
‪TYPO3\CMS\Core\Core\Environment\getConfigPath
‪static getConfigPath()
Definition: Environment.php:212
‪TYPO3\CMS\Core\Core\Environment\getProjectPath
‪static string getProjectPath()
Definition: Environment.php:160
‪TYPO3\CMS\Install\Tests\Functional\Controller
Definition: BackendModuleControllerTest.php:18
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:42
‪TYPO3\CMS\Core\Http\NormalizedParams\createFromServerParams
‪static static createFromServerParams(array $serverParams, array $systemConfiguration=null)
Definition: NormalizedParams.php:824
‪TYPO3\CMS\Install\Tests\Functional\Controller\BackendModuleControllerTest\$oldErrorReporting
‪int $oldErrorReporting
Definition: BackendModuleControllerTest.php:35
‪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:100
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:37
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:66
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Install\Tests\Functional\Controller\BackendModuleControllerTest
Definition: BackendModuleControllerTest.php:32
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder\REQUESTTYPE_INSTALL
‪const REQUESTTYPE_INSTALL
Definition: SystemEnvironmentBuilder.php:51
‪TYPO3\CMS\Core\Core\Environment\getContext
‪static getContext()
Definition: Environment.php:128
‪TYPO3\CMS\Install\Tests\Functional\Controller\BackendModuleControllerTest\environmentContextIsRespectedTestDataProvider
‪static environmentContextIsRespectedTestDataProvider()
Definition: BackendModuleControllerTest.php:110
‪TYPO3\CMS\Core\Http\NormalizedParams
Definition: NormalizedParams.php:38
‪TYPO3\CMS\Install\Controller\BackendModuleController
Definition: BackendModuleController.php:48
‪TYPO3\CMS\Core\Core\Environment\isWindows
‪static isWindows()
Definition: Environment.php:287