|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\MagentoCloud\Test\Functional\Acceptance; |
| 9 | + |
| 10 | +/** |
| 11 | + * This test runs on the latest version of PHP |
| 12 | + * @group php82 |
| 13 | + */ |
| 14 | +class AdminCredentialCest extends AbstractCest |
| 15 | +{ |
| 16 | + /** |
| 17 | + * @var string |
| 18 | + */ |
| 19 | + protected $magentoCloudTemplate = '2.4.6'; |
| 20 | + |
| 21 | + /** |
| 22 | + * @param \CliTester $I |
| 23 | + */ |
| 24 | + public function _before(\CliTester $I): void |
| 25 | + { |
| 26 | + parent::_before($I); |
| 27 | + |
| 28 | + $I->copyFileToWorkDir('files/debug_logging/.magento.env.yaml', '.magento.env.yaml'); |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * @param \CliTester $I |
| 33 | + * @param \Codeception\Example $data |
| 34 | + * @throws \Robo\Exception\TaskException |
| 35 | + * @dataProvider installWithoutAdminEmailDataProvider |
| 36 | + */ |
| 37 | + public function testInstallWithoutAdminEmail(\CliTester $I, \Codeception\Example $data): void |
| 38 | + { |
| 39 | + $I->generateDockerCompose( |
| 40 | + sprintf( |
| 41 | + '--mode=production --env-vars="%s"', |
| 42 | + $this->convertEnvFromArrayToJson($data['variables']) |
| 43 | + ) |
| 44 | + ); |
| 45 | + $I->runDockerComposeCommand('run build cloud-build'); |
| 46 | + $I->startEnvironment(); |
| 47 | + $I->runDockerComposeCommand('run build cloud-build'); |
| 48 | + $I->runDockerComposeCommand('run deploy cloud-deploy'); |
| 49 | + $I->amOnPage('/'); |
| 50 | + $I->see('Home page'); |
| 51 | + $I->see('CMS homepage content goes here.'); |
| 52 | + |
| 53 | + $log = $I->grabFileContent('/var/log/cloud.log'); |
| 54 | + $I->assertStringContainsString($data['installMessage'], $log); |
| 55 | + $I->assertStringNotContainsString('--admin-user', $log); |
| 56 | + $I->assertStringNotContainsString('--admin-firstname', $log); |
| 57 | + $I->assertStringNotContainsString('--admin-lastname', $log); |
| 58 | + $I->assertStringNotContainsString('--admin-email', $log); |
| 59 | + $I->assertStringNotContainsString('--admin-password', $log); |
| 60 | + |
| 61 | + // Upgrade |
| 62 | + $I->runDockerComposeCommand('run deploy cloud-deploy'); |
| 63 | + |
| 64 | + $I->assertStringContainsString($data['upgradeMessage'], $I->grabFileContent('/var/log/cloud.log')); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * @return array |
| 69 | + */ |
| 70 | + protected function installWithoutAdminEmailDataProvider(): array |
| 71 | + { |
| 72 | + return [ |
| 73 | + [ |
| 74 | + 'variables' => ['MAGENTO_CLOUD_VARIABLES' => []], |
| 75 | + 'installMessage' => '', |
| 76 | + 'upgradeMessage' => '', |
| 77 | + ], |
| 78 | + [ |
| 79 | + 'variables' => ['MAGENTO_CLOUD_VARIABLES' => ['ADMIN_USERNAME' => 'MyLogin']], |
| 80 | + 'installMessage' => 'The following admin data was ignored and an admin was not created because' |
| 81 | + . ' admin email is not set: admin login', |
| 82 | + 'upgradeMessage' => 'The following admin data is required to create an admin user during initial' |
| 83 | + . ' installation only and is ignored during upgrade process: admin login', |
| 84 | + ], |
| 85 | + ]; |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * @param \CliTester $I |
| 90 | + * @param \Codeception\Example $data |
| 91 | + * @throws \Robo\Exception\TaskException |
| 92 | + * @dataProvider installWithDifferentVariablesDataProvider |
| 93 | + */ |
| 94 | + public function testInstallWithDifferentVariables(\CliTester $I, \Codeception\Example $data) |
| 95 | + { |
| 96 | + $I->generateDockerCompose( |
| 97 | + sprintf( |
| 98 | + '--mode=production --env-vars="%s"', |
| 99 | + $this->convertEnvFromArrayToJson($data['variables']) |
| 100 | + ) |
| 101 | + ); |
| 102 | + $I->runDockerComposeCommand('run build cloud-build'); |
| 103 | + $I->startEnvironment(); |
| 104 | + $I->runDockerComposeCommand('run deploy cloud-deploy'); |
| 105 | + $I->amOnPage('/'); |
| 106 | + $I->see('Home page'); |
| 107 | + $I->see('CMS homepage content goes here.'); |
| 108 | + |
| 109 | + $credentialsEmail = $I->grabFileContent('/var/credentials_email.txt'); |
| 110 | + $I->assertStringContainsString($data['expectedAdminEmail'], $credentialsEmail); |
| 111 | + $I->assertStringContainsString($data['expectedAdminUsername'], $credentialsEmail); |
| 112 | + $I->assertStringContainsString($data['expectedAdminUrl'], $credentialsEmail); |
| 113 | + |
| 114 | + $log = $I->grabFileContent('/var/log/cloud.log'); |
| 115 | + $I->assertStringContainsString('--admin-user', $log); |
| 116 | + $I->assertStringContainsString('--admin-firstname', $log); |
| 117 | + $I->assertStringContainsString('--admin-lastname', $log); |
| 118 | + $I->assertStringContainsString('--admin-email', $log); |
| 119 | + $I->assertStringContainsString('--admin-password', $log); |
| 120 | + $I->assertStringNotContainsString( |
| 121 | + 'The following admin data was ignored and an admin was not created because admin email is not set', |
| 122 | + $log |
| 123 | + ); |
| 124 | + |
| 125 | + // Upgrade |
| 126 | + $I->runDockerComposeCommand('run deploy cloud-deploy'); |
| 127 | + |
| 128 | + $I->assertStringNotContainsString( |
| 129 | + 'The following admin data is required to create an admin user during initial installation only' |
| 130 | + . ' and is ignored during upgrade process: admin login', |
| 131 | + $I->grabFileContent('/var/log/cloud.log') |
| 132 | + ); |
| 133 | + } |
| 134 | + |
| 135 | + /** |
| 136 | + * @return array |
| 137 | + */ |
| 138 | + protected function installWithDifferentVariablesDataProvider() |
| 139 | + { |
| 140 | + return [ |
| 141 | + [ |
| 142 | + 'variables' => [ |
| 143 | + 'MAGENTO_CLOUD_VARIABLES' => ['ADMIN_EMAIL' => 'admin@example.com'], |
| 144 | + ], |
| 145 | + 'expectedAdminEmail' => 'admin@example.com', |
| 146 | + 'expectedAdminUsername' => 'admin', |
| 147 | + 'expectedAdminUrl' => 'admin', |
| 148 | + ], |
| 149 | + [ |
| 150 | + 'variables' => [ |
| 151 | + 'MAGENTO_CLOUD_VARIABLES' => [ |
| 152 | + 'ADMIN_EMAIL' => 'admin2@example.com', |
| 153 | + 'ADMIN_URL' => 'root', |
| 154 | + 'ADMIN_USERNAME' => 'myusername', |
| 155 | + ], |
| 156 | + ], |
| 157 | + 'expectedAdminEmail' => 'admin2@example.com', |
| 158 | + 'expectedAdminUsername' => 'root', |
| 159 | + 'expectedAdminUrl' => 'myusername', |
| 160 | + ] |
| 161 | + ]; |
| 162 | + } |
| 163 | +} |
0 commit comments