UpdateCoreTest.php 10.2 KB
Newer Older
1 2 3 4 5 6 7 8 9
<?php

/**
 * @file
 * Definition of Drupal\update\Tests\UpdateCoreTest.
 */

namespace Drupal\update\Tests;

10 11 12
/**
 * Tests behavior related to discovering and listing updates to Drupal core.
 */
13 14
class UpdateCoreTest extends UpdateTestBase {

15 16 17 18 19
  /**
   * Modules to enable.
   *
   * @var array
   */
20
  public static $modules = array('update_test', 'update', 'language');
21

22 23 24
  public static function getInfo() {
    return array(
      'name' => 'Update core functionality',
25
      'description' => 'Tests the Update Manager module through a series of functional tests using mock XML data.',
26 27 28 29 30
      'group' => 'Update',
    );
  }

  function setUp() {
31
    parent::setUp();
32 33 34 35
    $admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer modules'));
    $this->drupalLogin($admin_user);
  }

36

37
  /**
38
   * Tests the Update Manager module when no updates are available.
39 40 41 42 43 44 45 46 47 48 49
   */
  function testNoUpdatesAvailable() {
    $this->setSystemInfo7_0();
    $this->refreshUpdateStatus(array('drupal' => '0'));
    $this->standardTests();
    $this->assertText(t('Up to date'));
    $this->assertNoText(t('Update available'));
    $this->assertNoText(t('Security update required!'));
  }

  /**
50
   * Tests the Update Manager module when one normal update is available.
51 52 53 54 55 56 57 58
   */
  function testNormalUpdateAvailable() {
    $this->setSystemInfo7_0();
    $this->refreshUpdateStatus(array('drupal' => '1'));
    $this->standardTests();
    $this->assertNoText(t('Up to date'));
    $this->assertText(t('Update available'));
    $this->assertNoText(t('Security update required!'));
59 60 61
    $this->assertRaw(l('7.1', 'http://example.com/drupal-7-1-release'), 'Link to release appears.');
    $this->assertRaw(l(t('Download'), 'http://example.com/drupal-7-1.tar.gz'), 'Link to download appears.');
    $this->assertRaw(l(t('Release notes'), 'http://example.com/drupal-7-1-release'), 'Link to release notes appears.');
62 63 64
  }

  /**
65
   * Tests the Update Manager module when a security update is available.
66 67 68 69 70 71 72 73
   */
  function testSecurityUpdateAvailable() {
    $this->setSystemInfo7_0();
    $this->refreshUpdateStatus(array('drupal' => '2-sec'));
    $this->standardTests();
    $this->assertNoText(t('Up to date'));
    $this->assertNoText(t('Update available'));
    $this->assertText(t('Security update required!'));
74 75 76
    $this->assertRaw(l('7.2', 'http://example.com/drupal-7-2-release'), 'Link to release appears.');
    $this->assertRaw(l(t('Download'), 'http://example.com/drupal-7-2.tar.gz'), 'Link to download appears.');
    $this->assertRaw(l(t('Release notes'), 'http://example.com/drupal-7-2-release'), 'Link to release notes appears.');
77 78 79
  }

  /**
80
   * Ensures proper results where there are date mismatches among modules.
81 82 83 84 85 86 87 88 89 90 91 92 93
   */
  function testDatestampMismatch() {
    $system_info = array(
      '#all' => array(
        // We need to think we're running a -dev snapshot to see dates.
        'version' => '7.0-dev',
        'datestamp' => time(),
      ),
      'block' => array(
        // This is 2001-09-09 01:46:40 GMT, so test for "2001-Sep-".
        'datestamp' => '1000000000',
      ),
    );
94
    \Drupal::config('update_test.settings')->set('system_info', $system_info)->save();
95 96 97 98 99 100 101 102
    $this->refreshUpdateStatus(array('drupal' => 'dev'));
    $this->assertNoText(t('2001-Sep-'));
    $this->assertText(t('Up to date'));
    $this->assertNoText(t('Update available'));
    $this->assertNoText(t('Security update required!'));
  }

  /**
103
   * Checks that running cron updates the list of available updates.
104 105 106
   */
  function testModulePageRunCron() {
    $this->setSystemInfo7_0();
107 108
    \Drupal::config('update.settings')->set('fetch.url', url('update-test', array('absolute' => TRUE)))->save();
    \Drupal::config('update_test.settings')->set('xml_map', array('drupal' => '0'))->save();
109 110 111 112 113 114 115

    $this->cronRun();
    $this->drupalGet('admin/modules');
    $this->assertNoText(t('No update information available.'));
  }

  /**
116
   * Checks the messages at admin/modules when the site is up to date.
117 118 119 120
   */
  function testModulePageUpToDate() {
    $this->setSystemInfo7_0();
    // Instead of using refreshUpdateStatus(), set these manually.
121 122
    \Drupal::config('update.settings')->set('fetch.url', url('update-test', array('absolute' => TRUE)))->save();
    \Drupal::config('update_test.settings')->set('xml_map', array('drupal' => '0'))->save();
123 124 125 126 127 128 129 130 131 132

    $this->drupalGet('admin/reports/updates');
    $this->clickLink(t('Check manually'));
    $this->assertText(t('Checked available update data for one project.'));
    $this->drupalGet('admin/modules');
    $this->assertNoText(t('There are updates available for your version of Drupal.'));
    $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  }

  /**
133
   * Checks the messages at admin/modules when an update is missing.
134 135 136 137
   */
  function testModulePageRegularUpdate() {
    $this->setSystemInfo7_0();
    // Instead of using refreshUpdateStatus(), set these manually.
138 139
    \Drupal::config('update.settings')->set('fetch.url', url('update-test', array('absolute' => TRUE)))->save();
    \Drupal::config('update_test.settings')->set('xml_map', array('drupal' => '1'))->save();
140 141 142 143 144 145 146 147 148 149

    $this->drupalGet('admin/reports/updates');
    $this->clickLink(t('Check manually'));
    $this->assertText(t('Checked available update data for one project.'));
    $this->drupalGet('admin/modules');
    $this->assertText(t('There are updates available for your version of Drupal.'));
    $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  }

  /**
150
   * Checks the messages at admin/modules when a security update is missing.
151 152 153 154
   */
  function testModulePageSecurityUpdate() {
    $this->setSystemInfo7_0();
    // Instead of using refreshUpdateStatus(), set these manually.
155 156
    \Drupal::config('update.settings')->set('fetch.url', url('update-test', array('absolute' => TRUE)))->save();
    \Drupal::config('update_test.settings')->set('xml_map', array('drupal' => '2-sec'))->save();
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184

    $this->drupalGet('admin/reports/updates');
    $this->clickLink(t('Check manually'));
    $this->assertText(t('Checked available update data for one project.'));
    $this->drupalGet('admin/modules');
    $this->assertNoText(t('There are updates available for your version of Drupal.'));
    $this->assertText(t('There is a security update available for your version of Drupal.'));

    // Make sure admin/appearance warns you you're missing a security update.
    $this->drupalGet('admin/appearance');
    $this->assertNoText(t('There are updates available for your version of Drupal.'));
    $this->assertText(t('There is a security update available for your version of Drupal.'));

    // Make sure duplicate messages don't appear on Update status pages.
    $this->drupalGet('admin/reports/status');
    // We're expecting "There is a security update..." inside the status report
    // itself, but the drupal_set_message() appears as an li so we can prefix
    // with that and search for the raw HTML.
    $this->assertNoRaw('<li>' . t('There is a security update available for your version of Drupal.'));

    $this->drupalGet('admin/reports/updates');
    $this->assertNoText(t('There is a security update available for your version of Drupal.'));

    $this->drupalGet('admin/reports/updates/settings');
    $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  }

  /**
185
   * Tests the Update Manager module when the update server returns 503 errors.
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
   */
  function testServiceUnavailable() {
    $this->refreshUpdateStatus(array(), '503-error');
    // Ensure that no "Warning: SimpleXMLElement..." parse errors are found.
    $this->assertNoText('SimpleXMLElement');
    $this->assertUniqueText(t('Failed to get available update data for one project.'));
  }

  /**
   * Tests that exactly one fetch task per project is created and not more.
   */
  function testFetchTasks() {
    $projecta = array(
      'name' => 'aaa_update_test',
    );
    $projectb = array(
      'name' => 'bbb_update_test',
    );
204
    $queue = \Drupal::queue('update_fetch_tasks');
205 206 207 208 209 210 211 212 213
    $this->assertEqual($queue->numberOfItems(), 0, 'Queue is empty');
    update_create_fetch_task($projecta);
    $this->assertEqual($queue->numberOfItems(), 1, 'Queue contains one item');
    update_create_fetch_task($projectb);
    $this->assertEqual($queue->numberOfItems(), 2, 'Queue contains two items');
    // Try to add project a again.
    update_create_fetch_task($projecta);
    $this->assertEqual($queue->numberOfItems(), 2, 'Queue still contains two items');

214 215
    // Clear storage and try again.
    update_storage_clear();
216 217 218 219 220
    drupal_static_reset('_update_create_fetch_task');
    update_create_fetch_task($projecta);
    $this->assertEqual($queue->numberOfItems(), 2, 'Queue contains two items');
  }

221 222 223 224 225 226
  /**
   * Checks language module in core package at admin/reports/updates.
   */
  function testLanguageModuleUpdate() {
    $this->setSystemInfo7_0();
    // Instead of using refreshUpdateStatus(), set these manually.
227 228
    \Drupal::config('update.settings')->set('fetch.url', url('update-test', array('absolute' => TRUE)))->save();
    \Drupal::config('update_test.settings')->set('xml_map', array('drupal' => '1'))->save();
229 230 231 232 233

    $this->drupalGet('admin/reports/updates');
    $this->assertText(t('Language'));
  }

234 235 236
  /**
   * Sets the version to 7.0 when no project-specific mapping is defined.
   */
237 238 239 240 241 242
  protected function setSystemInfo7_0() {
    $setting = array(
      '#all' => array(
        'version' => '7.0',
      ),
    );
243
    \Drupal::config('update_test.settings')->set('system_info', $setting)->save();
244
  }
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265

  /**
   * Ensures that the local actions appear.
   */
  public function testLocalActions() {
    $admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer modules', 'administer software updates', 'administer themes'));
    $this->drupalLogin($admin_user);

    $this->drupalGet('admin/modules');
    $this->clickLink(t('Install new module'));
    $this->assertUrl('admin/modules/install');

    $this->drupalGet('admin/appearance');
    $this->clickLink(t('Install new theme'));
    $this->assertUrl('admin/theme/install');

    $this->drupalGet('admin/reports/updates');
    $this->clickLink(t('Install new module or theme'));
    $this->assertUrl('admin/reports/updates/install');
  }

266
}