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