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

Classes

Namesort descending Description
archiveDumpCase

File

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