6 * Tests sql-connect command
8 * Installs Drupal and checks that the given URL by sql-connect is correct.
13 class SqlConnectCase extends CommandUnishTestCase {
15 function testSqlConnect() {
16 $sites = $this->setUpDrupal(1, TRUE);
19 'root' => $this->webroot(),
23 // Get the connection details with sql-connect and check its structure.
24 $this->drush('sql-connect', array(), $options);
25 $connectionString = $this->getOutput();
27 // Not all drivers need -e option like sqlite
28 $shell_options = "-e";
29 $db_driver = $this->db_driver();
30 if ($db_driver == 'mysql') {
31 $this->assertRegExp('/^mysql --user=[^\s]+ --password=.* --database=[^\s]+ --host=[^\s]+/', $connectionString);
33 elseif ($db_driver == 'sqlite') {
34 $this->assertContains('sqlite3', $connectionString);
37 elseif ($db_driver == 'pgsql') {
38 $this->assertRegExp('/^psql -q --dbname=[^\s]+ --host=[^\s]+ --port=[^\s]+ --username=[^\s]+/', $connectionString);
41 $this->markTestSkipped('sql-connect test does not recognize database type in ' . UNISH_DB_URL);
44 // Issue a query and check the result to verify the connection.
45 $this->execute($connectionString . ' ' . $shell_options . ' "SELECT uid FROM users where uid = 1;"');
46 $output = $this->getOutput();
47 $this->assertContains('1', $output);
49 // Run 'core-status' and insure that we can bootstrap Drupal.
50 $this->drush('core-status', array("Drupal bootstrap"), $options);
51 $output = $this->getOutput();
52 $this->assertContains('Successful', $output);
54 // Test to see if 'sql-create' can erase the database.
55 // The only output is a confirmation string, so we'll run
56 // other commands to confirm that this worked.
57 $this->drush('sql-create', array(), $options);
59 // Try to execute a query. This should give a "table not found" error.
60 $this->execute($connectionString . ' ' . $shell_options . ' "SELECT uid FROM users where uid = 1;"', self::EXIT_ERROR);
62 // We should still be able to run 'core-status' without getting an
63 // error, although Drupal should not bootstrap any longer.
64 $this->drush('core-status', array("Drupal bootstrap"), $options);
65 $output = $this->getOutput();
66 $this->assertNotContains('Successful', $output);