function contextCase::testContextHierarchy

8.0.x contextTest.php contextCase::testContextHierarchy()
7.x contextTest.php contextCase::testContextHierarchy()
master contextTest.php contextCase::testContextHierarchy()

Assure that options are loaded into right context and hierarchy is respected by drush_get_option().

Stdin context not exercised here. See backendCase::testTarget().

File

tests/contextTest.php, line 132
Assure that context API behaves as designed. Mostly implicitly tested, but we do have some edges that need explicit testing. *

Namespace

Unish

Class

contextCase

Code

function testContextHierarchy() {
  // The 'custom' config file has higher priority than cli and regular config files.
  $eval = '$contextConfig = drush_get_option("contextConfig", "n/a");';
  $eval .= '$cli1 = drush_get_option("cli1");';
  $eval .= 'print json_encode(get_defined_vars());';
  $config = UNISH_SANDBOX . '/drushrc.php';
  $options = array(
    'cli1' => NULL,
    'config' => $config,
    'root' => $this->webroot(),
    'uri' => key($this->getSites()),
  );
  $this->drush('php-eval', array($eval), $options);
  $output = $this->getOutput();
  $actuals = json_decode(trim($output));
  $this->assertEquals('custom', $actuals->contextConfig);
  $this->assertTrue($actuals->cli1);

  // Site alias trumps 'custom'.
  $eval = '$contextConfig = drush_get_option("contextConfig", "n/a");';
  $eval .= 'print json_encode(get_defined_vars());';
  $options = array(
    'config' => $config,
    'root' => $this->webroot(),
    'uri' => key($this->getSites()),
  );
  $this->drush('php-eval', array($eval), $options, '@contextAlias');
  $output = $this->getOutput();
  $actuals = json_decode(trim($output));
  $this->assertEquals('alias1', $actuals->contextConfig);

  // Command specific wins over non-specific. If it did not, $expected would
  // be 'site'. Note we call unit-eval command in order not to purturb
  // php-eval with options in config file.
  $eval = '$contextConfig = drush_get_option("contextConfig", "n/a");';
  $eval .= 'print json_encode(get_defined_vars());';
  $options = array(
    'root' => $this->webroot(),
    'uri' => key($this->getSites()),
    'include' => dirname(__FILE__), // Find unit.drush.inc commandfile.
  );
  $this->drush('unit-eval', array($eval), $options);
  $output = $this->getOutput();
  $actuals = json_decode(trim($output));
  $this->assertEquals('site-specific', $actuals->contextConfig);
}