You are here

public function UpdateSemverTestBase::testNormalUpdateAvailable in Drupal 9

Tests the Update Manager module when one normal update is available.

File

core/modules/update/tests/src/Functional/UpdateSemverTestBase.php, line 84

Class

UpdateSemverTestBase
Common test methods for projects that use semver version releases.

Namespace

Drupal\Tests\update\Functional

Code

public function testNormalUpdateAvailable() {
  $this
    ->setProjectInstalledVersion('8.0.0');

  // Ensure that the update check requires a token.
  $this
    ->drupalGet('admin/reports/updates/check');
  $this
    ->assertSession()
    ->statusCodeEquals(403);
  foreach ([
    0,
    1,
  ] as $minor_version) {
    foreach ([
      '-alpha1',
      '-beta1',
      '',
    ] as $extra_version) {
      $full_version = "8.{$minor_version}.1{$extra_version}";
      $this
        ->refreshUpdateStatus([
        $this->updateProject => "{$minor_version}.1" . $extra_version,
      ]);
      $this
        ->standardTests();
      $this
        ->drupalGet('admin/reports/updates');
      $this
        ->clickLink('Check manually');
      $this
        ->checkForMetaRefresh();
      $this
        ->assertUpdateTableTextNotContains('Security update required!');

      // The XML test fixtures for this method all contain the '8.2.0' release
      // but because '8.2.0' is not in a supported branch it will not be in
      // the available updates.
      $this
        ->assertSession()
        ->responseNotContains('8.2.0');
      switch ($minor_version) {
        case 0:

          // Both stable and unstable releases are available.
          // A stable release is the latest.
          if ($extra_version == '') {
            $this
              ->assertUpdateTableTextNotContains('Up to date');
            $this
              ->assertUpdateTableTextContains('Update available');
            $this
              ->assertVersionUpdateLinks('Recommended version:', $full_version);
            $this
              ->assertUpdateTableTextNotContains('Latest version:');
            $this
              ->assertUpdateTableElementContains('warning.svg');
          }
          else {
            $this
              ->assertUpdateTableTextContains('Up to date');
            $this
              ->assertUpdateTableTextNotContains('Update available');
            $this
              ->assertUpdateTableTextNotContains('Recommended version:');
            $this
              ->assertVersionUpdateLinks('Latest version:', $full_version);
            $this
              ->assertUpdateTableElementContains('check.svg');
          }
          break;
        case 1:

          // Both stable and unstable releases are available.
          // A stable release is the latest.
          if ($extra_version == '') {
            $this
              ->assertUpdateTableTextNotContains('Up to date');
            $this
              ->assertUpdateTableTextContains('Update available');
            $this
              ->assertVersionUpdateLinks('Recommended version:', $full_version);
            $this
              ->assertUpdateTableTextNotContains('Latest version:');
            $this
              ->assertUpdateTableElementContains('warning.svg');
          }
          else {
            $this
              ->assertUpdateTableTextNotContains('Up to date');
            $this
              ->assertUpdateTableTextContains('Update available');
            $this
              ->assertVersionUpdateLinks('Recommended version:', '8.1.0');
            $this
              ->assertVersionUpdateLinks('Latest version:', $full_version);
            $this
              ->assertUpdateTableElementContains('warning.svg');
          }
          break;
      }
    }
  }
}