5 * Prepare a codebase and upgrade it in several stages, exercising
6 * updatecode's filters.
15 class pmUpdateCode extends CommandUnishTestCase {
18 * An array of modules to be downloaded and enabled.
22 private function getPreviousStable($project) {
23 // Call drush pm-releases and get the output
24 $this->drush('pm-releases', array($project), array('all' => NULL, 'fields' => 'Release'));
25 $list = $this->getOutputAsList();
26 // Line 0 is "Release"
27 // Line 1 is "...-dev"
28 // Line 2 is current best release
29 // Line 3 is the previous release
30 return trim($list[3]);
34 * Download old core and older contrib releases which will always need updating.
36 public function setUp() {
37 if (UNISH_DRUPAL_MAJOR_VERSION >= 8) {
38 // Make sure that we can still update from the previous release
39 // to the current release.
40 $core = $this->getPreviousStable("drupal-8");
41 $modules_str = 'unish-8.x-1.2,honeypot-8.x-1.19-beta14';
42 $this->modules = array('block', 'unish', 'honeypot');
44 elseif (UNISH_DRUPAL_MAJOR_VERSION == 7) {
46 $modules_str = 'devel-7.x-1.0-rc1,webform-7.x-3.4-beta1';
47 $this->modules = array('menu', 'devel', 'webform');
51 $modules_str = 'devel-6.x-1.26,webform-6.x-3.18';
52 $this->modules = array('menu', 'devel', 'webform');
55 $sites = $this->setUpDrupal(1, TRUE, $core);
57 'root' => $this->webroot(),
62 'skip' => NULL, // No FirePHP
66 $this->drush('pm-download', array($modules_str), $options);
67 $this->drush('pm-enable', $this->modules, $options);
70 function testUpdateCode() {
71 if (UNISH_DRUPAL_MAJOR_VERSION < 7) {
72 $this->markTestSkipped("pm-update does not work once Drupal core reaches EOL.");
74 $extension = UNISH_DRUPAL_MAJOR_VERSION == 8 ? '.info.yml' : '.info';
75 $first = $this->modules[1];
76 $second = $this->modules[2];
79 'root' => $this->webroot(),
80 'uri' => key($this->getSites()),
82 'backup-dir' => UNISH_SANDBOX . '/backups',
84 'check-updatedb' => 0,
85 // Needed in order to get 'Up to date' in the return value of updatestatus. See pm_project_filter().
90 // Upgrade a specific module.
91 $this->drush('pm-updatecode', array($first), $options + array());
93 // Assure that first was upgraded and second was not.
94 $this->drush('pm-updatestatus', array(), $options + array('format' => 'json'));
95 $all = $this->getOutputFromJSON();
96 $this->assertEquals($all->$first->existing_version, $all->$first->candidate_version);
97 $this->assertNotEquals($all->$second->existing_version, $all->$second->candidate_version);
99 // Lock second, and update core.
100 $this->drush('pm-updatecode', array(), $options + array('lock' => $second));
101 $list = $this->getOutputAsList(); // For debugging.
102 $this->drush('pm-updatestatus', array(), $options + array('format' => 'json'));
103 $all = $this->getOutputFromJSON();
104 $this->assertEquals($all->drupal->existing_version, $all->drupal->candidate_version);
105 $this->assertNotEquals($all->$second->existing_version, $all->$second->candidate_version);
107 // Unlock second, update, and check.
108 $this->drush('pm-updatecode', array(), $options + array('unlock' => $second, 'no-backup' => NULL));
109 $list = $this->getOutputAsList();
110 $this->drush('pm-updatestatus', array(), $options + array('format' => 'json'));
111 $all = $this->getOutputFromJSON();
112 $this->assertEquals($all->$second->existing_version, $all->$second->candidate_version);
114 // Verify that we keep backups as instructed.
115 $backup_dir = UNISH_SANDBOX . '/backups';
116 $Directory = new \RecursiveDirectoryIterator($backup_dir);
117 $Iterator = new \RecursiveIteratorIterator($Directory);
119 foreach ($Iterator as $item) {
120 if (basename($item) == $first . $extension) {
125 $this->assertTrue($found, 'Backup exists and contains the first module.');
127 $Iterator = new \RecursiveIteratorIterator($Directory);
129 foreach ($Iterator as $item) {
130 if (basename($item) == $second . '.module') {
135 $this->assertFalse($found, 'Backup exists and does not contain the second module.');