forked from drush-ops/drush
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchiveDumpTest.php
135 lines (118 loc) · 4.17 KB
/
archiveDumpTest.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
namespace Unish;
require_once dirname(__FILE__) . '/../includes/filesystem.inc';
/**
* Tests for archive-dump and archive-restore
*
* @group commands
*/
class archiveDumpCase extends CommandUnishTestCase {
/**
* archive-dump behaves slightly different when archiving a site installed
* at sites/default so we make the test to use sites/default as the
* installation directory instead of default sites/dev.
*/
const uri = 'default';
/**
* Install a site and dump it to an archive.
*/
private function archiveDump($no_core) {
$profile = UNISH_DRUPAL_MAJOR_VERSION >= 7 ? 'testing' : 'default';
$this->fetchInstallDrupal(self::uri, TRUE, UNISH_DRUPAL_MAJOR_VERSION, $profile);
$root = $this->webroot();
$dump_dest = UNISH_SANDBOX . DIRECTORY_SEPARATOR . 'dump.tar.gz';
$options = array(
'root' => $root,
'uri' => self::uri,
'yes' => NULL,
'destination' => $dump_dest,
'overwrite' => NULL,
);
if ($no_core) {
$options['no-core'] = NULL;
}
$this->drush('archive-dump', array(self::uri), $options);
return $dump_dest;
}
/**
* Untar an archive and return the path to the untarred folder.
*/
private function unTar($dump_dest) {
$untar_dest = UNISH_SANDBOX . DIRECTORY_SEPARATOR . 'untar';
unish_file_delete_recursive($untar_dest, TRUE);
$tar = self::get_tar_executable();
$exec = sprintf("mkdir %s && cd %s && $tar -xzf %s", $untar_dest, $untar_dest, $dump_dest);
$this->execute($exec);
return $untar_dest;
}
/**
* Test if tarball generated by archive-dump looks right.
*/
public function testArchiveDump() {
$dump_dest = $this->archiveDump(FALSE);
$docroot = basename($this->webroot());
// Check the dump file is a gzip file.
$exec = sprintf('file %s', $dump_dest);
$this->execute($exec);
$output = $this->getOutput();
$expected = '%sgzip compressed data%s';
$this->assertStringMatchesFormat($expected, $output);
// Untar the archive and make sure it looks right.
$untar_dest = $this->unTar($dump_dest);
if (strpos(UNISH_DB_URL, 'mysql') !== FALSE) {
$this->execute(sprintf('head %s/unish_%s.sql | grep "MySQL dump"', $untar_dest, self::uri));
}
$this->assertFileExists($untar_dest . '/MANIFEST.ini');
$this->assertFileExists($untar_dest . '/' . $docroot);
return $dump_dest;
}
/**
* Test archive-restore.
*
* Restore the archive generated in testArchiveDump() and verify that the
* directory contents are identical.
*
* @depends testArchiveDump
*/
public function testArchiveRestore($dump_dest) {
$restore_dest = UNISH_SANDBOX . DIRECTORY_SEPARATOR . 'restore';
$options = array(
'yes' => NULL,
'destination' => $restore_dest,
);
$this->drush('archive-restore', array($dump_dest), $options);
$original_codebase = drush_dir_md5($this->webroot());
$restored_codebase = drush_dir_md5($restore_dest);
$this->assertEquals($original_codebase, $restored_codebase);
}
/**
* Test if tarball generated by archive-dump with --no-core looks right.
*/
public function testArchiveDumpNoCore() {
$dump_dest = $this->archiveDump(TRUE);
$untar_dest = $this->unTar($dump_dest);
$docroot = basename($this->webroot());
$this->assertFileExists($untar_dest . '/MANIFEST.ini');
$this->assertFileExists($untar_dest . '/' . $docroot);
$modules_dir = UNISH_DRUPAL_MAJOR_VERSION >= 8 ? '/core/modules' : '/modules';
$this->assertFileNotExists($untar_dest . '/' . $docroot . $modules_dir, 'No modules directory should exist with --no-core');
return $dump_dest;
}
/**
* Test archive-restore for a site archive (--no-core).
*
* @depends testArchiveDumpNoCore
*/
public function testArchiveRestoreNoCore($dump_dest) {
$root = $this->webroot();
$original_codebase = drush_dir_md5($root);
unish_file_delete_recursive($root . '/sites/' . self::uri, TRUE);
$options = array(
'yes' => NULL,
'destination' => $root,
);
$this->drush('archive-restore', array($dump_dest), $options);
$restored_codebase = drush_dir_md5($root);
$this->assertEquals($original_codebase, $restored_codebase);
}
}