siteAliasTest.php

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

Tests for sitealias.inc

@group base

Classes

Namesort descending Description
saCase @file Tests for sitealias.inc

File

tests/siteAliasTest.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Tests for sitealias.inc
  5. *
  6. * @group base
  7. */
  8. class saCase extends Drush_CommandTestCase {
  9. /**
  10. * Covers the following responsibilities.
  11. * - Dispatching a Drush command that uses strict option handling
  12. * using a global option (e.g. --alias-path) places said global
  13. * option BEFORE the command name.
  14. * - Dispatching a Drush command that uses strict option handling
  15. * using a site alias that contains a command-specific option
  16. * places said option AFTER the command name.
  17. */
  18. function testDispatchStrictOptions() {
  19. $aliasPath = UNISH_SANDBOX . '/aliases';
  20. mkdir($aliasPath);
  21. $aliasFile = $aliasPath . '/bar.aliases.drushrc.php';
  22. $aliasContents = <<<EOD
  23. <?php
  24. // Writtne by Unish. This file is safe to delete.
  25. \$aliases['test'] = array(
  26. 'remote-host' => 'fake.remote-host.com',
  27. 'remote-user' => 'www-admin',
  28. 'root' => '/fake/path/to/root',
  29. 'uri' => 'default',
  30. 'command-specific' => array(
  31. 'rsync' => array(
  32. 'delete' => TRUE,
  33. ),
  34. ),
  35. );
  36. EOD;
  37. file_put_contents($aliasFile, $aliasContents);
  38. $options = array(
  39. 'alias-path' => $aliasPath,
  40. 'include' => dirname(__FILE__), // Find unit.drush.inc commandfile.
  41. 'simulate' => TRUE,
  42. );
  43. $this->drush('core-rsync', array('/a', '/b'), $options, '@test');
  44. $output = $this->getOutput();
  45. $command_position = strpos($output, 'core-rsync');
  46. $global_option_position = strpos($output, '--alias-path=');
  47. $command_specific_position = strpos($output, '--delete');
  48. $this->assertTrue($command_position !== FALSE);
  49. $this->assertTrue($global_option_position !== FALSE);
  50. $this->assertTrue($command_specific_position !== FALSE);
  51. $this->assertTrue($command_position > $global_option_position);
  52. $this->assertTrue($command_position < $command_specific_position);
  53. }
  54. /**
  55. * Assure that site lists work as expected.
  56. * @todo Use --backend for structured return data. Depends on http://drupal.org/node/1043922
  57. */
  58. public function testSAList() {
  59. $sites = $this->setUpDrupal(2);
  60. $subdirs = array_keys($sites);
  61. $eval = 'print "bon";';
  62. $options = array(
  63. 'yes' => NULL,
  64. 'verbose' => NULL,
  65. 'root' => $this->webroot(),
  66. );
  67. foreach ($subdirs as $dir) {
  68. $dirs[] = "#$dir";
  69. }
  70. $this->drush('php-eval', array($eval), $options, implode(',', $dirs));
  71. $output = $this->getOutputAsList();
  72. $expected = "You are about to execute 'php-eval print \"bon\";' non-interactively (--yes forced) on all of the following targets:
  73. #dev
  74. #stage
  75. Continue? (y/n): y
  76. #stage >> bon
  77. #dev >> bon";
  78. $actual = implode("\n", $output);
  79. $actual = trim(preg_replace('/^#[a-z]* *>> *$/m', '', $actual)); // ignore blank lines
  80. $this->assertEquals($expected, $actual);
  81. }
  82. /**
  83. * Ensure that requesting a non-existent alias throws an error.
  84. */
  85. public function testBadAlias() {
  86. $this->drush('sa', array('@badalias'), array(), NULL, NULL, self::EXIT_ERROR);
  87. }
  88. }