DistributionProfileTest.php in Drupal 9
File
core/tests/Drupal/FunctionalTests/Installer/DistributionProfileTest.php
View source
<?php
namespace Drupal\FunctionalTests\Installer;
use Drupal\Core\Serialization\Yaml;
class DistributionProfileTest 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' => 'bartik',
'finish_url' => '/root-user',
],
],
];
$path = $this->siteDirectory . '/profiles/my_distro';
mkdir($path, 0777, TRUE);
file_put_contents("{$path}/my_distro.info.yml", Yaml::encode($this->info));
file_put_contents("{$path}/my_distro.install", "<?php function my_distro_install() {\\Drupal::entityTypeManager()->getStorage('path_alias')->create(['path' => '/user/1', 'alias' => '/root-user'])->save();}");
}
protected function setUpLanguage() {
$this
->assertSession()
->pageTextContains($this->info['distribution']['name']);
$this
->assertSession()
->titleEquals('Choose language | ' . $this->info['distribution']['name']);
$this
->assertSession()
->responseContains($this->info['distribution']['install']['theme']);
$this
->assertSession()
->pageTextNotContains('profile');
parent::setUpLanguage();
}
protected function setUpProfile() {
}
public function testInstalled() {
$this
->assertSession()
->addressEquals('root-user');
$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.');
}
}