public function drushScriptCase::testDrushFinder

8.0.x drushScriptTest.php public drushScriptCase::testDrushFinder()
master drushScriptTest.php public drushScriptCase::testDrushFinder()

File

tests/drushScriptTest.php, line 30

Namespace

Unish

Class

drushScriptCase
Tests for the 'drush' script itself

Code

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);

  $globalDrushDotPhp = Path::join(UNISH_DRUSH, '../drush.php');

  // Control: test `drush --root ` ... with no site-local Drush
  $drush_location = $this->getDrushLocation();
  $this->assertEquals($globalDrushDotPhp, $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('var_export(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($globalDrushDotPhp, $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);
}