class shellAliasesCase

  1. 8.0.x tests/shellAliasTest.php shellAliasesCase
  2. 6.x tests/shellAliasTest.php shellAliasesCase
  3. 7.x tests/shellAliasTest.php shellAliasesCase
  4. 5.x tests/shellAliasTest.php shellAliasesCase
  5. master tests/shellAliasTest.php shellAliasesCase

Tests for Shell aliases.

@group base

Namespace

Unish

Hierarchy

Expanded class hierarchy of shellAliasesCase

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::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
shellAliasesCase::setUp function Write a config file that contains the shell-aliases array.
shellAliasesCase::testShellAliasBashLocal public function Test shell aliases to Bash commands. Assure we pass along extra arguments and options.
shellAliasesCase::testShellAliasBashRemote public function
shellAliasesCase::testShellAliasCompoundCommands public function Test shell aliases with replacements and compound commands.
shellAliasesCase::testShellAliasDrushLocal public function Test shell aliases to Drush commands.
shellAliasesCase::testShellAliasDrushRemote public function
shellAliasesCase::testShellAliasMultipleConfigFiles public function Test shell aliases with multiple config files.
shellAliasesCase::testShellAliasReplacementNoAlias public function Test shell aliases with complex replacements -- no alias.
shellAliasesCase::testShellAliasReplacementWithAlias public function Test shell aliases with replacements -- alias.
shellAliasesCase::testShellAliasSimpleReplacement public function Test shell aliases with simple replacements -- no alias.
UnishTestCase::$sites private static property A list of Drupal sites that have been recently installed.
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::randomString public function Helper function to generate a random string of arbitrary length.
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/shellAliasTest.php, line 10

View source
class shellAliasesCase extends CommandUnishTestCase {

  /**
   * Write a config file that contains the shell-aliases array.
   */
  function setUp() {
    parent::setUp();
    $contents = "
      <?php

      \$options['shell-aliases'] = array(
        'glopts' => 'topic core-global-options',
        'pull' => '!git pull',
        'echosimple' => '!echo {{@target}}',
        'echotest' => '!echo {{@target}} {{%root}} {{%mypath}}',
        'compound-command' => '!cd {{%sandbox}} && echo second',
      );
    ";
    file_put_contents(UNISH_SANDBOX . '/drushrc.php', trim($contents));
    if (!file_exists(UNISH_SANDBOX . '/b')) {
      mkdir(UNISH_SANDBOX . '/b');
    }
    $contents = "
      <?php

      \$options['shell-aliases'] = array(
        'also' => '!echo alternate config file included too',
      );
    ";
    file_put_contents(UNISH_SANDBOX . '/b/drushrc.php', trim($contents));
    $aliases['myalias'] = array(
      'root' => '/path/to/drupal',
      'uri' => 'mysite.org',
      '#peer' => '@live',
      'path-aliases' => array(
        '%mypath' => '/srv/data/mypath',
        '%sandbox' => UNISH_SANDBOX,
      ),
    );
    $contents = $this->unish_file_aliases($aliases);
    file_put_contents(UNISH_SANDBOX . '/aliases.drushrc.php', $contents);
  }

  /**
   * Test shell aliases to Drush commands.
   */
  public function testShellAliasDrushLocal() {
    $options = array(
      'config' => UNISH_SANDBOX,
    );
    $this->drush('glopts', array(), $options);
    $output = $this->getOutput();
    $this->assertContains('These options are applicable to most drush commands.', $output, 'Successfully executed local shell alias to drush command');
  }

  /**
   * Test shell aliases to Bash commands. Assure we pass along extra arguments
   * and options.
   */
  public function testShellAliasBashLocal() {
    $options = array(
      'config' => UNISH_SANDBOX,
      'simulate' => NULL,
      'rebase' => NULL,
    );
    $this->drush('pull', array('origin'), $options, NULL, NULL, self::EXIT_SUCCESS, '2>&1');
    $output = $this->getOutput();
    $this->assertContains('Calling proc_open(git pull origin --rebase);', $output);
  }

  public function testShellAliasDrushRemote() {
    $options = array(
      'config' => UNISH_SANDBOX,
      'simulate' => NULL,
      'ssh-options' => '',
    );
    $this->drush('glopts', array(), $options, 'user@server/path/to/drupal#sitename');
    // $expected might be different on non unix platforms. We shall see.
    // n.b. --config is not included in calls to remote systems.
    $bash = $this->escapeshellarg('drush  --config=drush-sandbox --nocolor --uri=sitename --root=/path/to/drupal  core-topic core-global-options 2>&1');
    $expected = "Simulating backend invoke: ssh -t user@server $bash 2>&1";
    $output = $this->getOutput();
    // Remove any coverage arguments. The filename changes, so it's not possible
    // to create a string for assertEquals, and the need for both shell escaping
    // and regexp escaping different parts of the expected output for
    // assertRegexp makes it easier just to remove the argument before checking
    // the output.
    $output = preg_replace('{--drush-coverage=[^ ]+ }', '', $output);
    $output = preg_replace('{--config=[^ ]+ +}', '--config=drush-sandbox ', $output);
    $this->assertEquals($expected, $output, 'Expected remote shell alias to a drush command was built');
  }

  public function testShellAliasBashRemote() {
    $options = array(
      'config' => UNISH_SANDBOX,
      'simulate' => NULL,
      'ssh-options' => '',
      'rebase' => NULL,
    );
    $this->drush('pull', array('origin'), $options, 'user@server/path/to/drupal#sitename', NULL, self::EXIT_SUCCESS, '2>&1');
    // $expected might be different on non unix platforms. We shall see.
    $expected = "Calling proc_open(ssh  user@server 'cd /path/to/drupal && git pull origin --rebase');";
    $output = $this->getOutput();
    $this->assertEquals($expected, $output, 'Expected remote shell alias to a bash command was built');
  }

  /**
   * Test shell aliases with simple replacements -- no alias.
   */
  public function testShellAliasSimpleReplacement() {
    $options = array(
      'config' => UNISH_SANDBOX,
    );
    $this->drush('echosimple', array(), $options);
    // Windows command shell actually prints quotes. See http://drupal.org/node/1452944.
    $expected = $this->is_windows() ? '"@none"' : '@none';
    $output = $this->getOutput();
    $this->assertEquals($expected, $output);
  }

  /**
   * Test shell aliases with complex replacements -- no alias.
   */
  public function testShellAliasReplacementNoAlias() {
    $options = array(
      'config' => UNISH_SANDBOX,
    );
    // echo test has replacements that are not satisfied, so this is expected to return an error.
    $this->drush('echotest', array(), $options, NULL, NULL, self::EXIT_ERROR);
  }

  /**
   * Test shell aliases with replacements -- alias.
   */
  public function testShellAliasReplacementWithAlias() {
    $options = array(
      'config' => UNISH_SANDBOX,
      'alias-path' => UNISH_SANDBOX,
    );
    $this->drush('echotest', array(), $options, '@myalias');
    // Windows command shell actually prints quotes. See http://drupal.org/node/1452944.
    $expected = $this->is_windows() ? '"@myalias"' : '@myalias';
    $expected .= ' /path/to/drupal /srv/data/mypath';
    $output = $this->getOutput();
    $this->assertEquals($expected, $output);
  }

  /**
   * Test shell aliases with replacements and compound commands.
   */
  public function testShellAliasCompoundCommands() {
    $options = array(
      'config' => UNISH_SANDBOX,
      'alias-path' => UNISH_SANDBOX,
    );
    $this->drush('compound-command', array(), $options, '@myalias');
    $expected = 'second';
    $output = $this->getOutput();
    $this->assertEquals($expected, $output);
  }


  /**
   * Test shell aliases with multiple config files.
   */
  public function testShellAliasMultipleConfigFiles() {
    $options = array(
      'config' => UNISH_SANDBOX . "/b" . PATH_SEPARATOR . UNISH_SANDBOX,
      'alias-path' => UNISH_SANDBOX,
    );
    $this->drush('also', array(), $options);
    $expected = "alternate config file included too";
    $output = $this->getOutput();
    $this->assertEquals($expected, $output);
  }

}