class coreCase

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

@file Tests for core commands.

@group commands

Hierarchy

Expanded class hierarchy of coreCase

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description
coreCase::testCoreRequirements function
coreCase::testDrupalDirectory function
coreCase::testPercentFilesOptimization function Test to see if the optimized code path in drush_sitealias_resolve_path_references that avoids a call to backend invoke when evaluating %files works.
coreCase::testRsyncPercentFiles function Test to see if rsync @site:%files calculates the %files path correctly. This tests the non-optimized code path in drush_sitealias_resolve_path_references.
coreCase::testStandaloneScript public function Test standalone php-script scripts. Assure that script args and options work.
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_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_driver function
Drush_TestCase::db_url function
Drush_TestCase::directory_cache function
Drush_TestCase::drupalSitewideDirectory 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::getOutputFromJSON function Accessor for the last output, decoded from json.
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/coreTest.php, line 9
Tests for core commands.

View source
class coreCase extends Drush_CommandTestCase {
  /**
   * Test to see if rsync @site:%files calculates the %files path correctly.
   * This tests the non-optimized code path in drush_sitealias_resolve_path_references.
   */
  function testRsyncPercentFiles() {
    $this->setUpDrupal(1, TRUE);
    $root = $this->webroot();
    $site = key($this->sites);
    $options = array(
      'root' => $root,
      'uri' => key($this->sites),
      'simulate' => NULL,
      'include-conf' => NULL,
      'include-vcs' => NULL,
      'yes' => NULL,
    );
    $this->drush('core-rsync', array("@$site:%files", "/tmp"), $options, NULL, NULL, self::EXIT_SUCCESS, '2>&1;');
    $output = $this->getOutput();
    $level = $this->log_level();
    $pattern = in_array($level, array('verbose', 'debug')) ? "Calling system(rsync -e 'ssh ' -akzv --stats --progress --yes %s /tmp);" : "Calling system(rsync -e 'ssh ' -akz --yes %s /tmp);";
    $expected = sprintf($pattern, UNISH_SANDBOX . "/web/sites/$site/files");
    $this->assertEquals($expected, $output);
  }

  /**
   * Test to see if the optimized code path in drush_sitealias_resolve_path_references
   * that avoids a call to backend invoke when evaluating %files works.
   */
  function testPercentFilesOptimization() {
    $this->setUpDrupal(1, TRUE);
    $root = $this->webroot();
    $site = key($this->sites);
    $options = array(
      'root' => $root,
      'uri' => key($this->sites),
      'simulate' => NULL,
      'include-conf' => NULL,
      'include-vcs' => NULL,
      'yes' => NULL,
      'strict' => 0, // invoke from script: do not verify options
    );
    $php = '$a=drush_sitealias_get_record("@' . $site . '"); drush_sitealias_resolve_path_references($a, "%files"); print_r($a["path-aliases"]["%files"]);';
    $this->drush('ev', array($php), $options);
    $output = $this->getOutput();
    $expected = "sites/dev/files";
    $this->assertEquals($expected, $output);
  }

  /**
   * Test standalone php-script scripts. Assure that script args and options work.
   */
  public function testStandaloneScript() {
    if ($this->is_windows()) {
      $this->markTestSkipped('Standalone scripts not currently available on Windows.');
    }

    $this->drush('version', array('drush_version'), array('pipe' => NULL));
    $standard = $this->getOutput();

    // Write out a hellounish.script into the sandbox. The correct /path/to/drush
    // is in the shebang line.
    $filename = 'hellounish.script';
    $data = '#!/usr/bin/env [PATH-TO-DRUSH]

$arg = drush_shift();
drush_invoke("version", $arg);
';
    $data = str_replace('[PATH-TO-DRUSH]', UNISH_DRUSH, $data);
    $script = UNISH_SANDBOX . '/' . $filename;
    file_put_contents($script, $data);
    chmod($script, 0755);
    $this->execute("$script drush_version --pipe");
    $standalone = $this->getOutput();
    $this->assertEquals($standard, $standalone);
  }

  function testDrupalDirectory() {
    $this->setUpDrupal(1, TRUE);
    $root = $this->webroot();
    $sitewide = $this->drupalSitewideDirectory();
    $options = array(
      'root' => $root,
      'uri' => key($this->sites),
      'yes' => NULL,
      'skip' => NULL,
      'cache' => NULL,
      'strict' => 0, // invoke from script: do not verify options
    );
    $this->drush('pm-download', array('devel'), $options);
    $this->drush('pm-enable', array('devel', 'menu'), $options);
    $this->drush('pm-download', array('zen'), $options);

    $this->drush('drupal-directory', array('devel'), $options);
    $output = $this->getOutput();
    $this->assertEquals($root . '/' . $sitewide . '/modules/devel', $output);

    $this->drush('drupal-directory', array('zen'), $options);
    $output = $this->getOutput();
    $this->assertEquals($root . '/' . $sitewide . '/themes/zen', $output);

    $this->drush('drupal-directory', array('%files'), $options);
    $output = $this->getOutput();
    $this->assertEquals($root . '/sites/dev/files', $output);

    $this->drush('drupal-directory', array('%modules'), $options);
    $output = $this->getOutput();
    $this->assertEquals($root . '/' . $sitewide . '/modules', $output);
  }

  function testCoreRequirements() {
    $this->setUpDrupal(1, TRUE);
    $root = $this->webroot();
    $options = array(
      'root' => $root,
      'uri' => key($this->sites),
      'pipe' => NULL,
      'ignore' => 'cron,http requests,update_core', // no network access when running in tests, so ignore these
      'strict' => 0, // invoke from script: do not verify options
    );
    // Verify that there are no severity 2 items in the status report
    $this->drush('core-requirements', array(), $options + array('severity' => '2'));
    $output = $this->getOutput();
    $this->assertEquals('', $output);

    $this->drush('core-requirements', array(), $options);
    $loaded = $this->getOutputFromJSON();
    // Pick a subset that are valid for D6/D7/D8.
    $expected = array(
      
      // 'install_profile' => -1,
      // 'node_access' => -1,
      'php' => -1,
      
      // 'php_extensions' => -1,
      'php_memory_limit' => -1,
      'php_register_globals' => -1,
      'settings.php' => -1,
    );
    foreach ($expected as $key => $value) {
      $this->assertEquals($value, $loaded->$key->sid);
    }
  }
}