archiveDumpTest.php

  1. 8.0.x tests/archiveDumpTest.php
  2. 6.x tests/archiveDumpTest.php
  3. 7.x tests/archiveDumpTest.php
  4. 4.x tests/archiveDumpTest.php
  5. 5.x tests/archiveDumpTest.php
  6. master tests/archiveDumpTest.php

Tests for archive-dump and archive-restore @group commands

Classes

Namesort descending Description
archiveDumpCase

File

tests/archiveDumpTest.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Tests for archive-dump and archive-restore
  5. * @group commands
  6. */
  7. require_once dirname(__FILE__) . '/../includes/filesystem.inc';
  8. class archiveDumpCase extends Drush_CommandTestCase {
  9. /**
  10. * archive-dump behaves slightly different when archiving a site installed
  11. * at sites/default so we make the test to use sites/default as the
  12. * installation directory instead of default sites/dev.
  13. */
  14. const uri = 'default';
  15. /**
  16. * Install a site and dump it to an archive.
  17. */
  18. private function archiveDump($no_core) {
  19. $profile = UNISH_DRUPAL_MAJOR_VERSION >= 7 ? 'testing' : 'default';
  20. $this->fetchInstallDrupal(self::uri, TRUE, UNISH_DRUPAL_MAJOR_VERSION, $profile);
  21. $root = $this->webroot();
  22. $dump_dest = UNISH_SANDBOX . DIRECTORY_SEPARATOR . 'dump.tar.gz';
  23. $options = array(
  24. 'root' => $root,
  25. 'uri' => self::uri,
  26. 'yes' => NULL,
  27. 'destination' => $dump_dest,
  28. 'overwrite' => NULL,
  29. );
  30. if ($no_core) {
  31. $options['no-core'] = NULL;
  32. }
  33. $this->drush('archive-dump', array(self::uri), $options);
  34. return $dump_dest;
  35. }
  36. /**
  37. * Untar an archive and return the path to the untarred folder.
  38. */
  39. private function unTar($dump_dest) {
  40. $untar_dest = UNISH_SANDBOX . DIRECTORY_SEPARATOR . 'untar';
  41. unish_file_delete_recursive($untar_dest, TRUE);
  42. $tar = self::get_tar_executable();
  43. $exec = sprintf("mkdir %s && cd %s && $tar -xzf %s", $untar_dest, $untar_dest, $dump_dest);
  44. $this->execute($exec);
  45. return $untar_dest;
  46. }
  47. /**
  48. * Test if tarball generated by archive-dump looks right.
  49. */
  50. public function testArchiveDump() {
  51. $dump_dest = $this->archiveDump(FALSE);
  52. $docroot = basename($this->webroot());
  53. // Check the dump file is a gzip file.
  54. $exec = sprintf('file %s', $dump_dest);
  55. $this->execute($exec);
  56. $output = $this->getOutput();
  57. $expected = '%sgzip compressed data%s';
  58. $this->assertStringMatchesFormat($expected, $output);
  59. // Untar the archive and make sure it looks right.
  60. $untar_dest = $this->unTar($dump_dest);
  61. if (strpos(UNISH_DB_URL, 'mysql') !== FALSE) {
  62. $this->execute(sprintf('head %s/unish_%s.sql | grep "MySQL dump"', $untar_dest, self::uri));
  63. }
  64. $this->assertFileExists($untar_dest . '/MANIFEST.ini');
  65. $this->assertFileExists($untar_dest . '/' . $docroot);
  66. return $dump_dest;
  67. }
  68. /**
  69. * Test archive-restore.
  70. *
  71. * Restore the archive generated in testArchiveDump() and verify that the
  72. * directory contents are identical.
  73. *
  74. * @depends testArchiveDump
  75. */
  76. public function testArchiveRestore($dump_dest) {
  77. $restore_dest = UNISH_SANDBOX . DIRECTORY_SEPARATOR . 'restore';
  78. $options = array(
  79. 'yes' => NULL,
  80. 'destination' => $restore_dest,
  81. );
  82. $this->drush('archive-restore', array($dump_dest), $options);
  83. $original_codebase = drush_dir_md5($this->webroot());
  84. $restored_codebase = drush_dir_md5($restore_dest);
  85. $this->assertEquals($original_codebase, $restored_codebase);
  86. }
  87. /**
  88. * Test if tarball generated by archive-dump with --no-core looks right.
  89. */
  90. public function testArchiveDumpNoCore() {
  91. $dump_dest = $this->archiveDump(TRUE);
  92. $untar_dest = $this->unTar($dump_dest);
  93. $docroot = basename($this->webroot());
  94. $this->assertFileExists($untar_dest . '/MANIFEST.ini');
  95. $this->assertFileExists($untar_dest . '/' . $docroot);
  96. $modules_dir = UNISH_DRUPAL_MAJOR_VERSION >= 8 ? '/core/modules' : '/modules';
  97. $this->assertFileNotExists($untar_dest . '/' . $docroot . $modules_dir, 'No modules directory should exist with --no-core');
  98. return $dump_dest;
  99. }
  100. /**
  101. * Test archive-restore for a site archive (--no-core).
  102. *
  103. * @depends testArchiveDumpNoCore
  104. */
  105. public function testArchiveRestoreNoCore($dump_dest) {
  106. $root = $this->webroot();
  107. $original_codebase = drush_dir_md5($root);
  108. unish_file_delete_recursive($root . '/sites/' . self::uri, TRUE);
  109. $options = array(
  110. 'yes' => NULL,
  111. 'destination' => $root,
  112. );
  113. $this->drush('archive-restore', array($dump_dest), $options);
  114. $restored_codebase = drush_dir_md5($root);
  115. $this->assertEquals($original_codebase, $restored_codebase);
  116. }
  117. }