Version 1
[yaffs-website] / vendor / drush / drush / tests / pmUpdateCodeTest.php
1 <?php
2
3 /**
4   * @file
5   *   Prepare a codebase and upgrade it in several stages, exercising
6   *   updatecode's filters.
7   */
8
9 namespace Unish;
10
11 /**
12  *  @group slow
13  *  @group pm
14  */
15 class pmUpdateCode extends CommandUnishTestCase {
16
17   /*
18    * An array of modules to be downloaded and enabled.
19    */
20   public $modules;
21
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]);
31   }
32
33   /**
34    * Download old core and older contrib releases which will always need updating.
35    */
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');
43     }
44     elseif (UNISH_DRUPAL_MAJOR_VERSION == 7) {
45       $core = '7.0-rc3';
46       $modules_str = 'devel-7.x-1.0-rc1,webform-7.x-3.4-beta1';
47       $this->modules = array('menu', 'devel', 'webform');
48     }
49     else {
50       $core = '6.28';
51       $modules_str = 'devel-6.x-1.26,webform-6.x-3.18';
52       $this->modules = array('menu', 'devel', 'webform');
53     }
54
55     $sites = $this->setUpDrupal(1, TRUE, $core);
56     $options = array(
57       'root' => $this->webroot(),
58       'uri' => key($sites),
59       'yes' => NULL,
60       'quiet' => NULL,
61       'cache' => NULL,
62       'skip' => NULL, // No FirePHP
63       'strict' => 0,
64     );
65
66     $this->drush('pm-download', array($modules_str), $options);
67     $this->drush('pm-enable', $this->modules, $options);
68   }
69
70   function testUpdateCode() {
71     if (UNISH_DRUPAL_MAJOR_VERSION < 7) {
72       $this->markTestSkipped("pm-update does not work once Drupal core reaches EOL.");
73     }
74     $extension = UNISH_DRUPAL_MAJOR_VERSION == 8 ? '.info.yml' : '.info';
75     $first = $this->modules[1];
76     $second = $this->modules[2];
77
78     $options = array(
79       'root' => $this->webroot(),
80       'uri' => key($this->getSites()),
81       'yes' => NULL,
82       'backup-dir' => UNISH_SANDBOX . '/backups',
83       'cache' => NULL,
84       'check-updatedb' => 0,
85       // Needed in order to get 'Up to date' in the return value of updatestatus. See pm_project_filter().
86       'verbose' => NULL,
87       'strict' => 0,
88     );
89
90     // Upgrade a specific module.
91     $this->drush('pm-updatecode', array($first), $options + array());
92
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);
98
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);
106
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);
113
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);
118     $found = FALSE;
119     foreach ($Iterator as $item) {
120       if (basename($item) == $first . $extension) {
121         $found = TRUE;
122         break;
123       }
124     }
125     $this->assertTrue($found, 'Backup exists and contains the first module.');
126
127     $Iterator = new \RecursiveIteratorIterator($Directory);
128     $found = FALSE;
129     foreach ($Iterator as $item) {
130       if (basename($item) == $second . '.module') {
131         $found = TRUE;
132         break;
133       }
134     }
135     $this->assertFalse($found, 'Backup exists and does not contain the second module.');
136   }
137 }