X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrush%2Fdrush%2Ftests%2FSqlConnectCreateTest.php;fp=vendor%2Fdrush%2Fdrush%2Ftests%2FSqlConnectCreateTest.php;h=b068c67a7670dc38ea1f7ab90ed721d49bf1835f;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/drush/drush/tests/SqlConnectCreateTest.php b/vendor/drush/drush/tests/SqlConnectCreateTest.php new file mode 100644 index 000000000..b068c67a7 --- /dev/null +++ b/vendor/drush/drush/tests/SqlConnectCreateTest.php @@ -0,0 +1,61 @@ +setUpDrupal(1, true); + // Get the connection details with sql-connect and check its structure. + $this->drush('sql-connect'); + $connectionString = $this->getOutput(); + + // Not all drivers need -e option like sqlite + $shell_options = "-e"; + $db_driver = $this->dbDriver(); + if ($db_driver == 'mysql') { + $this->assertRegExp('/^mysql --user=[^\s]+ --password=.* --database=[^\s]+ --host=[^\s]+/', $connectionString); + } elseif ($db_driver == 'sqlite') { + $this->assertContains('sqlite3', $connectionString); + $shell_options = ''; + } elseif ($db_driver == 'pgsql') { + $this->assertRegExp('/^psql -q --dbname=[^\s]+ --host=[^\s]+ --port=[^\s]+ --username=[^\s]+/', $connectionString); + } else { + $this->markTestSkipped('sql-connect test does not recognize database type in ' . self::getDbUrl()); + } + + // Issue a query and check the result to verify the connection. + $this->execute($connectionString . ' ' . $shell_options . ' "SELECT uid FROM users where uid = 1;"'); + $output = $this->getOutput(); + $this->assertContains('1', $output); + + // Run 'core-status' and insure that we can bootstrap Drupal. + $this->drush('core-status', [], ['fields' => 'bootstrap']); + $output = $this->getOutput(); + $this->assertContains('Successful', $output); + + // Test to see if 'sql-create' can erase the database. + // The only output is a confirmation string, so we'll run + // other commands to confirm that this worked. + $this->drush('sql-create'); + + // Try to execute a query. This should give a "table not found" error. + $this->execute($connectionString . ' ' . $shell_options . ' "SELECT uid FROM users where uid = 1;"', self::EXIT_ERROR); + + // We should still be able to run 'core-status' without getting an + // error, although Drupal should not bootstrap any longer. + $this->drush('core-status', [], ['fields' => 'bootstrap']); + $output = $this->getOutput(); + $this->assertNotContains('Successful', $output); + } +}