Version 1
[yaffs-website] / vendor / drush / drush / tests / pmDownloadTest.php
1 <?php
2
3 namespace Unish;
4
5 /**
6   * @group pm
7   */
8 class pmDownloadCase extends CommandUnishTestCase {
9   public function testPmDownload() {
10     $this->drush('pm-download', array('devel'), array('cache' => NULL, 'skip' => NULL)); // No FirePHP
11     $this->assertFileExists(UNISH_SANDBOX . '/devel/README.txt');
12
13     $this->drush('pm-download', array('drupal-7.500'), array('backend' => NULL), NULL, NULL, self::EXIT_ERROR);
14     $parsed = $this->parse_backend_output($this->getOutput());
15     $this->assertArrayHasKey('DRUSH_PM_COULD_NOT_FIND_VERSION', $parsed['error_log']);
16   }
17
18   // @todo Test pure drush commandfile projects. They get special destination.
19   public function testDestination() {
20     // Setup two Drupal sites. Skip install for speed.
21     $sites = $this->setUpDrupal(2, FALSE);
22     $uri = key($sites);
23     $root = $this->webroot();
24
25     // Common options for the invocations below.
26     $devel_options = array(
27       'cache' => NULL,
28       'skip' => NULL, // No FirePHP
29       'strict' => 0, // Invoke from script: do not verify options
30     );
31
32     // Default to Drupal sitewide directory.
33     $options = array(
34       'root' => $root,
35       'uri' => $uri,
36     ) + $devel_options;
37     $this->drush('pm-download', array('devel'), $options);
38     $this->assertFileExists($root . '/' . $this->drupalSitewideDirectory() . '/modules/devel/README.txt');
39
40     //  --use-site-dir
41     // Expand above $options.
42     $options += array('use-site-dir' => NULL);
43     $this->drush('pm-download', array('devel'), $options);
44     $this->assertFileExists("$root/sites/$uri/modules/devel/README.txt");
45     unish_file_delete_recursive("{$root}/sites/{$uri}/modules/devel", TRUE);
46
47     // If we are in site specific dir, then download belongs there.
48     $path_stage = "$root/sites/$uri";
49     // dir gets created by --use-site-dir above,
50     $options = $devel_options;
51     $this->drush('pm-download', array('devel'), $options, NULL, $path_stage);
52     $this->assertFileExists($path_stage . '/modules/devel/README.txt');
53
54     // --destination with absolute path.
55     $destination = UNISH_SANDBOX . '/test-destination1';
56     mkdir($destination);
57     $options = array(
58       'destination' => $destination,
59     ) + $devel_options;
60     $this->drush('pm-download', array('devel'), $options);
61     $this->assertFileExists($destination . '/devel/README.txt');
62
63     // --destination with a relative path.
64     $destination = 'test-destination2';
65     mkdir(UNISH_SANDBOX . '/' . $destination);
66     $options = array(
67       'destination' => $destination,
68     ) + $devel_options;
69     $this->drush('pm-download', array('devel'), $options);
70     $this->assertFileExists(UNISH_SANDBOX . '/' . $destination . '/devel/README.txt');
71 }
72
73   public function testSelect() {
74     $options = array(
75       'select' => NULL,
76       'choice' => 0, // Cancel.
77     );
78     // --select. Specify 6.x since that has so many releases.
79     $this->drush('pm-download', array('devel-6.x'), $options, NULL, NULL, CommandUnishTestCase::UNISH_EXITCODE_USER_ABORT);
80     $items = $this->getOutputAsList();
81     $output = $this->getOutput();
82      // 4 items are: Select message + Cancel + 2 versions.
83     $this->assertEquals(4, count($items), '--select offerred 2 options.');
84     $this->assertContains('6.x-1.x-dev', $output, 'Dev release was shown by --select.');
85
86     // --select --dev. Specify 6.x since that has so many releases.
87     $this->drush('pm-download', array('devel-6.x'), $options + array('dev' => NULL), NULL, NULL, CommandUnishTestCase::UNISH_EXITCODE_USER_ABORT);
88     $items = $this->getOutputAsList();
89     $output = $this->getOutput();
90     // 12 items are: Select message + Cancel + 1 option.
91     $this->assertEquals(3, count($items), '--select --dev expected to offer only one option.');
92     $this->assertContains('6.x-1.x-dev', $output, 'Assure that --dev lists the only dev release.');
93
94     // --select --all. Specify 5.x since this is frozen.
95     $this->drush('pm-download', array('devel-5.x'), $options + array('all' => NULL), NULL, NULL, CommandUnishTestCase::UNISH_EXITCODE_USER_ABORT);
96     $items = $this->getOutputAsList();
97     $output = $this->getOutput();
98     // 12 items are: Select message + Cancel + 9 options.
99     $this->assertEquals(11, count($items), '--select --all offerred 8 options.');
100     $this->assertContains('5.x-0.1', $output, 'Assure that --all lists very old releases.');
101   }
102
103   public function testPackageHandler() {
104     $options = array(
105       'cache' => NULL,
106       'package-handler' => 'git_drupalorg',
107       'yes' => NULL,
108     );
109     $this->drush('pm-download', array('devel'), $options);
110     $this->assertFileExists(UNISH_SANDBOX . '/devel/README.txt');
111     $this->assertFileExists(UNISH_SANDBOX . '/devel/.git');
112   }
113 }