class archiveDumpCase

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

Hierarchy

Expanded class hierarchy of archiveDumpCase

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description
archiveDumpCase::archiveDump private function Install a site and dump it to an archive.
archiveDumpCase::testArchiveDump public function Test if tarball generated by archive-dump looks right.
archiveDumpCase::testArchiveDumpNoCore public function Test if tarball generated by archive-dump with --no-core looks right.
archiveDumpCase::testArchiveRestore public function Test archive-restore.
archiveDumpCase::testArchiveRestoreNoCore public function Test archive-restore for a site archive (--no-core).
archiveDumpCase::unTar private function Untar an archive and return the path to the untarred folder.
archiveDumpCase::uri constant archive-dump behaves slightly different when archiving a site installed at sites/default so we make the test to use sites/default as the installation directory instead of default sites/dev.
Drush_CommandTestCase::drush function Invoke drush in via execute().
Drush_CommandTestCase::drush_major_version function
Drush_CommandTestCase::execute function Actually runs the command. Does not trap the error stream output as this need PHP 4.3+.
Drush_CommandTestCase::EXIT_ERROR constant
Drush_CommandTestCase::EXIT_SUCCESS constant
Drush_CommandTestCase::file_aliases function
Drush_TestCase::bit_bucket function Borrowed from Drush. Checks operating system and returns supported bit bucket folder.
Drush_TestCase::convert_path function Converts a Windows path (dir1\dir2\dir3) into a Unix path (dir1/dir2/dir3). Also converts a cygwin "drive emulation" path (/cygdrive/c/dir1) into a proper drive path, still with Unix slashes (c:/dir1).
Drush_TestCase::db_url function
Drush_TestCase::directory_cache function
Drush_TestCase::escapeshellarg public static function
Drush_TestCase::fetchInstallDrupal function
Drush_TestCase::getOutput function Accessor for the last output.
Drush_TestCase::getOutputAsList function Accessor for the last output.
Drush_TestCase::get_tar_executable public static function
Drush_TestCase::is_windows public static function
Drush_TestCase::log function Print a log message to the console.
Drush_TestCase::log_level function
Drush_TestCase::randomString public function Helper function to generate a random string of arbitrary length.
Drush_TestCase::setUpBeforeClass public static function Assure that each class starts with an empty sandbox directory and a clean environment - http://drupal.org/node/1103568.
Drush_TestCase::setUpDrupal function
Drush_TestCase::setUpFreshSandBox public static function Remove any pre-existing sandbox, then create a new one.
Drush_TestCase::tearDownAfterClass public static function Runs after all tests in a class are run. Remove sandbox directory.
Drush_TestCase::webroot function
Drush_TestCase::_escapeshellarg_windows public static function
Drush_TestCase::__construct function

File

tests/archiveDumpTest.php, line 8

View source
class archiveDumpCase extends Drush_CommandTestCase {
  /**
   * archive-dump behaves slightly different when archiving a site installed
   * at sites/default so we make the test to use sites/default as the
   * installation directory instead of default sites/dev.
   */
  const uri = 'default';

  /**
   * Install a site and dump it to an archive.
   */
  private function archiveDump($no_core) {
    $this->fetchInstallDrupal(self::uri, TRUE, UNISH_DRUPAL_MAJOR_VERSION, 'testing');
    $root = $this->webroot();
    $dump_dest = UNISH_SANDBOX . DIRECTORY_SEPARATOR . 'dump.tar.gz';
    $options = array(
      'root' => $root,
      'uri' => self::uri,
      'yes' => NULL,
      'destination' => $dump_dest,
      'overwrite' => NULL,
    );
    if ($no_core) {
      $options['no-core'] = NULL;
    }
    $this->drush('archive-dump', array(self::uri), $options);

    return $dump_dest;
  }

  /**
   * Untar an archive and return the path to the untarred folder.
   */
  private function unTar($dump_dest) {
    $untar_dest = UNISH_SANDBOX . DIRECTORY_SEPARATOR . 'untar';
    unish_file_delete_recursive($untar_dest);
    $tar = self::get_tar_executable();
    $exec = sprintf("mkdir %s && cd %s && $tar -xzf %s", $untar_dest, $untar_dest, $dump_dest);
    $this->execute($exec);

    return $untar_dest;
  }

  /**
   * Test if tarball generated by archive-dump looks right.
   */
  public function testArchiveDump() {
    $dump_dest = $this->archiveDump(FALSE);
    $docroot = basename($this->webroot());

    // Check the dump file is a gzip file.
    $exec = sprintf('file %s', $dump_dest);
    $this->execute($exec);
    $output = $this->getOutput();
    $sep = self::is_windows() ? ';' : ':';
    $expected = $dump_dest . "$sep gzip compressed data, from";
    $this->assertStringStartsWith($expected, $output);

    // Untar the archive and make sure it looks right.
    $untar_dest = $this->unTar($dump_dest);

    if (strpos(UNISH_DB_URL, 'mysql') !== FALSE) {
      $this->execute(sprintf('head %s/unish_%s.sql | grep "MySQL dump"', $untar_dest, self::uri));
    }
    $this->assertFileExists($untar_dest . '/MANIFEST.ini');
    $this->assertFileExists($untar_dest . '/' . $docroot);

    return $dump_dest;
  }

  /**
   * Test archive-restore.
   *
   * Restore the archive generated in testArchiveDump() and verify that the
   * directory contents are identical.
   *
   * @depends testArchiveDump
   */
  public function testArchiveRestore($dump_dest) {
    require_once dirname(__FILE__) . '/../includes/filesystem.inc';
    $restore_dest = UNISH_SANDBOX . DIRECTORY_SEPARATOR . 'restore';
    $options = array(
      'yes' => NULL,
      'destination' => $restore_dest,
    );
    $this->drush('archive-restore', array($dump_dest), $options);
    $original_codebase = drush_dir_md5($this->webroot());
    $restored_codebase = drush_dir_md5($restore_dest);
    $this->assertEquals($original_codebase, $restored_codebase);
  }

  /**
   * Test if tarball generated by archive-dump with --no-core looks right.
   */
  public function testArchiveDumpNoCore() {
    $dump_dest = $this->archiveDump(TRUE);
    $untar_dest = $this->unTar($dump_dest);
    $docroot = basename($this->webroot());
    $this->assertFileExists($untar_dest . '/MANIFEST.ini');
    $this->assertFileExists($untar_dest . '/' . $docroot);
    $this->assertFileNotExists($untar_dest . '/' . $docroot . '/modules', 'No modules directory should exist with --no-core');

    return $dump_dest;
  }

  /**
   * Test archive-restore for a site archive (--no-core).
   *
   * @depends testArchiveDumpNoCore
   */
  public function testArchiveRestoreNoCore($dump_dest) {
    $root = $this->webroot();
    $original_codebase = drush_dir_md5($root);
    unish_file_delete_recursive($root . '/sites/' . self::uri);

    $options = array(
      'yes' => NULL,
      'destination' => $root,
    );
    $this->drush('archive-restore', array($dump_dest), $options);

    $restored_codebase = drush_dir_md5($root);
    $this->assertEquals($original_codebase, $restored_codebase);
  }
}