sqlConnectCreateTest.php

  1. 8.0.x tests/sqlConnectCreateTest.php
  2. 7.x tests/sqlConnectCreateTest.php
  3. master tests/sqlConnectCreateTest.php

Namespace

Unish

Classes

Namesort descending Description
SqlConnectCase Tests sql-connect command

File

tests/sqlConnectCreateTest.php
View source
  1. <?php
  2. namespace Unish;
  3. /**
  4. * Tests sql-connect command
  5. *
  6. * Installs Drupal and checks that the given URL by sql-connect is correct.
  7. *
  8. * @group commands
  9. * @group sql
  10. */
  11. class SqlConnectCase extends CommandUnishTestCase {
  12. function testSqlConnect() {
  13. $sites = $this->setUpDrupal(1, TRUE);
  14. $options = array(
  15. 'yes' => NULL,
  16. 'root' => $this->webroot(),
  17. 'uri' => key($sites),
  18. );
  19. // Get the connection details with sql-connect and check its structure.
  20. $this->drush('sql-connect', array(), $options);
  21. $connectionString = $this->getOutput();
  22. // Not all drivers need -e option like sqlite
  23. $shell_options = "-e";
  24. $db_driver = $this->db_driver();
  25. if ($db_driver == 'mysql') {
  26. $this->assertRegExp('/^mysql --user=[^\s]+ --password=.* --database=[^\s]+ --host=[^\s]+/', $connectionString);
  27. }
  28. elseif ($db_driver == 'sqlite') {
  29. $this->assertContains('sqlite3', $connectionString);
  30. $shell_options = '';
  31. }
  32. elseif ($db_driver == 'pgsql') {
  33. $this->assertRegExp('/^psql -q --dbname=[^\s]+ --host=[^\s]+ --port=[^\s]+ --username=[^\s]+/', $connectionString);
  34. }
  35. else {
  36. $this->markTestSkipped('sql-connect test does not recognize database type in ' . UNISH_DB_URL);
  37. }
  38. // Issue a query and check the result to verify the connection.
  39. $this->execute($connectionString . ' ' . $shell_options . ' "SELECT uid FROM users where uid = 1;"');
  40. $output = $this->getOutput();
  41. $this->assertContains('1', $output);
  42. // Run 'core-status' and insure that we can bootstrap Drupal.
  43. $this->drush('core-status', array("Drupal bootstrap"), $options);
  44. $output = $this->getOutput();
  45. $this->assertContains('Successful', $output);
  46. // Test to see if 'sql-create' can erase the database.
  47. // The only output is a confirmation string, so we'll run
  48. // other commands to confirm that this worked.
  49. $this->drush('sql-create', array(), $options);
  50. // Try to execute a query. This should give a "table not found" error.
  51. $this->execute($connectionString . ' ' . $shell_options . ' "SELECT uid FROM users where uid = 1;"', self::EXIT_ERROR);
  52. // We should still be able to run 'core-status' without getting an
  53. // error, although Drupal should not bootstrap any longer.
  54. $this->drush('core-status', array("Drupal bootstrap"), $options);
  55. $output = $this->getOutput();
  56. $this->assertNotContains('Successful', $output);
  57. }
  58. }