Version 1
[yaffs-website] / vendor / drush / drush / tests / pmUpdateStatusTest.php
1 <?php
2
3 /**
4   * @file
5   *   Prepare a codebase with modules in several update status and test pm-updatestatus.
6   */
7
8 namespace Unish;
9
10 /**
11  *  @group slow
12  *  @group pm
13  */
14 class pmUpdateStatus extends CommandUnishTestCase {
15
16   /**
17    * Setup the test environment.
18    *
19    * Here we assume that any Drupal core version parses data from Drupal's
20    * update service the same way. We focus on testing drush functionality.
21    *
22    * Several drupal core versions are already tested by pmUpdateCode.
23    *
24    * We choose to setup a Drupal 7 environment for convenience:
25    *  - It has modules in each maintenance status
26    *    and they're not willing to change in short
27    *  - Drupal 6 will start to be unsupported at some point
28    *  - Drupal 8 still has not enough variety to cover the tests
29    */
30   function setUp() {
31     $sites = $this->setUpDrupal(1, TRUE, "7.30");
32     $options = array(
33       'root' => $this->webroot(),
34       'uri' => key($sites),
35       'yes' => NULL,
36       'cache' => NULL,
37       'skip' => NULL, // No FirePHP
38       'strict' => 0,
39     );
40
41     // Prepare a list of modules with several update statuses.
42     $modules_dl = array();
43     $modules_en = array();
44     // Update available but not a security one. Cross fingers they never release a security update.
45     $modules_dl[] = 'bad_judgement-1.0-rc38';
46     $modules_en[] = 'bad_judgement';
47     // Old devel release with a security update available.
48     $modules_dl[] = 'devel-7.x-1.0-rc1';
49     $modules_en[] = 'devel';
50     // Installed version not supported.
51     $modules_dl[] = 'cck-2.x-dev';
52     $modules_en[] = 'cck';
53     // Up to date.
54     $modules_dl[] = 'ctools';
55     $modules_en[] = 'ctools';
56
57     // Download and enable the modules. Additionally download a module from git, so it has no version information.
58     $this->drush('pm-download', $modules_dl, $options);
59     $this->drush('pm-download', array('zen'), $options + array('package-handler' => 'git_drupalorg'));
60     $modules_en[] = 'zen';
61     // self::EXIT_ERROR because of bad_judgement.
62     $this->drush('pm-enable', $modules_en, $options, NULL, NULL, self::EXIT_ERROR);
63   }
64
65   /**
66    * Test several update statuses via drupal backend.
67    */
68   function testUpdateStatusDrupal() {
69     $this->doTest('drupal');
70   }
71
72   /**
73    * Test several update statuses via drush backend.
74    */
75   function testUpdateStatusDrush() {
76     $this->doTest('drush');
77   }
78
79   function doTest($update_backend) {
80
81     // Test several projects with a variety of statuses.
82     $options = array(
83       'root' => $this->webroot(),
84       'uri' => key($this->getSites()),
85       'verbose' => NULL,
86       'backend' => NULL,
87       'update-backend' => $update_backend,
88     );
89     $this->drush('pm-updatestatus', array(), $options);
90     $parsed = $this->parse_backend_output($this->getOutput());
91     $data = $parsed['object'];
92
93     $expected = array(
94       'drupal'                  => 'SECURITY UPDATE available',
95       'bad_judgement'           => 'Update available',
96       'ctools'                  => 'Up to date',
97       'devel'                   => 'SECURITY UPDATE available',
98       'cck'                     => 'Installed version not supported',
99       'zen'                     => 'Project was not packaged by drupal.org but obtained from git. You need to enable git_deploy module',
100     );
101     foreach ($expected as $module => $status_msg) {
102       $this->assertArrayHasKey($module, $data, "$module module present in pm-updatestatus output");
103       $this->assertEquals($data[$module]['status_msg'], $status_msg, "$module status is '$status_msg'");
104     }
105
106
107     // Test statuses when asked for specific projects and versions.
108     $args = array(
109       'bad_judgement-1.0-rc38',
110       'ctools-0.0',
111       'devel-1.5',
112       'foo',
113     );
114     $this->drush('pm-updatestatus', $args, $options);
115     $parsed = $this->parse_backend_output($this->getOutput());
116     $data = $parsed['object'];
117
118     $expected = array(
119       'bad_judgement'           => 'Specified version already installed',
120       'ctools'                  => 'Specified version not found',
121       'devel'                   => 'Specified version available',
122       'foo'                     => 'Specified project not found',
123     );
124     foreach ($expected as $module => $status_msg) {
125       $this->assertArrayHasKey($module, $data, "$module module present in pm-updatestatus output");
126       $this->assertEquals($data[$module]['status_msg'], $status_msg, "$module status is '$status_msg'");
127     }
128     // We don't expect any output for other projects than the provided ones.
129     $not_expected = array(
130       'drupal',
131       'cck',
132       'zen',
133     );
134     foreach ($not_expected as $module) {
135       $this->assertArrayNotHasKey($module, $data, "$module module not present in pm-updatestatus output");
136     }
137
138
139     // Test --security-only.
140     $this->drush('pm-updatestatus', array(), $options + array('security-only' => NULL));
141     $parsed = $this->parse_backend_output($this->getOutput());
142     $data = $parsed['object'];
143
144     $expected = array(
145       'drupal' => 'SECURITY UPDATE available',
146       'devel'  => 'SECURITY UPDATE available',
147     );
148     foreach ($expected as $module => $status_msg) {
149       $this->assertArrayHasKey($module, $data, "$module module present in pm-updatestatus output");
150       $this->assertEquals($data[$module]['status_msg'], $status_msg, "$module status is '$status_msg'");
151     }
152     // We don't expect any output for projects without security updates.
153     $not_expected = array(
154       'bad_judgement',
155       'ctools',
156       'cck',
157       'zen',
158     );
159     foreach ($not_expected as $module) {
160       $this->assertArrayNotHasKey($module, $data, "$module module not present in pm-updatestatus output");
161     }
162
163
164     // Test --check-disabled.
165     $dis_options = array(
166       'root' => $this->webroot(),
167       'uri' => key($this->getSites()),
168       'yes' => NULL,
169     );
170     $this->drush('pm-disable', array('devel'), $dis_options);
171
172     $this->drush('pm-updatestatus', array(), $options + array('check-disabled' => 1));
173     $parsed = $this->parse_backend_output($this->getOutput());
174     $data = $parsed['object'];
175     $this->assertArrayHasKey('devel', $data, "devel module present in pm-updatestatus output");
176
177     $this->drush('pm-updatestatus', array(), $options + array('check-disabled' => 0));
178     $parsed = $this->parse_backend_output($this->getOutput());
179     $data = $parsed['object'];
180     $this->assertArrayNotHasKey('devel', $data, "devel module not present in pm-updatestatus output");
181   }
182 }
183