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 "...-dev"
29 // Line 3 is "...-dev"
30 // Line 4 is current best release
31 // Line 5 is the previous release
32 return trim($list[5]);
36 * Download old core and older contrib releases which will always need updating.
38 public function setUp() {
39 if (UNISH_DRUPAL_MAJOR_VERSION >= 8) {
40 // Make sure that we can still update from the previous release
41 // to the current release.
42 $core = $this->getPreviousStable("drupal-8");
43 $modules_str = 'unish-8.x-1.2,honeypot-8.x-1.19-beta14';
44 $this->modules = array('block', 'unish', 'honeypot');
46 elseif (UNISH_DRUPAL_MAJOR_VERSION == 7) {
48 $modules_str = 'devel-7.x-1.0-rc1,webform-7.x-3.4-beta1';
49 $this->modules = array('menu', 'devel', 'webform');
53 $modules_str = 'devel-6.x-1.26,webform-6.x-3.18';
54 $this->modules = array('menu', 'devel', 'webform');
57 $sites = $this->setUpDrupal(1, TRUE, $core);
59 'root' => $this->webroot(),
64 'skip' => NULL, // No FirePHP
68 $this->drush('pm-download', array($modules_str), $options);
69 $this->drush('pm-enable', $this->modules, $options);
72 function testUpdateCode() {
73 if (UNISH_DRUPAL_MAJOR_VERSION < 7) {
74 $this->markTestSkipped("pm-update does not work once Drupal core reaches EOL.");
76 $extension = UNISH_DRUPAL_MAJOR_VERSION == 8 ? '.info.yml' : '.info';
77 $first = $this->modules[1];
78 $second = $this->modules[2];
81 'root' => $this->webroot(),
82 'uri' => key($this->getSites()),
84 'backup-dir' => UNISH_SANDBOX . '/backups',
86 'check-updatedb' => 0,
87 // Needed in order to get 'Up to date' in the return value of updatestatus. See pm_project_filter().
92 // Upgrade a specific module.
93 $this->drush('pm-updatecode', array($first), $options + array());
95 // Assure that first was upgraded and second was not.
96 $this->drush('pm-updatestatus', array(), $options + array('format' => 'json'));
97 $all = $this->getOutputFromJSON();
98 $this->assertEquals($all->$first->existing_version, $all->$first->candidate_version);
99 $this->assertNotEquals($all->$second->existing_version, $all->$second->candidate_version);
101 // Lock second, and update core.
102 $this->drush('pm-updatecode', array(), $options + array('lock' => $second));
103 $list = $this->getOutputAsList(); // For debugging.
104 $this->drush('pm-updatestatus', array(), $options + array('format' => 'json'));
105 $all = $this->getOutputFromJSON();
106 $this->assertEquals($all->drupal->existing_version, $all->drupal->candidate_version);
107 $this->assertNotEquals($all->$second->existing_version, $all->$second->candidate_version);
109 // Unlock second, update, and check.
110 $this->drush('pm-updatecode', array(), $options + array('unlock' => $second, 'no-backup' => NULL));
111 $list = $this->getOutputAsList();
112 $this->drush('pm-updatestatus', array(), $options + array('format' => 'json'));
113 $all = $this->getOutputFromJSON();
114 $this->assertEquals($all->$second->existing_version, $all->$second->candidate_version);
116 // Verify that we keep backups as instructed.
117 $backup_dir = UNISH_SANDBOX . '/backups';
118 $Directory = new \RecursiveDirectoryIterator($backup_dir);
119 $Iterator = new \RecursiveIteratorIterator($Directory);
121 foreach ($Iterator as $item) {
122 if (basename($item) == $first . $extension) {
127 $this->assertTrue($found, 'Backup exists and contains the first module.');
129 $Iterator = new \RecursiveIteratorIterator($Directory);
131 foreach ($Iterator as $item) {
132 if (basename($item) == $second . '.module') {
137 $this->assertFalse($found, 'Backup exists and does not contain the second module.');