sqlConnectTest.php

  1. 6.x tests/sqlConnectTest.php
  2. 5.x tests/sqlConnectTest.php

Tests sql-connect command

Installs Drupal and checks that the given URL by sql-connect is correct.

@group commands @group sql

Classes

Namesort descending Description
SqlConnectCase @file Tests sql-connect command

File

tests/sqlConnectTest.php
View source
  1. <?php
  2. /**
  3. * @file
  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 Drush_CommandTestCase {
  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. $output = $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 --database=[^\s]+ --host=[^\s]+ --user=[^\s]+ --password=.*$/', $output);
  27. }
  28. elseif ($db_driver == 'sqlite') {
  29. $this->assertContains('sqlite3', $output);
  30. $shell_options = '';
  31. }
  32. elseif ($db_driver == 'pgsql') {
  33. $this->assertRegExp('/^psql --dbname=[^\s]+ --host=[^\s]+ --port=[^\s]+ --username=[^\s]+/', $output);
  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($output . ' ' . $shell_options . ' "select name from users where uid = 1;"');
  40. $output = $this->getOutput();
  41. $this->assertContains('admin', $output);
  42. }
  43. }