You are here

public function UpdateContribTest::testNormalUpdateAvailable in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/update/tests/src/Functional/UpdateContribTest.php \Drupal\Tests\update\Functional\UpdateContribTest::testNormalUpdateAvailable()
  2. 10 core/modules/update/tests/src/Functional/UpdateContribTest.php \Drupal\Tests\update\Functional\UpdateContribTest::testNormalUpdateAvailable()

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

File

core/modules/update/tests/src/Functional/UpdateContribTest.php, line 249

Class

UpdateContribTest
Tests how the Update Manager module handles contributed modules and themes in a series of functional tests using mock XML data.

Namespace

Drupal\Tests\update\Functional

Code

public function testNormalUpdateAvailable() {
  $assert_session = $this
    ->assertSession();

  // Ensure that the update check requires a token.
  $this
    ->drupalGet('admin/reports/updates/check');
  $assert_session
    ->statusCodeEquals(403);
  $system_info = [
    'aaa_update_test' => [
      'project' => 'aaa_update_test',
      'version' => '8.x-1.0',
      'hidden' => FALSE,
    ],
  ];
  $this
    ->config('update_test.settings')
    ->set('system_info', $system_info)
    ->save();
  foreach ([
    '1.1',
    '1.2',
    '2.0',
  ] as $version) {
    foreach ([
      '-beta1',
      '-alpha1',
      '',
    ] as $extra_version) {
      $full_version = "8.x-{$version}{$extra_version}";
      $this
        ->refreshUpdateStatus([
        'drupal' => '0.0',
        'aaa_update_test' => str_replace('.', '_', $version) . $extra_version,
      ]);
      $this
        ->standardTests();
      $this
        ->drupalGet('admin/reports/updates');
      $this
        ->clickLink('Check manually');
      $this
        ->checkForMetaRefresh();
      $assert_session
        ->pageTextNotContains('Security update required!');

      // The XML test fixtures for this method all contain the '8.x-3.0'
      // release but because '8.x-3.0' is not in a supported branch it will
      // not be in the available updates.
      $this
        ->assertNoRaw('8.x-3.0');

      // Set a CSS selector in order for assertions to target the 'Modules'
      // table and not Drupal core updates.
      $this->updateTableLocator = 'table.update:nth-of-type(2)';
      switch ($version) {
        case '1.1':

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

          // Both stable and unstable releases are available.
          // A stable release is the latest.
          if ($extra_version == '') {
            $assert_session
              ->elementTextNotContains('css', $this->updateTableLocator, 'Up to date');
            $assert_session
              ->elementTextContains('css', $this->updateTableLocator, 'Update available');
            $this
              ->assertVersionUpdateLinks('Recommended version:', $full_version);
            $assert_session
              ->elementTextNotContains('css', $this->updateTableLocator, 'Latest version:');
            $assert_session
              ->elementContains('css', $this->updateTableLocator, 'warning.svg');
          }
          else {
            $assert_session
              ->elementTextNotContains('css', $this->updateTableLocator, 'Up to date');
            $assert_session
              ->elementTextContains('css', $this->updateTableLocator, 'Update available');
            $this
              ->assertVersionUpdateLinks('Recommended version:', '8.x-1.1');
            $this
              ->assertVersionUpdateLinks('Latest version:', $full_version);
            $assert_session
              ->elementTextContains('css', $this->updateTableLocator, 'Latest version:');
            $assert_session
              ->elementContains('css', $this->updateTableLocator, 'warning.svg');
          }
          break;
        case '2.0':

          // When next major release (either stable or unstable) is available
          // and the current major is still supported, the next major will be
          // listed as "Also available".
          $assert_session
            ->elementTextNotContains('css', $this->updateTableLocator, 'Up to date');
          $assert_session
            ->elementTextContains('css', $this->updateTableLocator, 'Update available');
          $this
            ->assertVersionUpdateLinks('Recommended version', '8.x-1.2');
          $this
            ->assertVersionUpdateLinks('Also available', $full_version);
          $assert_session
            ->elementTextNotContains('css', $this->updateTableLocator, 'Latest version:');
          $assert_session
            ->elementContains('css', $this->updateTableLocator, 'warning.svg');
      }
    }
  }
}