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

Tests for archive-dump and archive-restore

@group commands

Namespace

Unish

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.
CommandUnishTestCase::$coverage_data protected property Code coverage data collected during a single test.
CommandUnishTestCase::$defaultIdleTimeout private property Default idle timeout for commands.
CommandUnishTestCase::$defaultTimeout private property Default timeout for commands.
CommandUnishTestCase::$idleTimeout protected property Idle timeouts for commands.
CommandUnishTestCase::$process private property Process of last executed command.
CommandUnishTestCase::$timeout protected property Timeout for command.
CommandUnishTestCase::assertLogHasMessage function Ensure that an expected log message appears in the Drush log.
CommandUnishTestCase::drush function Invoke drush in via execute().
CommandUnishTestCase::drush_major_version function
CommandUnishTestCase::execute function Actually runs the command.
CommandUnishTestCase::EXIT_ERROR constant
CommandUnishTestCase::EXIT_SUCCESS constant
CommandUnishTestCase::getErrorOutput function Accessor for the last stderr output, trimmed.
CommandUnishTestCase::getErrorOutputAsList function Accessor for the last stderr output, rtrimmed and split on newlines.
CommandUnishTestCase::getErrorOutputRaw function Accessor for the last stderr output, non-trimmed.
CommandUnishTestCase::getOutput function Accessor for the last output, trimmed.
CommandUnishTestCase::getOutputAsList function Accessor for the last output, rtrimmed and split on newlines.
CommandUnishTestCase::getOutputFromJSON function Accessor for the last output, decoded from json.
CommandUnishTestCase::getOutputRaw function Accessor for the last output, non-trimmed.
CommandUnishTestCase::parse_backend_output function A slightly less functional copy of drush_backend_parse_output().
CommandUnishTestCase::run public function Override the run method, so we can add in our code coverage data after the test has run.
CommandUnishTestCase::UNISH_EXITCODE_USER_ABORT constant
UnishTestCase::$sites private static property A list of Drupal sites that have been recently installed. They key is the site name and values are details about each site.
UnishTestCase::bit_bucket function Borrowed from Drush. Checks operating system and returns supported bit bucket folder.
UnishTestCase::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).
UnishTestCase::db_driver function
UnishTestCase::db_url function
UnishTestCase::directory_cache function
UnishTestCase::drupalSitewideDirectory function
UnishTestCase::escapeshellarg public static function
UnishTestCase::fetchInstallDrupal function
UnishTestCase::getSites function
UnishTestCase::get_tar_executable public static function
UnishTestCase::is_windows public static function
UnishTestCase::log function Print a log message to the console.
UnishTestCase::log_level function
UnishTestCase::mkdir public function
UnishTestCase::randomString public function Helper function to generate a random string of arbitrary length.
UnishTestCase::recursive_copy public function
UnishTestCase::setUpBeforeClass public static function Assure that each class starts with an empty sandbox directory and a clean environment - http://drupal.org/node/1103568.
UnishTestCase::setUpDrupal function
UnishTestCase::setUpFreshSandBox public static function Remove any pre-existing sandbox, then create a new one.
UnishTestCase::tearDownAfterClass public static function Runs after all tests in a class are run. Remove sandbox directory.
UnishTestCase::tick function Print out a tick mark.
UnishTestCase::unish_file_aliases function Prepare the contents of an aliases file.
UnishTestCase::webroot function
UnishTestCase::writeSiteAlias function
UnishTestCase::_escapeshellarg_windows public static function
UnishTestCase::__construct function

File

tests/archiveDumpTest.php, line 12

View source
class archiveDumpCase extends CommandUnishTestCase {
  /**
   * 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) {
    $profile = UNISH_DRUPAL_MAJOR_VERSION >= 7 ? 'testing' : 'default';
    $this->fetchInstallDrupal(self::uri, TRUE, UNISH_DRUPAL_MAJOR_VERSION, $profile);
    $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, TRUE);
    $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();
    $expected = '%sgzip compressed data%s';
    $this->assertStringMatchesFormat($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) {
    $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);
    $modules_dir = UNISH_DRUPAL_MAJOR_VERSION >= 8 ? '/core/modules' : '/modules';
    $this->assertFileNotExists($untar_dest . '/' . $docroot . $modules_dir, '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, TRUE);
    $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);
  }
}