You are here

protected function NodeFieldFilterTest::assertPageCounts in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/node/tests/src/Functional/Views/NodeFieldFilterTest.php \Drupal\Tests\node\Functional\Views\NodeFieldFilterTest::assertPageCounts()

Asserts that the given node translation counts are correct.

Parameters

string $path: Path of the page to test.

array $counts: Array whose keys are languages, and values are the number of times that translation should be shown on the given page.

string $message: Message suffix to display.

1 call to NodeFieldFilterTest::assertPageCounts()
NodeFieldFilterTest::testFilters in core/modules/node/tests/src/Functional/Views/NodeFieldFilterTest.php
Tests body and title filters.

File

core/modules/node/tests/src/Functional/Views/NodeFieldFilterTest.php, line 101

Class

NodeFieldFilterTest
Tests node field filters with translations.

Namespace

Drupal\Tests\node\Functional\Views

Code

protected function assertPageCounts($path, $counts, $message) {

  // Disable read more links.
  \Drupal::service('entity_display.repository')
    ->getViewDisplay('node', 'page', 'teaser')
    ->removeComponent('links')
    ->save();

  // Get the text of the page.
  $this
    ->drupalGet($path);
  $text = $this
    ->getTextContent();

  // Check the counts. Note that the title and body are both shown on the
  // page, and they are the same. So the title/body string should appear on
  // the page twice as many times as the input count.
  foreach ($counts as $langcode => $count) {
    $this
      ->assertEqual(substr_count($text, $this->nodeTitles[$langcode]), 2 * $count, 'Translation ' . $langcode . ' has count ' . $count . ' with ' . $message);
  }
}