5 require_once dirname(__FILE__) . '/../includes/context.inc';
6 require_once dirname(__FILE__) . '/../includes/filesystem.inc';
9 * Tests for archive-dump and archive-restore
13 class archiveDumpCase extends CommandUnishTestCase {
15 * archive-dump behaves slightly different when archiving a site installed
16 * at sites/default so we make the test to use sites/default as the
17 * installation directory instead of default sites/dev.
19 const uri = 'default';
22 * Install a site and dump it to an archive.
24 private function archiveDump($no_core) {
25 $profile = UNISH_DRUPAL_MAJOR_VERSION >= 7 ? 'testing' : 'default';
26 $this->fetchInstallDrupal(self::uri, TRUE, NULL, $profile);
27 $root = $this->webroot();
28 $dump_dest = UNISH_SANDBOX . DIRECTORY_SEPARATOR . 'dump.tar.gz';
33 'destination' => $dump_dest,
37 $options['no-core'] = NULL;
39 $this->drush('archive-dump', array(self::uri), $options);
45 * Untar an archive and return the path to the untarred folder.
47 private function unTar($dump_dest) {
48 $untar_dest = UNISH_SANDBOX . DIRECTORY_SEPARATOR . 'untar';
49 unish_file_delete_recursive($untar_dest, TRUE);
50 $tar = self::get_tar_executable();
51 $exec = sprintf("mkdir %s && cd %s && $tar -xzf %s", $untar_dest, $untar_dest, $dump_dest);
52 $this->execute($exec);
58 * Test if tarball generated by archive-dump looks right.
60 public function testArchiveDump() {
61 $dump_dest = $this->archiveDump(FALSE);
62 $docroot = basename($this->webroot());
64 // Check the dump file is a gzip file.
65 $exec = sprintf('file %s', $dump_dest);
66 $this->execute($exec);
67 $output = $this->getOutput();
68 $expected = '%sgzip compressed data%s';
69 $this->assertStringMatchesFormat($expected, $output);
71 // Untar the archive and make sure it looks right.
72 $untar_dest = $this->unTar($dump_dest);
74 if (strpos(UNISH_DB_URL, 'mysql') !== FALSE) {
75 $this->execute(sprintf('head %s/unish_%s.sql | grep "MySQL dump"', $untar_dest, self::uri));
77 $this->assertFileExists($untar_dest . '/MANIFEST.ini');
78 $this->assertFileExists($untar_dest . '/' . $docroot);
84 * Test archive-restore.
86 * Restore the archive generated in testArchiveDump() and verify that the
87 * directory contents are identical.
89 * @depends testArchiveDump
91 public function testArchiveRestore($dump_dest) {
92 $restore_dest = UNISH_SANDBOX . DIRECTORY_SEPARATOR . 'restore';
95 'destination' => $restore_dest,
97 $this->drush('archive-restore', array($dump_dest), $options);
98 $original_codebase = drush_dir_md5($this->webroot());
99 $restored_codebase = drush_dir_md5($restore_dest);
100 $this->assertEquals($original_codebase, $restored_codebase);
104 * Test if tarball generated by archive-dump with --no-core looks right.
106 public function testArchiveDumpNoCore() {
107 $dump_dest = $this->archiveDump(TRUE);
108 $untar_dest = $this->unTar($dump_dest);
109 $docroot = basename($this->webroot());
110 $this->assertFileExists($untar_dest . '/MANIFEST.ini');
111 $this->assertFileExists($untar_dest . '/' . $docroot);
112 $modules_dir = UNISH_DRUPAL_MAJOR_VERSION >= 8 ? '/core/modules' : '/modules';
113 $this->assertFileNotExists($untar_dest . '/' . $docroot . $modules_dir, 'No modules directory should exist with --no-core');
119 * Test archive-restore for a site archive (--no-core).
121 * @depends testArchiveDumpNoCore
123 public function testArchiveRestoreNoCore($dump_dest) {
124 $root = $this->webroot();
125 $original_codebase = drush_dir_md5($root);
126 unish_file_delete_recursive($root . '/sites/' . self::uri, TRUE);
129 'destination' => $root,
131 $this->drush('archive-restore', array($dump_dest), $options);
133 $restored_codebase = drush_dir_md5($root);
134 $this->assertEquals($original_codebase, $restored_codebase);