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