5 * Prepare a codebase with modules in several update status and test pm-updatestatus.
14 class pmUpdateStatus extends CommandUnishTestCase {
17 * Setup the test environment.
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.
22 * Several drupal core versions are already tested by pmUpdateCode.
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
31 $sites = $this->setUpDrupal(1, TRUE, "7.30");
33 'root' => $this->webroot(),
37 'skip' => NULL, // No FirePHP
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';
54 $modules_dl[] = 'ctools';
55 $modules_en[] = 'ctools';
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);
66 * Test several update statuses via drupal backend.
68 function testUpdateStatusDrupal() {
69 $this->doTest('drupal');
73 * Test several update statuses via drush backend.
75 function testUpdateStatusDrush() {
76 $this->doTest('drush');
79 function doTest($update_backend) {
81 // Test several projects with a variety of statuses.
83 'root' => $this->webroot(),
84 'uri' => key($this->getSites()),
87 'update-backend' => $update_backend,
89 $this->drush('pm-updatestatus', array(), $options);
90 $parsed = $this->parse_backend_output($this->getOutput());
91 $data = $parsed['object'];
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',
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'");
107 // Test statuses when asked for specific projects and versions.
109 'bad_judgement-1.0-rc38',
114 $this->drush('pm-updatestatus', $args, $options);
115 $parsed = $this->parse_backend_output($this->getOutput());
116 $data = $parsed['object'];
119 'bad_judgement' => 'Specified version already installed',
120 'ctools' => 'Specified version not found',
121 'devel' => 'Specified version available',
122 'foo' => 'Specified project not found',
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'");
128 // We don't expect any output for other projects than the provided ones.
129 $not_expected = array(
134 foreach ($not_expected as $module) {
135 $this->assertArrayNotHasKey($module, $data, "$module module not present in pm-updatestatus output");
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'];
145 'drupal' => 'SECURITY UPDATE available',
146 'devel' => 'SECURITY UPDATE available',
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'");
152 // We don't expect any output for projects without security updates.
153 $not_expected = array(
159 foreach ($not_expected as $module) {
160 $this->assertArrayNotHasKey($module, $data, "$module module not present in pm-updatestatus output");
164 // Test --check-disabled.
165 $dis_options = array(
166 'root' => $this->webroot(),
167 'uri' => key($this->getSites()),
170 $this->drush('pm-disable', array('devel'), $dis_options);
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");
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");