class drushScriptCase

  1. 8.0.x tests/drushScriptTest.php drushScriptCase
  2. 6.x tests/drushScriptTest.php drushScriptCase
  3. 7.x tests/drushScriptTest.php drushScriptCase
  4. 5.x tests/drushScriptTest.php drushScriptCase
  5. master tests/drushScriptTest.php drushScriptCase

Tests for the 'drush' script itself

Namespace

Unish

Hierarchy

Expanded class hierarchy of drushScriptCase

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description
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
drushScriptCase::createDrushWrapper function TODO: Create a Drush wrapper script, and copy it to to the root of the fake Drupal site, and point it at the specified site-local Drush script.
drushScriptCase::create_site_local_drush function Copy UNISH_DRUSH into the specified site-local location.
drushScriptCase::getDrushLocation function Get the current location of the Drush script via `drush status 'Drush script' --format=yaml`. This will return results other than UNISH_DRUSH in the presence of a site-local Drush.
drushScriptCase::remove_site_local_drush function
drushScriptCase::testDrushFinder public function
drushScriptCase::testPhpOptionsTest public function Test `PHP_OPTIONS=... drush`
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/drushScriptTest.php, line 8

View source
class drushScriptCase extends CommandUnishTestCase {

  /**
   * Test `PHP_OPTIONS=... drush`
   */
  public function testPhpOptionsTest() {
    // @todo: could probably run this test on mingw
    if ($this->is_windows()) {
      $this->markTestSkipped('Environment variable tests not currently functional on Windows.');
    }

    $options = array();
    $env = array('PHP_OPTIONS' => '-d default_mimetype="text/drush"');
    $this->drush('ev', array('print ini_get("default_mimetype");'), $options, NULL, NULL, self::EXIT_SUCCESS, NULL, $env);
    $output = $this->getOutput();
    $this->assertEquals('text/drush', $output);
  }

  public function testDrushFinder() {
    // We don't really need a real Drupal site; we could
    // create a fake site, as long as we had the right signature
    // files to allow us to bootstrap to the DRUPAL_ROOT phase.
    $this->setUpDrupal(1, TRUE);

    // Control: test `drush --root ` ... with no site-local Drush
    $drush_location = $this->getDrushLocation();
    $this->assertEquals(UNISH_DRUSH . '.php', $drush_location);

    // We will try copying a site-local Drush to
    // all of the various locations the 'drush finder'
    // might expect to find it.
    $drush_locations = array(
      "vendor",
      "../vendor",
      "sites/all/vendor",
      "sites/all",
    );

    foreach ($drush_locations as $drush_base) {
      $drush_root = $this->create_site_local_drush($drush_base);

      // Test `drush --root ` ... with a site-local Drush
      $drush_location = $this->getDrushLocation(array('root' => $this->webroot()));
      $this->assertEquals(realpath($drush_root . '/drush.php'), realpath($drush_location));
      // Ensure that --local was NOT added
      $result = $this->drush('ev', array('return drush_get_option("local");'), array('root' => $this->webroot()));
      $output = $this->getOutput();
      $this->assertEquals("", $output);

      // Run the `drush --root` test again, this time with
      // a drush.wrapper script in place.
      $this->createDrushWrapper($drush_base);
      $drush_location = $this->getDrushLocation(array('root' => $this->webroot()));
      $this->assertEquals(realpath($drush_root . '/drush.php'), realpath($drush_location));
      // Test to see if --local was added
      $result = $this->drush('ev', array('return drush_get_option("local");'), array('root' => $this->webroot()));
      $output = $this->getOutput();
      $this->assertEquals("TRUE", $output);

      // Get rid of the symlink and site-local Drush we created
      $this->remove_site_local_drush($drush_base);
    }

    // Next, try again with a site-local Drush in a location
    // that Drush does not search.
    $mysterious_location = "path/drush/does/not/search";
    $drush_root = $this->create_site_local_drush($mysterious_location);
    // We should not find the site-local Drush without a Drush wrapper.
    $drush_location = $this->getDrushLocation(array('root' => $this->webroot()));
    $this->assertEquals(UNISH_DRUSH . '.php', $drush_location);
    $this->createDrushWrapper($mysterious_location);
    // Now that there is a Drush wrapper, we should be able to find the site-local Drush.
    $drush_location = $this->getDrushLocation(array('root' => $this->webroot()));
    $this->assertEquals(realpath($drush_root . '/drush.php'), $drush_location);
  }

  /**
   * Copy UNISH_DRUSH into the specified site-local location.
   */
  function create_site_local_drush($drush_base) {
    $drush_root = $this->webroot() . '/' . $drush_base . '/drush/drush';
    $bin_dir = $this->webroot() . '/' . $drush_base . '/bin';

    $this->mkdir(dirname($drush_root));
    $this->recursive_copy(dirname(UNISH_DRUSH), $drush_root);
    @chmod($drush_root . '/drush', 0777);
    @chmod($drush_root . '/drush.launcher', 0777);
    $this->mkdir($bin_dir);
    symlink($drush_root . '/drush', $bin_dir . '/drush');

    return $drush_root;
  }

  function remove_site_local_drush($drush_base) {
    // Get rid of the symlink and site-local Drush we created
    unish_file_delete_recursive($this->webroot() . '/' . $drush_base . '/drush/drush');
    unlink($this->webroot() . '/' . $drush_base . '/bin/drush');
    if (file_exists($this->webroot() . '/drush.wrapper')) {
      unlink($this->webroot() . '/drush.wrapper');
    }
  }

  /**
   * TODO: Create a Drush wrapper script, and copy it to
   * to the root of the fake Drupal site, and point it
   * at the specified site-local Drush script.
   */
  function createDrushWrapper($drush_base) {
    $drush_launcher = $drush_base . '/drush/drush/drush.launcher';

    $drush_wrapper_src = dirname(UNISH_DRUSH) . '/examples/drush.wrapper';
    $drush_wrapper_contents = file_get_contents($drush_wrapper_src);
    $drush_wrapper_contents = preg_replace('#\.\./vendor/bin/drush.launcher#', $drush_launcher, $drush_wrapper_contents);
    $drush_wrapper_target = $this->webroot() . '/drush.wrapper';

    file_put_contents($drush_wrapper_target, $drush_wrapper_contents);
    @chmod($drush_wrapper_target, 0777);
  }

  /**
   * Get the current location of the Drush script via
   * `drush status 'Drush script' --format=yaml`.  This
   * will return results other than UNISH_DRUSH in the
   * presence of a site-local Drush.
   */
  function getDrushLocation($options = array(), $site_specification = NULL, $env = array()) {
    $options += array(
      'format' => 'yaml',
      'verbose' => NULL,
    );
    $cd = NULL;
    $expected_return = self::EXIT_SUCCESS;
    $suffix = NULL;
    $result = $this->drush('status', array('Drush script'), $options, $site_specification, $cd, $expected_return, $suffix, $env);

    $output = $this->getOutput();
    list($key, $value) = explode(": ", $output);
    return trim($value);
  }
}