public function saCase::testBackendHonorsAliasOverride

master siteAliasTest.php public saCase::testBackendHonorsAliasOverride()

Ensure that a --uri on CLI overrides on provided by site alias during a backend invoke.

File

tests/siteAliasTest.php, line 177

Namespace

Unish

Class

saCase
Tests for sitealias.inc

Code

public function testBackendHonorsAliasOverride() {
  // Test a standard remote dispatch.
  $this->drush('core-status', array(), array('uri' => 'http://example.com', 'simulate' => NULL), 'user@server/path/to/drupal#sitename');
  $this->assertContains('--uri=http://example.com', $this->getOutput());

  // Test a local-handling command which uses drush_redispatch_get_options().
  $this->drush('browse', array(), array('uri' => 'http://example.com', 'simulate' => NULL), 'user@server/path/to/drupal#sitename');
  $this->assertContains('--uri=http://example.com', $this->getOutput());

  // Test a command which uses drush_invoke_process('@self') internally.
  $sites = $this->setUpDrupal(1, TRUE);
  $name = key($sites);
  $sites_php = "\n\$sites['example.com'] = '$name';";
  file_put_contents($sites[$name]['root'] . '/sites/sites.php', $sites_php, FILE_APPEND);
  $this->drush('pm-updatecode', array(), array('uri' => 'http://example.com', 'no' => NULL, 'no-core' => NULL, 'verbose' => NULL), '@' . $name);
  $this->assertContains('--uri=http://example.com', $this->getErrorOutput());

  // Test a remote alias that does not have a 'root' element
  $aliasPath = UNISH_SANDBOX . '/site-alias-directory';
  @mkdir($aliasPath);
  $aliasContents = <<<EOD
  <?php
  // Written by Unish. This file is safe to delete.
  \$aliases['rootlessremote'] = array(
    'uri' => 'remoteuri',
    'remote-host' => 'exampleisp.com',
    'remote-user' => 'www-admin',
  );
EOD;
  file_put_contents("$aliasPath/rootlessremote.aliases.drushrc.php", $aliasContents);
  $this->drush('core-status', array(), array('uri' => 'http://example.com', 'simulate' => NULL, 'alias-path' => $aliasPath), '@rootlessremote');
  $output = $this->getOutput();
  $this->assertContains(' ssh ', $output);
  $this->assertContains('--uri=http://example.com', $output);

  // Test a remote alias that does not have a 'root' element with cwd inside a Drupal root directory
  $root = $this->webroot();
  $this->drush('core-status', array(), array('uri' => 'http://example.com', 'simulate' => NULL, 'alias-path' => $aliasPath), '@rootlessremote', $root);
  $output = $this->getOutput();
  $this->assertContains(' ssh ', $output);
  $this->assertContains('--uri=http://example.com', $output);
}