DistributionProfileExistingSettingsTest.php in Drupal 10
File
core/tests/Drupal/FunctionalTests/Installer/DistributionProfileExistingSettingsTest.php
View source
<?php
namespace Drupal\FunctionalTests\Installer;
use Drupal\Component\Serialization\Yaml;
use Drupal\Core\Database\Database;
use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;
class DistributionProfileExistingSettingsTest extends InstallerTestBase {
protected $info;
protected $defaultTheme = 'stark';
protected function prepareEnvironment() {
parent::prepareEnvironment();
$this->info = [
'type' => 'profile',
'core_version_requirement' => '*',
'name' => 'Distribution profile',
'distribution' => [
'name' => 'My Distribution',
'install' => [
'theme' => 'olivero',
],
],
];
$path = $this->siteDirectory . '/profiles/my_distro';
mkdir($path, 0777, TRUE);
file_put_contents("{$path}/my_distro.info.yml", Yaml::encode($this->info));
$this->settings['settings']['hash_salt'] = (object) [
'value' => __CLASS__,
'required' => TRUE,
];
$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,
];
$site_path = DrupalKernel::findSitePath(Request::createFromGlobals());
$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);
}
protected function setUpLanguage() {
$filename = $this->siteDirectory . '/settings.php';
chmod($filename, 0444);
$this
->assertSession()
->pageTextContains($this->info['distribution']['name']);
$this
->assertSession()
->responseContains($this->info['distribution']['install']['theme']);
$this
->assertSession()
->pageTextNotContains('profile');
parent::setUpLanguage();
}
protected function setUpProfile() {
}
protected function setUpSettings() {
}
public function testInstalled() {
$this
->assertSession()
->addressEquals('user/1');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains($this->rootUser
->getAccountName());
$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());
}
}