[TASK] Provide AcceptanceTest for stand alone install tool
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Acceptance / InstallTool / AbstractCest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Core\Tests\Acceptance\InstallTool;
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 use TYPO3\CMS\Core\Core\Environment;
18 use TYPO3\CMS\Core\Crypto\PasswordHashing\Argon2iPasswordHash;
19 use TYPO3\CMS\Core\Tests\Acceptance\Support\BackendTester;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21
22 class AbstractCest
23 {
24 public const ENABLE_INSTALL_TOOL_FILEPATH = 'typo3conf/ENABLE_INSTALL_TOOL';
25 public const ADDITIONAL_CONFIGURATION_FILEPATH = 'typo3conf/AdditionalConfiguration.php';
26
27 public function _before(BackendTester $I)
28 {
29 $I->amOnPage('typo3/install.php');
30 }
31
32 public function _after(BackendTester $I)
33 {
34 $I->click('Logout');
35
36 $I->amGoingTo('clean up created files');
37 unlink(Environment::getProjectPath() . '/' . self::ADDITIONAL_CONFIGURATION_FILEPATH);
38
39 $I->dontSeeFileFound(self::ENABLE_INSTALL_TOOL_FILEPATH);
40 $I->dontSeeFileFound(self::ADDITIONAL_CONFIGURATION_FILEPATH);
41 }
42
43 protected function logIntoInstallTool(BackendTester $I)
44 {
45 $password = $this->setInstallToolPassword($I);
46
47 $I->writeToFile(AbstractCest::ENABLE_INSTALL_TOOL_FILEPATH, '');
48 $I->reloadPage();
49 $I->fillField('#t3-install-form-password', $password);
50 $I->click('Login');
51 $I->waitForText('Maintenance');
52 }
53
54 /**
55 * @param BackendTester $I
56 * @return string
57 * @throws \TYPO3\CMS\Core\Crypto\PasswordHashing\InvalidPasswordHashException
58 */
59 private function setInstallToolPassword(BackendTester $I): string
60 {
61 $hashMethod = GeneralUtility::makeInstance(Argon2iPasswordHash::class);
62 $password = 'temporary password';
63 $hashedPassword = $hashMethod->getHashedPassword($password);
64 $I->writeToFile(
65 self::ADDITIONAL_CONFIGURATION_FILEPATH,
66 '<?php' . PHP_EOL . '$GLOBALS[\'TYPO3_CONF_VARS\'][\'BE\'][\'installToolPassword\'] = \'' . $hashedPassword . '\';'
67 );
68 return $password;
69 }
70 }