forked from drush-ops/drush
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqlDumpTest.php
107 lines (101 loc) · 4.04 KB
/
sqlDumpTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
namespace Unish;
/**
* Tests for sql-dump commands.
*
* @group commands
* @group sql
* @group slow
*/
class SqlDumpTest extends CommandUnishTestCase {
/**
* Test that a dump file is created successfully.
*/
function testSqlDump() {
if ($this->db_driver() == 'sqlite') {
$this->markTestSkipped('SQL Dump does not apply to SQLite.');
return;
}
$this->setUpDrupal(1, TRUE);
$root = $this->webroot();
$uri = 'dev';
$full_dump_file_path = UNISH_SANDBOX . DIRECTORY_SEPARATOR . 'full_db.sql';
$options = array(
'result-file' => $full_dump_file_path,
// Last 5 entries are for D8+
'skip-tables-list' => 'hist*,cache*,router,config*,watchdog,key_valu*',
'yes' => NULL,
);
$site_selection_options = array(
'root' => $root,
'uri' => $uri,
);
// First, do a test without any aliases, and dump the whole database
$this->drush('sql-dump', array(), array_merge($options, $site_selection_options));
$this->assertFileExists($full_dump_file_path);
$full_dump_file = file_get_contents($full_dump_file_path);
// Test that we have sane contents.
$this->assertContains('batch', $full_dump_file);
// Test skip-files-list and wildcard expansion.
$this->assertNotContains('history', $full_dump_file);
// Next, set up an alias file and run a couple of simulated
// tests to see if options are propagated correctly.
// Control: insure options are not set when not specified
unset($options['skip-tables-list']);
unlink($full_dump_file_path);
$this->drush('sql-dump', array(), array_merge($options, $site_selection_options));
$this->assertFileExists($full_dump_file_path);
$full_dump_file = file_get_contents($full_dump_file_path);
// Test that we have sane contents.
$this->assertContains('batch', $full_dump_file);
// Test skip-files-list and wildcard expansion.
$this->assertContains('history', $full_dump_file);
$aliasPath = UNISH_SANDBOX . '/aliases';
mkdir($aliasPath);
$aliasFile = $aliasPath . '/bar.aliases.drushrc.php';
$aliasContents = <<<EOD
<?php
// Written by Unish. This file is safe to delete.
\$aliases['test'] = array(
'root' => '$root',
'uri' => '$uri',
'site' => 'stage',
'command-specific' => array(
'sql-dump' => array(
'skip-tables-list' => 'hist*,cache*,router,config*,watchdog,key_valu*',
),
),
);
EOD;
file_put_contents($aliasFile, $aliasContents);
$options['alias-path'] = $aliasPath;
unlink($full_dump_file_path);
// Now run again with an alias, and test to see if the option is there
$this->drush('sql-dump', array(), array_merge($options), '@test');
$this->assertFileExists($full_dump_file_path);
$full_dump_file = file_get_contents($full_dump_file_path);
// Test that we have sane contents.
$this->assertContains('batch', $full_dump_file);
// Test skip-files-list and wildcard expansion.
$this->assertNotContains('history', $full_dump_file);
// Repeat control test: options not recovered in absence of an alias.
unlink($full_dump_file_path);
$this->drush('sql-dump', array(), array_merge($options, $site_selection_options));
$this->assertFileExists($full_dump_file_path);
$full_dump_file = file_get_contents($full_dump_file_path);
// Test that we have sane contents.
$this->assertContains('batch', $full_dump_file);
// Test skip-files-list and wildcard expansion.
$this->assertContains('history', $full_dump_file);
// Now run yet with @self, and test to see that Drush can recover the option
// --skip-tables-list, defined in @test.
unlink($full_dump_file_path);
$this->drush('sql-dump', array(), array_merge($options, $site_selection_options), '@self');
$this->assertFileExists($full_dump_file_path);
$full_dump_file = file_get_contents($full_dump_file_path);
// Test that we have sane contents.
$this->assertContains('batch', $full_dump_file);
// Test skip-files-list and wildcard expansion.
$this->assertNotContains('history', $full_dump_file);
}
}