You are here

public function LinksSortWidgetKernelTest::testExposedLinks in Better Exposed Filters 8.4

Same name and namespace in other branches
  1. 8.5 tests/src/Kernel/Plugin/sort/LinksSortWidgetKernelTest.php \Drupal\Tests\better_exposed_filters\Kernel\Plugin\sort\LinksSortWidgetKernelTest::testExposedLinks()

Tests the exposed links sort widget.

File

tests/src/Kernel/Plugin/sort/LinksSortWidgetKernelTest.php, line 25

Class

LinksSortWidgetKernelTest
Tests the links sort widget (i.e. "bef_links").

Namespace

Drupal\Tests\better_exposed_filters\Kernel\Plugin\sort

Code

public function testExposedLinks() {
  $view = Views::getView('bef_test');
  $display =& $view->storage
    ->getDisplay('default');

  // Change exposed sort to links (i.e. 'bef_links').
  $this
    ->setBetterExposedOptions($view, [
    'sort' => [
      'plugin_id' => 'bef_links',
    ],
  ]);

  // Render the exposed form.
  $this
    ->renderExposedForm($view);

  // Check our sort item "sort_by" is rendered as links.
  $actual = $this
    ->xpath('//form//a[starts-with(@id, "edit-sort-by")]');
  $this
    ->assertCount(1, $actual, 'Exposed sort "sort_by" has correct number of exposed links.');

  // Check our sort item "sort_order" is rendered as links.
  $actual = $this
    ->xpath('//form//a[starts-with(@id, "edit-sort-order")]');
  $this
    ->assertCount(2, $actual, 'Exposed sort "sort_order" has correct number of exposed links.');
  $view
    ->destroy();
}