View source
<?php
namespace Drupal\FunctionalTests\Installer;
use Drupal\Core\Database\Database;
use Drupal\Core\Routing\RoutingEvents;
use Drupal\Core\Test\PerformanceTestRecorder;
use Drupal\Core\Extension\ModuleUninstallValidatorException;
class InstallerTest extends InstallerTestBase {
protected $defaultTheme = 'stark';
public function testInstaller() {
$this
->assertNotNull(\Drupal::state()
->get('system.css_js_query_string'), 'The dummy query string should be set during install');
$this
->assertSession()
->addressEquals('user/1');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains($this->rootUser
->getAccountName());
require_once $this->root . '/core/includes/install.inc';
$this
->assertSession()
->pageTextContains('Congratulations, you installed Drupal!');
$this
->assertEquals('Australia/Sydney', $this
->config('system.date')
->get('timezone.default'));
$module_extension_list = \Drupal::service('extension.list.module');
$extensions = $module_extension_list
->getList();
$this
->assertArrayHasKey('testing', $extensions);
$this
->assertEquals(1000, $extensions['testing']->weight);
$this
->assertSame(1, \Drupal::service('core.performance.test.recorder')
->getCount('event', RoutingEvents::FINISHED));
}
protected function setUpLanguage() {
$this
->assertSession()
->responseContains("css/components/button.css");
$this
->assertSession()
->responseContains('<meta charset="utf-8" />');
$this
->assertEquals('Choose language', $this
->cssSelect('main h2')[0]
->getText());
parent::setUpLanguage();
}
protected function setUpProfile() {
$settings_services_file = DRUPAL_ROOT . '/sites/default/default.services.yml';
copy($settings_services_file, $this->siteDirectory . '/services.yml');
PerformanceTestRecorder::registerService($this->siteDirectory . '/services.yml', TRUE);
$this
->assertEquals('Select an installation profile', $this
->cssSelect('main h2')[0]
->getText());
$this
->assertSession()
->elementsCount('xpath', "//span[contains(@class, 'visually-hidden') and contains(text(), 'Select an installation profile')]", 1);
parent::setUpProfile();
}
protected function setUpSettings() {
$this
->assertEquals('Database configuration', $this
->cssSelect('main h2')[0]
->getText());
$this
->assertSession()
->elementTextEquals('xpath', '//label[@for="edit-driver-mysql"]', 'MySQL, MariaDB, Percona Server, or equivalent');
$this
->assertSession()
->elementTextEquals('xpath', '//label[@for="edit-driver-pgsql"]', 'PostgreSQL');
parent::setUpSettings();
}
protected function setUpSite() {
$this
->assertEquals('Configure site', $this
->cssSelect('main h2')[0]
->getText());
$site_directory = $this->container
->getParameter('app.root') . '/' . $this->siteDirectory;
$this
->assertDirectoryIsNotWritable($site_directory);
$this
->assertFileIsNotWritable($site_directory . '/settings.php');
parent::setUpSite();
}
protected function visitInstaller() {
parent::visitInstaller();
$this
->assertSession()
->titleEquals('Choose language | Drupal');
}
public function testInstalled() {
$this
->assertSession()
->addressEquals('user/1');
$this
->assertSession()
->statusCodeEquals(200);
$database = Database::getConnection();
$module = $database
->getProvider();
$module_handler = \Drupal::service('module_handler');
$this
->assertFalse($module_handler
->moduleExists('update'), 'The Update module is not installed.');
$this
->assertTrue($module_handler
->moduleExists($module));
try {
$this->container
->get('module_installer')
->uninstall([
$module,
]);
$this
->fail("Uninstalled {$module} module.");
} catch (ModuleUninstallValidatorException $e) {
$module_name = $module_handler
->getName($module);
$driver = $database
->driver();
$this
->assertStringContainsString("The module '{$module_name}' is providing the database driver '{$driver}'.", $e
->getMessage());
}
}
}