AbstractCest.php 2.6 KB
Newer Older
1
<?php
2

3
declare(strict_types=1);
4
5
6
7
8
9
10
11
12
13
14
15
16

/*
 * This file is part of the TYPO3 CMS project.
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */
17

18
namespace TYPO3\CMS\Core\Tests\Acceptance\Backend\InstallTool;
19

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Crypto\PasswordHashing\Argon2iPasswordHash;
use TYPO3\CMS\Core\Tests\Acceptance\Support\BackendTester;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class AbstractCest
{
    public const ENABLE_INSTALL_TOOL_FILEPATH = 'typo3conf/ENABLE_INSTALL_TOOL';
    public const ADDITIONAL_CONFIGURATION_FILEPATH = 'typo3conf/AdditionalConfiguration.php';

    public function _before(BackendTester $I)
    {
        $I->amOnPage('typo3/install.php');
    }

    public function _after(BackendTester $I)
    {
        $I->click('Logout');
38
39
        // Make sure logout has finished
        $I->waitForText('The Install Tool is locked', 20);
40
41
42
43

        $I->amGoingTo('clean up created files');
        unlink(Environment::getProjectPath() . '/' . self::ADDITIONAL_CONFIGURATION_FILEPATH);

44
45
        $I->dontSeeFileFound(Environment::getProjectPath() . '/' . self::ENABLE_INSTALL_TOOL_FILEPATH);
        $I->dontSeeFileFound(Environment::getProjectPath() . '/' . self::ADDITIONAL_CONFIGURATION_FILEPATH);
46
47
48
49
50
51
52
53
    }

    protected function logIntoInstallTool(BackendTester $I)
    {
        $password = $this->setInstallToolPassword($I);

        $I->writeToFile(AbstractCest::ENABLE_INSTALL_TOOL_FILEPATH, '');
        $I->reloadPage();
54
        $I->waitForElementVisible('#t3-install-form-password');
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
        $I->fillField('#t3-install-form-password', $password);
        $I->click('Login');
        $I->waitForText('Maintenance');
    }

    /**
     * @param BackendTester $I
     * @return string
     * @throws \TYPO3\CMS\Core\Crypto\PasswordHashing\InvalidPasswordHashException
     */
    private function setInstallToolPassword(BackendTester $I): string
    {
        $hashMethod = GeneralUtility::makeInstance(Argon2iPasswordHash::class);
        $password = 'temporary password';
        $hashedPassword = $hashMethod->getHashedPassword($password);
        $I->writeToFile(
            self::ADDITIONAL_CONFIGURATION_FILEPATH,
            '<?php' . PHP_EOL . '$GLOBALS[\'TYPO3_CONF_VARS\'][\'BE\'][\'installToolPassword\'] = \'' . $hashedPassword . '\';'
        );
        return $password;
    }
}