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