Version 1
[yaffs-website] / vendor / drush / drush / tests / commandUnitTest.php
1 <?php
2
3 namespace Unish;
4
5 use Webmozart\PathUtil\Path;
6
7 class commandUnitCase extends UnitUnishTestCase {
8   /**
9    * Assure that matching version-specific command files are loaded and others are ignored.
10    */
11   function testCommandVersionSpecific() {
12     $path = Path::join(UNISH_SANDBOX, 'commandUnitCase');
13     $major = $this->drush_major_version();
14     $major_plus1 = $major + 1;
15
16     // Write matched and unmatched files to the system search path.
17     $files = array(
18       Path::join($path, "$major.drush$major.inc"),
19       Path::join($path, "drush$major/drush$major.drush.inc"),
20       Path::join($path, "$major_plus1.drush$major_plus1.inc"),
21       Path::join($path, "drush$major_plus1/drush$major_plus1.drush.inc"),
22     );
23     $this->mkdir(Path::join($path, 'drush'. $major));
24     $this->mkdir(Path::join($path, 'drush'. $major_plus1));
25     foreach ($files as $file) {
26       $contents = <<<EOD
27 <?php
28 // Written by Unish. This file is safe to delete.
29 \$GLOBALS['unish_foo'][] = '$file';
30 EOD;
31       $return = file_put_contents($file, $contents);
32     }
33     drush_set_context('DRUSH_INCLUDE', array($path));
34     drush_preflight();
35     $loaded = drush_commandfile_list();
36     $this->assertContains($files[0], $loaded); //Loaded a version-specific command file.
37     $this->assertContains($files[1], $loaded); //Loaded a version-specific command directory.
38     $this->assertNotContains($files[2], $loaded); //Did not load a mismatched version-specific command file.
39     $this->assertNotContains($files[3], $loaded); //Did not load a a mismatched version-specific command directory.
40   }
41
42   /**
43    * Assert that $command has interesting properties. Reference command by
44    * it's alias (dl) to assure that those aliases are built as expected.
45    */
46   public function testGetCommands() {
47     drush_preflight();
48     $commands = drush_get_commands();
49     $command = $commands['dl'];
50
51     $this->assertEquals('dl', current($command['aliases']));
52     $this->assertArrayHasKey('version_control', $command['engines']);
53     $this->assertArrayHasKey('package_handler', $command['engines']);
54     $this->assertArrayHasKey('release_info', $command['engines']);
55     $this->assertEquals('pm-download', $command['command']);
56     $this->assertEquals('pm', $command['commandfile']);
57     $this->assertEquals('drush_command', $command['callback']);
58     $this->assertArrayHasKey('examples', $command['sections']);
59     $this->assertTrue($command['is_alias']);
60
61     $command = $commands['pm-download'];
62     $this->assertArrayNotHasKey('is_alias', $command);
63   }
64 }