shellAliasTest.php

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

Classes

Namesort descending Description
shellAliasesCase

File

tests/shellAliasTest.php
View source
  1. <?php
  2. /*
  3. * @file
  4. * Tests for Shell aliases.
  5. *
  6. * @group base
  7. */
  8. class shellAliasesCase extends Drush_CommandTestCase {
  9. /**
  10. * Write a config file that contains the shell-aliases array.
  11. */
  12. static function setUpBeforeClass() {
  13. parent::setUpBeforeClass();
  14. $contents = "
  15. <?php
  16. \$options['shell-aliases'] = array(
  17. 'glopts' => 'topic core-global-options',
  18. 'pull' => '!git pull',
  19. 'echosimple' => '!echo {{@target}}',
  20. 'echotest' => '!echo {{@target}} {{%root}} {{%mypath}}',
  21. 'compound-command' => '!cd {{%sandbox}} && echo second',
  22. );
  23. ";
  24. file_put_contents(UNISH_SANDBOX . '/drushrc.php', trim($contents));
  25. mkdir(UNISH_SANDBOX . '/b');
  26. $contents = "
  27. <?php
  28. \$options['shell-aliases'] = array(
  29. 'also' => '!echo alternate config file included too',
  30. );
  31. ";
  32. file_put_contents(UNISH_SANDBOX . '/b/drushrc.php', trim($contents));
  33. $contents = "
  34. <?php
  35. \$aliases['myalias'] = array (
  36. 'root' => '/path/to/drupal',
  37. 'uri' => 'mysite.org',
  38. '#peer' => '@live',
  39. 'path-aliases' => array (
  40. '%mypath' => '/srv/data/mypath',
  41. '%sandbox' => '" . UNISH_SANDBOX . "'
  42. ),
  43. );
  44. ";
  45. file_put_contents(UNISH_SANDBOX . '/aliases.drushrc.php', trim($contents));
  46. }
  47. /*
  48. * Test shell aliases to Drush commands.
  49. */
  50. public function testShellAliasDrushLocal() {
  51. $options = array(
  52. 'config' => UNISH_SANDBOX,
  53. );
  54. $this->drush('glopts', array(), $options);
  55. $output = $this->getOutput();
  56. $this->assertContains('These options are applicable to most drush commands.', $output, 'Successfully executed local shell alias to drush command');
  57. }
  58. /*
  59. * Test shell aliases to Bash commands. Assure we pass along extra arguments
  60. * and options.
  61. */
  62. public function testShellAliasBashLocal() {
  63. $options = array(
  64. 'config' => UNISH_SANDBOX,
  65. 'simulate' => NULL,
  66. 'rebase' => NULL,
  67. );
  68. $this->drush('pull', array('origin'), $options, NULL, NULL, self::EXIT_SUCCESS, '2>&1');
  69. $output = $this->getOutput();
  70. $this->assertContains('Calling proc_open(git pull origin --rebase);', $output);
  71. }
  72. public function testShellAliasDrushRemote() {
  73. $options = array(
  74. 'config' => UNISH_SANDBOX,
  75. 'simulate' => NULL,
  76. 'ssh-options' => '',
  77. );
  78. $this->drush('glopts', array(), $options, 'user@server/path/to/drupal#sitename');
  79. // $expected might be different on non unix platforms. We shall see.
  80. // n.b. --config is not included in calls to remote systems.
  81. $bash = $this->escapeshellarg('drush --invoke --simulate --nocolor --uri=sitename --root=/path/to/drupal core-topic core-global-options 2>&1');
  82. $expected = "Simulating backend invoke: ssh user@server $bash 2>&1";
  83. $output = $this->getOutput();
  84. $this->assertEquals($expected, $output, 'Expected remote shell alias to a drush command was built');
  85. }
  86. public function testShellAliasBashRemote() {
  87. $options = array(
  88. 'config' => UNISH_SANDBOX,
  89. 'simulate' => NULL,
  90. 'ssh-options' => '',
  91. 'rebase' => NULL,
  92. );
  93. $this->drush('pull', array('origin'), $options, 'user@server/path/to/drupal#sitename', NULL, self::EXIT_SUCCESS, '2>&1');
  94. // $expected might be different on non unix platforms. We shall see.
  95. $expected = "Calling proc_open(ssh user@server 'cd /path/to/drupal && git pull origin --rebase');";
  96. $output = $this->getOutput();
  97. $this->assertEquals($expected, $output, 'Expected remote shell alias to a bash command was built');
  98. }
  99. /*
  100. * Test shell aliases with simple replacements -- no alias.
  101. */
  102. public function testShellAliasSimpleReplacement() {
  103. $options = array(
  104. 'config' => UNISH_SANDBOX,
  105. );
  106. $this->drush('echosimple', array(), $options);
  107. // Windows command shell actually prints quotes. See http://drupal.org/node/1452944.
  108. $expected = $this->is_windows() ? '"@none"' : '@none';
  109. $output = $this->getOutput();
  110. $this->assertEquals($expected, $output);
  111. }
  112. /*
  113. * Test shell aliases with complex replacements -- no alias.
  114. */
  115. public function testShellAliasReplacementNoAlias() {
  116. $options = array(
  117. 'config' => UNISH_SANDBOX,
  118. );
  119. // echo test has replacements that are not satisfied, so this is expected to return an error.
  120. $this->drush('echotest', array(), $options, NULL, NULL, self::EXIT_ERROR);
  121. }
  122. /*
  123. * Test shell aliases with replacements -- alias.
  124. */
  125. public function testShellAliasReplacementWithAlias() {
  126. $options = array(
  127. 'config' => UNISH_SANDBOX,
  128. 'alias-path' => UNISH_SANDBOX,
  129. );
  130. $this->drush('echotest', array(), $options, '@myalias');
  131. // Windows command shell actually prints quotes. See http://drupal.org/node/1452944.
  132. $expected = $this->is_windows() ? '"@myalias"' : '@myalias';
  133. $expected .= ' /path/to/drupal /srv/data/mypath';
  134. $output = $this->getOutput();
  135. $this->assertEquals($expected, $output);
  136. }
  137. /*
  138. * Test shell aliases with replacements and compound commands.
  139. */
  140. public function testShellAliasCompoundCommands() {
  141. $options = array(
  142. 'config' => UNISH_SANDBOX,
  143. 'alias-path' => UNISH_SANDBOX,
  144. );
  145. $this->drush('compound-command', array(), $options, '@myalias');
  146. $expected = 'second';
  147. $output = $this->getOutput();
  148. $this->assertEquals($expected, $output);
  149. }
  150. /*
  151. * Test shell aliases with multiple config files.
  152. */
  153. public function testShellAliasMultipleConfigFiles() {
  154. $options = array(
  155. 'config' => UNISH_SANDBOX . "/b" . PATH_SEPARATOR . UNISH_SANDBOX,
  156. 'alias-path' => UNISH_SANDBOX,
  157. );
  158. $this->drush('also', array(), $options);
  159. $expected = "alternate config file included too";
  160. $output = $this->getOutput();
  161. $this->assertEquals($expected, $output);
  162. }
  163. }