commandTest.php

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

Classes

Namesort descending Description
commandCase @group base

File

tests/commandTest.php
View source
  1. <?php
  2. /**
  3. * @group base
  4. */
  5. class commandCase extends Drush_CommandTestCase {
  6. public function testInvoke() {
  7. $expected = array(
  8. 'unit_drush_init',
  9. 'drush_unit_invoke_init',
  10. 'drush_unit_invoke_validate',
  11. 'drush_unit_pre_unit_invoke',
  12. 'drush_unit_invoke_primary',
  13. // Primary callback is not invoked when command specifies a 'callback'.
  14. // 'drush_unit_invoke',
  15. 'drush_unit_post_unit_invoke',
  16. 'drush_unit_post_unit_invoke_rollback',
  17. 'drush_unit_pre_unit_invoke_rollback',
  18. 'drush_unit_invoke_validate_rollback',
  19. );
  20. $options = array(
  21. 'include' => dirname(__FILE__),
  22. );
  23. $this->drush('unit-invoke', array(), $options, NULL, NULL, self::EXIT_ERROR);
  24. $called = $this->getOutputFromJSON();
  25. $this->assertSame($expected, $called);
  26. }
  27. /**
  28. * Assert that minimum bootstrap phase is honored.
  29. *
  30. * Not testing dependency on a module since that requires an installed Drupal.
  31. * Too slow for little benefit.
  32. */
  33. public function testRequirementBootstrapPhase() {
  34. // Assure that core-cron fails when run outside of a Drupal site.
  35. $return = $this->drush('core-cron', array(), array('quiet' => NULL), NULL, NULL, self::EXIT_ERROR);
  36. }
  37. /**
  38. * Assert that unknown options are caught and flagged as errors
  39. */
  40. public function testUnknownOptions() {
  41. // Make sure an ordinary 'version' command works
  42. $return = $this->drush('version', array(), array('pipe' => NULL));
  43. // Add an unknown option --magic=1234 and insure it fails
  44. $return = $this->drush('version', array(), array('pipe' => NULL, 'magic' => 1234), NULL, NULL, self::EXIT_ERROR);
  45. // Finally, add in a hook that uses drush_hook_help_alter to allow the 'magic' option.
  46. // We need to run 'drush cc drush' to clear the commandfile cache; otherwise, our include will not be found.
  47. $include_path = dirname(__FILE__) . '/hooks/magic_help_alter';
  48. $this->drush('version', array(), array('include' => $include_path, 'pipe' => NULL, 'magic' => '1234', 'strict' => NULL));
  49. }
  50. /**
  51. * Assert that errors are thrown for commands with missing callbacks.
  52. */
  53. public function testMissingCommandCallback() {
  54. $options = array(
  55. 'include' => dirname(__FILE__), // Find unit.drush.inc commandfile.
  56. //'show-invoke' => TRUE,
  57. );
  58. $this->drush('missing-callback', array(), $options, NULL, NULL, self::EXIT_ERROR);
  59. }
  60. /**
  61. * Assert that commands depending on unknown commandfiles are detected.
  62. */
  63. public function testMissingDrushDependency() {
  64. $options = array(
  65. 'include' => dirname(__FILE__), // Find unit.drush.inc commandfile.
  66. 'backend' => NULL, // To obtain and parse the error log.
  67. );
  68. $this->drush('unit-drush-dependency', array(), $options, NULL, NULL, self::EXIT_ERROR);
  69. $parsed = parse_backend_output($this->getOutput());
  70. $this->assertArrayHasKey("DRUSH_COMMANDFILE_DEPENDENCY_ERROR", $parsed['error_log']);
  71. }
  72. /**
  73. * Assert that commands in disabled modules are detected.
  74. */
  75. public function testDisabledModule() {
  76. $sites = $this->setUpDrupal(1, TRUE);
  77. $uri = key($sites);
  78. $root = $this->webroot();
  79. $options = array(
  80. 'root' => $root,
  81. 'uri' => $uri,
  82. 'cache' => NULL,
  83. );
  84. $this->drush('pm-download', array('devel'), $options);
  85. $options += array(
  86. 'backend' => NULL, // To obtain and parse the error log.
  87. );
  88. $this->drush('devel-download', array(), $options, NULL, NULL, self::EXIT_ERROR);
  89. $parsed = parse_backend_output($this->getOutput());
  90. $this->assertArrayHasKey("DRUSH_COMMAND_DEPENDENCY_ERROR", $parsed['error_log']);
  91. }
  92. }