You are here

protected function SearchMultilingualEntityTest::assertIndexCounts in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/search/tests/src/Functional/SearchMultilingualEntityTest.php \Drupal\Tests\search\Functional\SearchMultilingualEntityTest::assertIndexCounts()
  2. 9 core/modules/search/tests/src/Functional/SearchMultilingualEntityTest.php \Drupal\Tests\search\Functional\SearchMultilingualEntityTest::assertIndexCounts()

Verifies the indexing status counts.

@internal

Parameters

int $remaining: Count of remaining items to verify.

int $total: Count of total items to verify.

string $message: Message to use, something like "after updating the search index".

File

core/modules/search/tests/src/Functional/SearchMultilingualEntityTest.php, line 290

Class

SearchMultilingualEntityTest
Tests entities with multilingual fields.

Namespace

Drupal\Tests\search\Functional

Code

protected function assertIndexCounts(int $remaining, int $total, string $message) : void {

  // Check status via plugin method call.
  $status = $this->plugin
    ->indexStatus();
  $this
    ->assertEquals($remaining, $status['remaining'], 'Remaining items ' . $message . ' is ' . $remaining);
  $this
    ->assertEquals($total, $status['total'], 'Total items ' . $message . ' is ' . $total);

  // Check text in progress section of Search settings page. Note that this
  // test avoids using
  // \Drupal\Core\StringTranslation\TranslationInterface::formatPlural(), so
  // it tests for fragments of text.
  $indexed = $total - $remaining;
  $percent = $total > 0 ? floor(100 * $indexed / $total) : 100;
  $this
    ->drupalGet('admin/config/search/pages');
  $this
    ->assertSession()
    ->pageTextContains($percent . '% of the site has been indexed.');
  $this
    ->assertSession()
    ->pageTextContains($remaining . ' item');

  // Check text in pages section of Search settings page.
  $this
    ->assertSession()
    ->pageTextContains($indexed . ' of ' . $total . ' indexed');

  // Check text on status report page.
  $this
    ->drupalGet('admin/reports/status');
  $this
    ->assertSession()
    ->pageTextContains('Search index progress');
  $this
    ->assertSession()
    ->pageTextContains($percent . '%');
  $this
    ->assertSession()
    ->pageTextContains('(' . $remaining . ' remaining)');
}