function UpdateSemverCoreTest::testBrokenThenFixedUpdates

Same name and namespace in other branches
  1. 9 core/modules/update/tests/src/Functional/UpdateSemverCoreTest.php \Drupal\Tests\update\Functional\UpdateSemverCoreTest::testBrokenThenFixedUpdates()
  2. 11.x core/modules/update/tests/src/Functional/UpdateSemverCoreTest.php \Drupal\Tests\update\Functional\UpdateSemverCoreTest::testBrokenThenFixedUpdates()

Checks that Drupal recovers after problems connecting to update server.

This test uses the following XML fixtures.

  • drupal.broken.xml
  • drupal.sec.8.0.2.xml 'supported_branches' is '8.0.,8.1.'.

File

core/modules/update/tests/src/Functional/UpdateSemverCoreTest.php, line 86

Class

UpdateSemverCoreTest
Tests edge cases of the Available Updates report UI.

Namespace

Drupal\Tests\update\Functional

Code

public function testBrokenThenFixedUpdates() : void {
  $this->drupalLogin($this->drupalCreateUser([
    'administer site configuration',
    'view update notifications',
    'access administration pages',
  ]));
  $this->setProjectInstalledVersion('8.0.0');
  // Instead of using refreshUpdateStatus(), set these manually.
  $this->config('update.settings')
    ->set('fetch.url', Url::fromRoute('update_test.update_test')->setAbsolute()
    ->toString())
    ->save();
  // Use update XML that has no information to simulate a broken response from
  // the update server.
  $this->mockReleaseHistory([
    'drupal' => 'broken',
  ]);
  // This will retrieve broken updates.
  $this->cronRun();
  $this->drupalGet('admin/reports/status');
  $this->assertSession()
    ->statusCodeEquals(200);
  $this->assertSession()
    ->pageTextContains('There was a problem checking available updates for Drupal.');
  $this->mockReleaseHistory([
    'drupal' => 'sec.8.0.2',
  ]);
  // Simulate the update_available_releases state expiring before cron is run
  // and the state is used by \Drupal\update\UpdateManager::getProjects().
  \Drupal::keyValueExpirable('update_available_releases')->deleteAll();
  // This cron run should retrieve fixed updates.
  $this->cronRun();
  $this->drupalGet('admin/config');
  $this->assertSession()
    ->statusCodeEquals(200);
  $this->assertSession()
    ->pageTextContains('There is a security update available for your version of Drupal.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.