6 * Tests for sql-dump commands.
12 class SqlDumpTest extends CommandUnishTestCase {
15 * Test that a dump file is created successfully.
17 function testSqlDump() {
18 if ($this->db_driver() == 'sqlite') {
19 $this->markTestSkipped('SQL Dump does not apply to SQLite.');
23 $this->setUpDrupal(1, TRUE);
24 $root = $this->webroot();
26 $full_dump_file_path = UNISH_SANDBOX . DIRECTORY_SEPARATOR . 'full_db.sql';
29 'result-file' => $full_dump_file_path,
30 // Last 5 entries are for D8+
31 'skip-tables-list' => 'hist*,cache*,router,config*,watchdog,key_valu*',
34 $site_selection_options = array(
39 // Test --extra option
40 if ($this->db_driver() == 'mysql') {
41 $this->drush('sql-dump', array(), array_merge($options, $site_selection_options, array('extra' => '--skip-add-drop-table')));
42 $this->assertFileExists($full_dump_file_path);
43 $full_dump_file = file_get_contents($full_dump_file_path);
44 $this->assertNotContains('DROP TABLE IF EXISTS', $full_dump_file);
48 // First, do a test without any aliases, and dump the whole database
49 $this->drush('sql-dump', array(), array_merge($options, $site_selection_options));
50 $this->assertFileExists($full_dump_file_path);
51 $full_dump_file = file_get_contents($full_dump_file_path);
52 // Test that we have sane contents.
53 $this->assertContains('queue', $full_dump_file);
54 // Test skip-files-list and wildcard expansion.
55 $this->assertNotContains('history', $full_dump_file);
56 // Next, set up an alias file and run a couple of simulated
57 // tests to see if options are propagated correctly.
58 // Control: insure options are not set when not specified
59 unset($options['skip-tables-list']);
60 unlink($full_dump_file_path);
61 $this->drush('sql-dump', array(), array_merge($options, $site_selection_options));
62 $this->assertFileExists($full_dump_file_path);
63 $full_dump_file = file_get_contents($full_dump_file_path);
64 // Test that we have sane contents.
65 $this->assertContains('queue', $full_dump_file);
66 // Test skip-files-list and wildcard expansion.
67 $this->assertContains('history', $full_dump_file);
69 $aliasPath = UNISH_SANDBOX . '/aliases';
71 $aliasFile = $aliasPath . '/bar.aliases.drushrc.php';
72 $aliasContents = <<<EOD
74 // Written by Unish. This file is safe to delete.
75 \$aliases['test'] = array(
79 'command-specific' => array(
81 'skip-tables-list' => 'hist*,cache*,router,config*,watchdog,key_valu*',
86 file_put_contents($aliasFile, $aliasContents);
87 $options['alias-path'] = $aliasPath;
88 unlink($full_dump_file_path);
89 // Now run again with an alias, and test to see if the option is there
90 $this->drush('sql-dump', array(), array_merge($options), '@test');
91 $this->assertFileExists($full_dump_file_path);
92 $full_dump_file = file_get_contents($full_dump_file_path);
93 // Test that we have sane contents.
94 $this->assertContains('queue', $full_dump_file);
95 // Test skip-files-list and wildcard expansion.
96 $this->assertNotContains('history', $full_dump_file);
97 // Repeat control test: options not recovered in absence of an alias.
98 unlink($full_dump_file_path);
99 $this->drush('sql-dump', array(), array_merge($options, $site_selection_options));
100 $this->assertFileExists($full_dump_file_path);
101 $full_dump_file = file_get_contents($full_dump_file_path);
102 // Test that we have sane contents.
103 $this->assertContains('queue', $full_dump_file);
104 // Test skip-files-list and wildcard expansion.
105 $this->assertContains('history', $full_dump_file);
106 // Now run yet with @self, and test to see that Drush can recover the option
107 // --skip-tables-list, defined in @test.
108 unlink($full_dump_file_path);
109 $this->drush('sql-dump', array(), array_merge($options, $site_selection_options), '@self');
110 $this->assertFileExists($full_dump_file_path);
111 $full_dump_file = file_get_contents($full_dump_file_path);
112 // Test that we have sane contents.
113 $this->assertContains('queue', $full_dump_file);
114 // Test skip-files-list and wildcard expansion.
115 $this->assertNotContains('history', $full_dump_file);