You are here

public function UpdateManagerUpdateTest::testIncompatibleUpdatesTable in Drupal 8

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

Tests the Update form for a single test scenario of incompatible updates.

@dataProvider incompatibleUpdatesTableProvider

Parameters

string $core_fixture: The fixture file to use for Drupal core.

string $a_fixture: The fixture file to use for the aaa_update_test module.

string $b_fixture: The fixture file to use for the bbb_update_test module.

string[] $compatible: Compatible recommended updates (if any). Keys are module identifier ('AAA' or 'BBB') and values are the expected recommended release.

string[][] $incompatible: Incompatible recommended updates (if any). Keys are module identifier ('AAA' or 'BBB') and values are subarrays with the following keys:

  • 'recommended': The recommended version.
  • 'range': The versions of Drupal core required for that version.

File

core/modules/update/tests/src/Functional/UpdateManagerUpdateTest.php, line 190

Class

UpdateManagerUpdateTest
Tests the Update Manager module's 'Update' form and functionality.

Namespace

Drupal\Tests\update\Functional

Code

public function testIncompatibleUpdatesTable($core_fixture, $a_fixture, $b_fixture, array $compatible, array $incompatible) {
  $assert_session = $this
    ->assertSession();
  $compatible_table_locator = '[data-drupal-selector="edit-projects"]';
  $incompatible_table_locator = '[data-drupal-selector="edit-not-compatible"]';
  $this
    ->refreshUpdateStatus([
    'drupal' => $core_fixture,
    'aaa_update_test' => $a_fixture,
    'bbb_update_test' => $b_fixture,
  ]);
  $this
    ->drupalGet('admin/reports/updates/update');
  if ($compatible) {

    // Verify the number of rows in the table.
    $assert_session
      ->elementsCount('css', "{$compatible_table_locator} tbody tr", count($compatible));

    // We never want to see a compatibility range in the compatible table.
    $assert_session
      ->elementTextNotContains('css', $compatible_table_locator, 'Requires Drupal core');
    foreach ($compatible as $module => $version) {
      $compatible_row = "{$compatible_table_locator} tbody tr:contains('{$module} Update test')";

      // First <td> is the checkbox, so start with td #2.
      $assert_session
        ->elementTextContains('css', "{$compatible_row} td:nth-of-type(2)", "{$module} Update test");

      // Both contrib modules use 8.x-1.0 as the currently installed version.
      $assert_session
        ->elementTextContains('css', "{$compatible_row} td:nth-of-type(3)", '8.x-1.0');
      $assert_session
        ->elementTextContains('css', "{$compatible_row} td:nth-of-type(4)", $version);
    }
  }
  else {

    // Verify there is no compatible updates table.
    $assert_session
      ->elementNotExists('css', $compatible_table_locator);
  }
  if ($incompatible) {

    // Verify the number of rows in the table.
    $assert_session
      ->elementsCount('css', "{$incompatible_table_locator} tbody tr", count($incompatible));
    foreach ($incompatible as $module => $data) {
      $incompatible_row = "{$incompatible_table_locator} tbody tr:contains('{$module} Update test')";
      $assert_session
        ->elementTextContains('css', "{$incompatible_row} td:nth-of-type(1)", "{$module} Update test");

      // Both contrib modules use 8.x-1.0 as the currently installed version.
      $assert_session
        ->elementTextContains('css', "{$incompatible_row} td:nth-of-type(2)", '8.x-1.0');
      $assert_session
        ->elementTextContains('css', "{$incompatible_row} td:nth-of-type(3)", $data['recommended']);
      $assert_session
        ->elementTextContains('css', "{$incompatible_row} td:nth-of-type(3)", 'Requires Drupal core: ' . $data['range']);
    }
  }
  else {

    // Verify there is no incompatible updates table.
    $assert_session
      ->elementNotExists('css', $incompatible_table_locator);
  }
}