InstallerNonDefaultDatabaseDriverTest.php in Drupal 8
File
core/tests/Drupal/FunctionalTests/Installer/InstallerNonDefaultDatabaseDriverTest.php
View source
<?php
namespace Drupal\FunctionalTests\Installer;
use Drupal\Core\Database\Database;
class InstallerNonDefaultDatabaseDriverTest extends InstallerTestBase {
protected $defaultTheme = 'stark';
protected $testDriverName;
protected function setUpSettings() {
$driver = Database::getConnection()
->driver();
if (!in_array($driver, [
'mysql',
'pgsql',
])) {
$this
->markTestSkipped("This test does not support the {$driver} database driver.");
}
$this->testDriverName = 'Drivertest' . ucfirst($driver);
$elements = $this
->xpath('//label[@for="edit-driver-drivertestmysql"]');
$this
->assertEqual(current($elements)
->getText(), 'MySQL by the driver_test module');
$elements = $this
->xpath('//label[@for="edit-driver-drivertestpgsql"]');
$this
->assertEqual(current($elements)
->getText(), 'PostgreSQL by the driver_test module');
$settings = $this->parameters['forms']['install_settings_form'];
$settings['driver'] = $this->testDriverName;
$settings[$this->testDriverName] = $settings[$driver];
unset($settings[$driver]);
$edit = $this
->translatePostValues($settings);
$this
->drupalPostForm(NULL, $edit, $this->translations['Save and continue']);
}
public function testInstalled() {
$this
->assertUrl('user/1');
$this
->assertSession()
->statusCodeEquals(200);
$contents = file_get_contents($this->root . '/' . $this->siteDirectory . '/settings.php');
$this
->assertStringContainsString("'namespace' => 'Drupal\\\\driver_test\\\\Driver\\\\Database\\\\{$this->testDriverName}',", $contents);
$this
->assertStringContainsString("'driver' => '{$this->testDriverName}',", $contents);
$this
->assertStringContainsString("'autoload' => 'core/modules/system/tests/modules/driver_test/src/Driver/Database/{$this->testDriverName}/',", $contents);
}
}