8 class annotatedCommandCase extends CommandUnishTestCase {
10 public function testGlobal() {
11 $globalExtensions = $this->setupGlobalExtensionsForTests();
15 // We modified the set of available Drush commands; we need to clear the Drush command cache
16 $this->drush('cc', array('drush'), $options);
19 $options['include'] = "$globalExtensions";
20 $this->drush('foobar', array(), $options);
21 $output = $this->getOutput();
22 $this->assertEquals('baz', $output);
24 // Clear the Drush command cache again and test again with new includes
25 $this->drush('cc', array('drush'), $options);
27 // drush foobar again, except include the 'Commands' folder when passing --include
28 $options['include'] = "$globalExtensions/Commands";
29 $this->drush('foobar', array(), $options);
30 $output = $this->getOutput();
31 $this->assertEquals('baz', $output);
34 public function testExecute() {
35 $sites = $this->setUpDrupal(1, TRUE);
37 $root = $this->webroot();
44 // Copy the 'woot' module over to the Drupal site we just set up.
45 $this->setupModulesForTests($root);
47 // These are not good asserts, but for the purposes of isolation....
48 $targetDir = $root . DIRECTORY_SEPARATOR . $this->drupalSitewideDirectory() . '/modules/woot';
49 if (UNISH_DRUPAL_MAJOR_VERSION == 8) {
50 $commandFile = $targetDir . "/src/Commands/WootCommands.php";
52 $commandFile = $targetDir . "/Commands/WootCommands.php";
54 $this->assertFileExists(dirname(dirname(dirname($commandFile))));
55 $this->assertFileExists(dirname(dirname($commandFile)));
56 $this->assertFileExists(dirname($commandFile));
57 $this->assertFileExists($commandFile);
59 // Enable out module. This will also clear the commandfile cache.
60 $this->drush('pm-enable', array('woot'), $options);
62 // In theory this is not necessary, but this test keeps failing.
63 $this->drush('cc', array('drush'), $options);
66 $this->drush('woot', array(), $options + ['help' => NULL]);
67 $output = $this->getOutput();
68 $this->assertContains('Woot mightily.', $output);
69 $this->assertContains('Aliases: wt', $output);
72 $this->drush('help', array('woot'), $options);
73 $output = $this->getOutput();
74 $this->assertContains('Woot mightily.', $output);
77 $this->drush('woot', array(), $options);
78 $output = $this->getOutput();
79 $this->assertEquals('Woot!', $output);
81 // drush my-cat --help
82 $this->drush('my-cat', array(), $options + ['help' => NULL]);
83 $output = $this->getOutput();
84 $this->assertContains('This is the my-cat command', $output);
85 $this->assertContains('bet alpha --flip', $output);
86 $this->assertContains('The first parameter', $output);
87 $this->assertContains('The other parameter', $output);
88 $this->assertContains('Whether or not the second parameter', $output);
89 $this->assertContains('Aliases: c', $output);
92 $this->drush('help', array('my-cat'), $options);
93 $output = $this->getOutput();
94 $this->assertContains('This is the my-cat command', $output);
96 // drush my-cat bet alpha --flip
97 $this->drush('my-cat', array('bet', 'alpha'), $options + ['flip' => NULL]);
98 $output = $this->getOutput();
99 $this->assertEquals('alphabet', $output);
101 // drush woot --help with the 'woot' module ignored
102 $this->drush('woot', array(), $options + ['help' => NULL, 'ignored-modules' => 'woot'], NULL, NULL, self::EXIT_ERROR);
104 // drush my-cat bet alpha --flip
105 $this->drush('my-cat', array('bet', 'alpha'), $options + ['flip' => NULL, 'ignored-modules' => 'woot'], NULL, NULL, self::EXIT_ERROR);
107 $this->drush('try-formatters', array(), $options);
108 $output = $this->getOutput();
110 ------ ------ -------
112 ------ ------ -------
117 ------ ------ -------
119 $this->assertEquals(trim(preg_replace('#[ \n]+#', ' ', $expected)), trim(preg_replace('#[ \n]+#', ' ', $output)));
121 $this->drush('try-formatters --format=yaml --fields=III,II', array(), $options, NULL, NULL, self::EXIT_SUCCESS);
122 $output = $this->getOutput();
137 $this->assertEquals($expected, $output);
139 $this->drush('try-formatters', array(), $options + ['backend' => NULL]);
140 $parsed = $this->parse_backend_output($this->getOutput());
141 $data = $parsed['object'];
143 {"en":{"first":"One","second":"Two","third":"Three"},"de":{"first":"Eins","second":"Zwei","third":"Drei"},"jp":{"first":"Ichi","second":"Ni","third":"San"},"es":{"first":"Uno","second":"Dos","third":"Tres"}}
145 $this->assertEquals($expected, json_encode($data));
147 // drush try-formatters --help
148 $this->drush('try-formatters', array(), $options + ['help' => NULL], NULL, NULL, self::EXIT_SUCCESS);
149 $output = $this->getOutput();
150 $this->assertContains('Demonstrate formatters', $output);
151 $this->assertContains('try:formatters --fields=first,third', $output);
152 $this->assertContains('try:formatters --fields=III,II', $output);
153 $this->assertContains('--fields=<first, second, third>', $output);
154 $this->assertContains('Fields to output. All available', $output);
155 $this->assertContains('--format=<table>', $output);
156 $this->assertContains('Select output format. Available:', $output);
157 $this->assertContains('Aliases: try-formatters', $output);
159 // If we are running Drupal version 8 or later, then also check to
160 // see if the demo:greet and annotated:greet commands are available.
161 if (UNISH_DRUPAL_MAJOR_VERSION >= 8) {
162 $this->drush('demo:greet symfony', array(), $options, NULL, NULL, self::EXIT_SUCCESS);
163 $output = $this->getOutput();
164 $this->assertEquals('Hello symfony', $output);
166 $this->drush('annotated:greet symfony', array(), $options, NULL, NULL, self::EXIT_SUCCESS);
167 $output = $this->getOutput();
168 $this->assertEquals('Hello symfony', $output);
171 // Flush the Drush cache so that our 'woot' command is not cached.
172 $this->drush('cache-clear', array('drush'), $options, NULL, NULL, self::EXIT_SUCCESS);
175 public function setupGlobalExtensionsForTests() {
176 $globalExtension = __DIR__ . '/resources/global-includes';
177 $targetDir = UNISH_SANDBOX . DIRECTORY_SEPARATOR . 'global-includes';
178 $this->mkdir($targetDir);
179 $this->recursive_copy($globalExtension, $targetDir);
183 public function setupModulesForTests($root) {
184 $wootModule = __DIR__ . '/resources/modules/d' . UNISH_DRUPAL_MAJOR_VERSION . '/woot';
185 $targetDir = $root . DIRECTORY_SEPARATOR . $this->drupalSitewideDirectory() . '/modules/woot';
186 $this->mkdir($targetDir);
187 $this->recursive_copy($wootModule, $targetDir);