Yaffs site version 1.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 "...-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]);
33   }
34
35   /**
36    * Download old core and older contrib releases which will always need updating.
37    */
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');
45     }
46     elseif (UNISH_DRUPAL_MAJOR_VERSION == 7) {
47       $core = '7.0-rc3';
48       $modules_str = 'devel-7.x-1.0-rc1,webform-7.x-3.4-beta1';
49       $this->modules = array('menu', 'devel', 'webform');
50     }
51     else {
52       $core = '6.28';
53       $modules_str = 'devel-6.x-1.26,webform-6.x-3.18';
54       $this->modules = array('menu', 'devel', 'webform');
55     }
56
57     $sites = $this->setUpDrupal(1, TRUE, $core);
58     $options = array(
59       'root' => $this->webroot(),
60       'uri' => key($sites),
61       'yes' => NULL,
62       'quiet' => NULL,
63       'cache' => NULL,
64       'skip' => NULL, // No FirePHP
65       'strict' => 0,
66     );
67
68     $this->drush('pm-download', array($modules_str), $options);
69     $this->drush('pm-enable', $this->modules, $options);
70   }
71
72   function testUpdateCode() {
73     if (UNISH_DRUPAL_MAJOR_VERSION < 7) {
74       $this->markTestSkipped("pm-update does not work once Drupal core reaches EOL.");
75     }
76     $extension = UNISH_DRUPAL_MAJOR_VERSION == 8 ? '.info.yml' : '.info';
77     $first = $this->modules[1];
78     $second = $this->modules[2];
79
80     $options = array(
81       'root' => $this->webroot(),
82       'uri' => key($this->getSites()),
83       'yes' => NULL,
84       'backup-dir' => UNISH_SANDBOX . '/backups',
85       'cache' => NULL,
86       'check-updatedb' => 0,
87       // Needed in order to get 'Up to date' in the return value of updatestatus. See pm_project_filter().
88       'verbose' => NULL,
89       'strict' => 0,
90     );
91
92     // Upgrade a specific module.
93     $this->drush('pm-updatecode', array($first), $options + array());
94
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);
100
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);
108
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);
115
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);
120     $found = FALSE;
121     foreach ($Iterator as $item) {
122       if (basename($item) == $first . $extension) {
123         $found = TRUE;
124         break;
125       }
126     }
127     $this->assertTrue($found, 'Backup exists and contains the first module.');
128
129     $Iterator = new \RecursiveIteratorIterator($Directory);
130     $found = FALSE;
131     foreach ($Iterator as $item) {
132       if (basename($item) == $second . '.module') {
133         $found = TRUE;
134         break;
135       }
136     }
137     $this->assertFalse($found, 'Backup exists and does not contain the second module.');
138   }
139 }