6 * Tests for sql-dump commands.
12 class SqlDumpTest extends CommandUnishTestCase
16 * Test that a dump file is created successfully.
18 public function testSqlDump()
20 if ($this->dbDriver() == 'sqlite') {
21 $this->markTestSkipped('SQL Dump does not apply to SQLite.');
25 $this->setUpDrupal(1, true);
26 $root = $this->webroot();
27 $uri = $this->getUri();
28 $full_dump_file_path = self::getSandbox() . DIRECTORY_SEPARATOR . 'full_db.sql';
31 'result-file' => $full_dump_file_path,
32 // Last 5 entries are for D8+
33 'skip-tables-list' => 'hist*,cache*,router,config*,watchdog,key_valu*',
37 $this->drush('sql-dump', [], $options + ['simulate' => null]);
38 $this->assertContains('--ignore-table=unish_dev.cache_discovery', $this->getErrorOutput());
40 // Test --extra-dump option
41 if ($this->dbDriver() == 'mysql') {
42 $this->drush('sql-dump', [], array_merge($options, [], ['extra-dump' => '--skip-add-drop-table']));
43 $this->assertFileExists($full_dump_file_path);
44 $full_dump_file = file_get_contents($full_dump_file_path);
45 $this->assertNotContains('DROP TABLE IF EXISTS', $full_dump_file);
49 // First, do a test without any aliases, and dump the whole database
50 $this->drush('sql-dump', [], $options);
51 $this->assertFileExists($full_dump_file_path);
52 $full_dump_file = file_get_contents($full_dump_file_path);
53 // Test that we have sane contents.
54 $this->assertContains('menu_tree', $full_dump_file);
55 // Test skip-files-list and wildcard expansion.
56 $this->assertNotContains('CREATE TABLE `key_value', $full_dump_file);
57 // Next, set up an alias file and run a couple of simulated
58 // tests to see if options are propagated correctly.
59 // Control: insure options are not set when not specified
60 unset($options['skip-tables-list']);
61 unlink($full_dump_file_path);
62 $this->drush('sql-dump', [], $options);
63 $this->assertFileExists($full_dump_file_path);
64 $full_dump_file = file_get_contents($full_dump_file_path);
65 // Test that we have sane contents.
66 $this->assertContains('CREATE TABLE `menu_tree', $full_dump_file);
67 // Test absence of skip-files-list.
68 $this->assertContains('CREATE TABLE `key_value', $full_dump_file);
70 // @todo Aliases to local sites are no longer supported. Throw exception?
71 // $aliasPath = self::getSandbox() . '/aliases';
73 // $aliasFile = $aliasPath . '/bar.aliases.drushrc.php';
74 // $aliasContents = <<<EOD
76 // // Written by Unish. This file is safe to delete.
77 // \$aliases['test'] = array(
81 // 'command-specific' => array(
82 // 'sql-dump' => array(
83 // 'skip-tables-list' => 'hist*,cache*,router,config*,watchdog,key_valu*',
88 // file_put_contents($aliasFile, $aliasContents);
89 // $options['alias-path'] = $aliasPath;
90 // unlink($full_dump_file_path);
91 // // Now run again with an alias, and test to see if the option is there
92 // $this->drush('sql-dump', array(), array_merge($options), '@test');
93 // $this->assertFileExists($full_dump_file_path);
94 // $full_dump_file = file_get_contents($full_dump_file_path);
95 // // Test that we have sane contents.
96 // $this->assertContains('queue', $full_dump_file);
97 // // Test skip-files-list and wildcard expansion.
98 // $this->assertNotContains('CREATE TABLE `key_value', $full_dump_file);
99 // // Repeat control test: options not recovered in absence of an alias.
100 // unlink($full_dump_file_path);
101 // $this->drush('sql-dump', array(), $options);
102 // $this->assertFileExists($full_dump_file_path);
103 // $full_dump_file = file_get_contents($full_dump_file_path);
104 // // Test that we have sane contents.
105 // $this->assertContains('queue', $full_dump_file);
106 // // Test absence of skip-files-list.
107 // $this->assertContains('CREATE TABLE `key_value', $full_dump_file);
108 // // Now run yet with @self, and test to see that Drush can recover the option
109 // // --skip-tables-list, defined in @test.
110 // unlink($full_dump_file_path);
111 // $this->drush('sql-dump', array(), $options, '@self');
112 // $this->assertFileExists($full_dump_file_path);
113 // $full_dump_file = file_get_contents($full_dump_file_path);
114 // // Test that we have sane contents.
115 // $this->assertContains('queue', $full_dump_file);
116 // // Test absence of skip-files-list.
117 // $this->assertNotContains('CREATE TABLE `key_value', $full_dump_file);