10ca95f484b1951eaffa14ddf4dfc9df7e223c68
[yaffs-website] / vendor / drush / drush / tests / SqlDumpTest.php
1 <?php
2
3 namespace Unish;
4
5 /**
6  * Tests for sql-dump commands.
7  *
8  * @group commands
9  * @group sql
10  * @group slow
11  */
12 class SqlDumpTest extends CommandUnishTestCase
13 {
14
15   /**
16    * Test that a dump file is created successfully.
17    */
18     public function testSqlDump()
19     {
20         if ($this->dbDriver() == 'sqlite') {
21             $this->markTestSkipped('SQL Dump does not apply to SQLite.');
22             return;
23         }
24
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';
29
30         $options = [
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*',
34         'yes' => null,
35         ];
36
37         $this->drush('sql-dump', [], $options + ['simulate' => null]);
38         $this->assertContains('--ignore-table=unish_dev.cache_discovery', $this->getErrorOutput());
39
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);
46         }
47
48
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);
69
70     // @todo Aliases to local sites are no longer supported. Throw exception?
71     //    $aliasPath = self::getSandbox() . '/aliases';
72     //    mkdir($aliasPath);
73     //    $aliasFile = $aliasPath . '/bar.aliases.drushrc.php';
74     //    $aliasContents = <<<EOD
75     //  <?php
76     //  // Written by Unish. This file is safe to delete.
77     //  \$aliases['test'] = array(
78     //    'root' => '$root',
79     //    'uri' => '$uri',
80     //    'site' => 'stage',
81     //    'command-specific' => array(
82     //      'sql-dump' => array(
83     //        'skip-tables-list' => 'hist*,cache*,router,config*,watchdog,key_valu*',
84     //      ),
85     //    ),
86     //  );
87     //EOD;
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);
118     }
119 }