class DistributionProfileExistingSettingsTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/FunctionalTests/Installer/DistributionProfileExistingSettingsTest.php \Drupal\FunctionalTests\Installer\DistributionProfileExistingSettingsTest
Tests distribution profile support with existing settings.
@group Installer
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\FunctionalTests\Installer\InstallerTestBase uses \Drupal\Tests\RequirementsPageTrait implements \Drupal\Tests\BrowserTestBase
- class \Drupal\FunctionalTests\Installer\DistributionProfileExistingSettingsTest implements \Drupal\FunctionalTests\Installer\InstallerTestBase
- class \Drupal\FunctionalTests\Installer\InstallerTestBase uses \Drupal\Tests\RequirementsPageTrait implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of DistributionProfileExistingSettingsTest
File
-
core/
tests/ Drupal/ FunctionalTests/ Installer/ DistributionProfileExistingSettingsTest.php, line 15
Namespace
Drupal\FunctionalTests\InstallerView source
class DistributionProfileExistingSettingsTest extends InstallerTestBase {
/**
* The distribution profile info.
*
* @var array
*/
protected $info;
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function prepareEnvironment() {
parent::prepareEnvironment();
$this->info = [
'type' => 'profile',
'core_version_requirement' => '*',
'name' => 'Distribution profile',
'distribution' => [
'name' => 'My Distribution',
'install' => [
'theme' => 'olivero',
],
],
];
// File API functions are not available yet.
$path = $this->siteDirectory . '/profiles/my_distro';
mkdir($path, 0777, TRUE);
file_put_contents("{$path}/my_distro.info.yml", Yaml::encode($this->info));
// Pre-configure hash salt.
// Any string is valid, so simply use the class name of this test.
$this->settings['settings']['hash_salt'] = (object) [
'value' => __CLASS__,
'required' => TRUE,
];
// Pre-configure database credentials.
$connection_info = Database::getConnectionInfo();
unset($connection_info['default']['pdo']);
unset($connection_info['default']['init_commands']);
$this->settings['databases']['default'] = (object) [
'value' => $connection_info,
'required' => TRUE,
];
// Use the kernel to find the site path because the site.path service should
// not be available at this point in the install process.
$site_path = DrupalKernel::findSitePath(Request::createFromGlobals());
// Pre-configure config directories.
$this->settings['settings']['config_sync_directory'] = (object) [
'value' => $site_path . '/files/config_staging',
'required' => TRUE,
];
mkdir($this->settings['settings']['config_sync_directory']->value, 0777, TRUE);
}
/**
* {@inheritdoc}
*/
protected function setUpLanguage() {
// Make settings file not writable.
$filename = $this->siteDirectory . '/settings.php';
// Make the settings file read-only.
// Not using File API; a potential error must trigger a PHP warning.
chmod($filename, 0444);
// Verify that the distribution name appears.
$this->assertSession()
->pageTextContains($this->info['distribution']['name']);
// Verify that the requested theme is used.
$this->assertSession()
->responseContains($this->info['distribution']['install']['theme']);
// Verify that the "Choose profile" step does not appear.
$this->assertSession()
->pageTextNotContains('profile');
parent::setUpLanguage();
}
/**
* {@inheritdoc}
*/
protected function setUpProfile() {
// This step is skipped, because there is a distribution profile.
}
/**
* {@inheritdoc}
*/
protected function setUpSettings() {
// This step should not appear, since settings.php is fully configured
// already.
}
/**
* Confirms that the installation succeeded.
*/
public function testInstalled() {
$this->assertSession()
->addressEquals('user/1');
$this->assertSession()
->statusCodeEquals(200);
// Confirm that we are logged-in after installation.
$this->assertSession()
->pageTextContains($this->rootUser
->getAccountName());
// Confirm that Drupal recognizes this distribution as the current profile.
$this->assertEquals('my_distro', \Drupal::installProfile());
$this->assertEquals('my_distro', $this->config('core.extension')
->get('profile'), 'The install profile has been written to core.extension configuration.');
$this->rebuildContainer();
$this->assertEquals('my_distro', \Drupal::installProfile());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.