InstallerNonDefaultDatabaseDriverTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace Drupal\FunctionalTests\Installer;
  3. use Drupal\Core\Database\Database;
  4. /**
  5. * Tests the interactive installer.
  6. *
  7. * @group Installer
  8. */
  9. class InstallerNonDefaultDatabaseDriverTest extends InstallerTestBase {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. protected $defaultTheme = 'stark';
  14. /**
  15. * The name of the test database driver in use.
  16. * @var string
  17. */
  18. protected $testDriverName;
  19. /**
  20. * {@inheritdoc}
  21. */
  22. protected function setUpSettings() {
  23. $driver = Database::getConnection()->driver();
  24. if (!in_array($driver, ['mysql', 'pgsql'])) {
  25. $this->markTestSkipped("This test does not support the {$driver} database driver.");
  26. }
  27. $this->testDriverName = 'Drivertest' . ucfirst($driver);
  28. // Assert that we are using the database drivers from the driver_test module.
  29. $elements = $this->xpath('//label[@for="edit-driver-drivertestmysql"]');
  30. $this->assertEqual(current($elements)->getText(), 'MySQL by the driver_test module');
  31. $elements = $this->xpath('//label[@for="edit-driver-drivertestpgsql"]');
  32. $this->assertEqual(current($elements)->getText(), 'PostgreSQL by the driver_test module');
  33. $settings = $this->parameters['forms']['install_settings_form'];
  34. $settings['driver'] = $this->testDriverName;
  35. $settings[$this->testDriverName] = $settings[$driver];
  36. unset($settings[$driver]);
  37. $edit = $this->translatePostValues($settings);
  38. $this->drupalPostForm(NULL, $edit, $this->translations['Save and continue']);
  39. }
  40. /**
  41. * Confirms that the installation succeeded.
  42. */
  43. public function testInstalled() {
  44. $this->assertUrl('user/1');
  45. $this->assertSession()->statusCodeEquals(200);
  46. // Assert that in the settings.php the database connection array has the
  47. // correct values set.
  48. $contents = file_get_contents($this->root . '/' . $this->siteDirectory . '/settings.php');
  49. $this->assertStringContainsString("'namespace' => 'Drupal\\\\driver_test\\\\Driver\\\\Database\\\\{$this->testDriverName}',", $contents);
  50. $this->assertStringContainsString("'driver' => '{$this->testDriverName}',", $contents);
  51. $this->assertStringContainsString("'autoload' => 'core/modules/system/tests/modules/driver_test/src/Driver/Database/{$this->testDriverName}/',", $contents);
  52. }
  53. }