You are here

protected function AreaDisplayLinkTest::assertRenderedDisplayLinks in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Kernel/Handler/AreaDisplayLinkTest.php \Drupal\Tests\views\Kernel\Handler\AreaDisplayLinkTest::assertRenderedDisplayLinks()
  2. 9 core/modules/views/tests/src/Kernel/Handler/AreaDisplayLinkTest.php \Drupal\Tests\views\Kernel\Handler\AreaDisplayLinkTest::assertRenderedDisplayLinks()

Assert the display links are correctly rendered for a display.

@internal

Parameters

\Drupal\views\ViewExecutable $view: The view to check.

string $display_id: The display ID to check the links for.

File

core/modules/views/tests/src/Kernel/Handler/AreaDisplayLinkTest.php, line 327

Class

AreaDisplayLinkTest
Tests the core views_handler_area_display_link handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

protected function assertRenderedDisplayLinks(ViewExecutable $view, string $display_id) : void {
  $page_1_active = $display_id === 'page_1' ? ' is-active' : '';
  $page_2_active = $display_id === 'page_2' ? ' is-active' : '';
  $view
    ->destroy();
  $view
    ->setDisplay($display_id);
  $this
    ->executeView($view);
  $this
    ->assertSame('<a href="/page_1" class="views-display-link views-display-link-page_1' . $page_1_active . '">Page 1</a>', $this
    ->renderDisplayLink($view, 'display_link_1'));
  $this
    ->assertSame('<a href="/page_2" class="views-display-link views-display-link-page_2' . $page_2_active . '">Page 2</a>', $this
    ->renderDisplayLink($view, 'display_link_2'));

  // Assert the exposed filters, pager and contextual links are passed
  // correctly in the links.
  $view
    ->destroy();
  $view
    ->setDisplay($display_id);
  $view
    ->setExposedInput([
    'name' => 'John',
    'sort_by' => 'created',
    'sort_order' => 'ASC',
  ]);
  $view
    ->setCurrentPage(2);
  $this
    ->executeView($view, [
    1,
  ]);
  $this
    ->assertSame('<a href="/page_1/1?name=John&amp;sort_by=created&amp;sort_order=ASC&amp;page=1" class="views-display-link views-display-link-page_1' . $page_1_active . '">Page 1</a>', $this
    ->renderDisplayLink($view, 'display_link_1'));
  $this
    ->assertSame('<a href="/page_2/1?name=John&amp;sort_by=created&amp;sort_order=ASC&amp;page=1" class="views-display-link views-display-link-page_2' . $page_2_active . '">Page 2</a>', $this
    ->renderDisplayLink($view, 'display_link_2'));
}