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

Namespace

Unish

Classes

Namesort descending Description
archiveDumpCase Tests for archive-dump and archive-restore

File

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