5 require_once dirname(__FILE__) . '/../includes/filesystem.inc';
8 * Tests for archive-dump and archive-restore
12 class archiveDumpCase extends CommandUnishTestCase {
14 * archive-dump behaves slightly different when archiving a site installed
15 * at sites/default so we make the test to use sites/default as the
16 * installation directory instead of default sites/dev.
18 const uri = 'default';
21 * Install a site and dump it to an archive.
23 private function archiveDump($no_core) {
24 $profile = UNISH_DRUPAL_MAJOR_VERSION >= 7 ? 'testing' : 'default';
25 $this->fetchInstallDrupal(self::uri, TRUE, NULL, $profile);
26 $root = $this->webroot();
27 $dump_dest = UNISH_SANDBOX . DIRECTORY_SEPARATOR . 'dump.tar.gz';
32 'destination' => $dump_dest,
36 $options['no-core'] = NULL;
38 $this->drush('archive-dump', array(self::uri), $options);
44 * Untar an archive and return the path to the untarred folder.
46 private function unTar($dump_dest) {
47 $untar_dest = UNISH_SANDBOX . DIRECTORY_SEPARATOR . 'untar';
48 unish_file_delete_recursive($untar_dest, TRUE);
49 $tar = self::get_tar_executable();
50 $exec = sprintf("mkdir %s && cd %s && $tar -xzf %s", $untar_dest, $untar_dest, $dump_dest);
51 $this->execute($exec);
57 * Test if tarball generated by archive-dump looks right.
59 public function testArchiveDump() {
60 $dump_dest = $this->archiveDump(FALSE);
61 $docroot = basename($this->webroot());
63 // Check the dump file is a gzip file.
64 $exec = sprintf('file %s', $dump_dest);
65 $this->execute($exec);
66 $output = $this->getOutput();
67 $expected = '%sgzip compressed data%s';
68 $this->assertStringMatchesFormat($expected, $output);
70 // Untar the archive and make sure it looks right.
71 $untar_dest = $this->unTar($dump_dest);
73 if (strpos(UNISH_DB_URL, 'mysql') !== FALSE) {
74 $this->execute(sprintf('head %s/unish_%s.sql | grep "MySQL dump"', $untar_dest, self::uri));
76 $this->assertFileExists($untar_dest . '/MANIFEST.ini');
77 $this->assertFileExists($untar_dest . '/' . $docroot);
83 * Test archive-restore.
85 * Restore the archive generated in testArchiveDump() and verify that the
86 * directory contents are identical.
88 * @depends testArchiveDump
90 public function testArchiveRestore($dump_dest) {
91 $restore_dest = UNISH_SANDBOX . DIRECTORY_SEPARATOR . 'restore';
94 'destination' => $restore_dest,
96 $this->drush('archive-restore', array($dump_dest), $options);
97 $original_codebase = drush_dir_md5($this->webroot());
98 $restored_codebase = drush_dir_md5($restore_dest);
99 $this->assertEquals($original_codebase, $restored_codebase);
103 * Test if tarball generated by archive-dump with --no-core looks right.
105 public function testArchiveDumpNoCore() {
106 $dump_dest = $this->archiveDump(TRUE);
107 $untar_dest = $this->unTar($dump_dest);
108 $docroot = basename($this->webroot());
109 $this->assertFileExists($untar_dest . '/MANIFEST.ini');
110 $this->assertFileExists($untar_dest . '/' . $docroot);
111 $modules_dir = UNISH_DRUPAL_MAJOR_VERSION >= 8 ? '/core/modules' : '/modules';
112 $this->assertFileNotExists($untar_dest . '/' . $docroot . $modules_dir, 'No modules directory should exist with --no-core');
118 * Test archive-restore for a site archive (--no-core).
120 * @depends testArchiveDumpNoCore
122 public function testArchiveRestoreNoCore($dump_dest) {
123 $root = $this->webroot();
124 $original_codebase = drush_dir_md5($root);
125 unish_file_delete_recursive($root . '/sites/' . self::uri, TRUE);
128 'destination' => $root,
130 $this->drush('archive-restore', array($dump_dest), $options);
132 $restored_codebase = drush_dir_md5($root);
133 $this->assertEquals($original_codebase, $restored_codebase);