You are here

public function BlockExposedFilterAJAXTest::testExposedFilteringAndReset in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/FunctionalJavascript/BlockExposedFilterAJAXTest.php \Drupal\Tests\views\FunctionalJavascript\BlockExposedFilterAJAXTest::testExposedFilteringAndReset()

Tests if exposed filtering and reset works with a views block and ajax.

File

core/modules/views/tests/src/FunctionalJavascript/BlockExposedFilterAJAXTest.php, line 52

Class

BlockExposedFilterAJAXTest
Tests the exposed filter ajax functionality in a block.

Namespace

Drupal\Tests\views\FunctionalJavascript

Code

public function testExposedFilteringAndReset() {
  $node = $this
    ->createNode();
  $block = $this
    ->drupalPlaceBlock('views_block:test_block_exposed_ajax-block_1');
  $this
    ->drupalGet($node
    ->toUrl());
  $page = $this
    ->getSession()
    ->getPage();

  // Ensure that the Content we're testing for is present.
  $html = $page
    ->getHtml();
  $this
    ->assertStringContainsString('Page A', $html);
  $this
    ->assertStringContainsString('Page B', $html);
  $this
    ->assertStringContainsString('Article A', $html);

  // Filter by page type.
  $this
    ->submitForm([
    'type' => 'page',
  ], 'Apply');
  $this
    ->assertSession()
    ->waitForElementRemoved('xpath', '//*[text()="Article A"]');

  // Verify that only the page nodes are present.
  $html = $page
    ->getHtml();
  $this
    ->assertStringContainsString('Page A', $html);
  $this
    ->assertStringContainsString('Page B', $html);
  $this
    ->assertStringNotContainsString('Article A', $html);

  // Reset the form.
  $this
    ->submitForm([], 'Reset');

  // Assert we are still on the node page.
  $html = $page
    ->getHtml();

  // Repeat the original tests.
  $this
    ->assertStringContainsString('Page A', $html);
  $this
    ->assertStringContainsString('Page B', $html);
  $this
    ->assertStringContainsString('Article A', $html);
  $this
    ->assertSession()
    ->addressEquals('node/' . $node
    ->id());
  $block
    ->delete();

  // Do the same test with a block that has a page display to test the user
  // is redirected to the page display.
  $this
    ->drupalPlaceBlock('views_block:test_block_exposed_ajax_with_page-block_1');
  $this
    ->drupalGet($node
    ->toUrl());
  $this
    ->submitForm([
    'type' => 'page',
  ], 'Apply');
  $this
    ->assertSession()
    ->waitForElementRemoved('xpath', '//*[text()="Article A"]');
  $this
    ->submitForm([], 'Reset');
  $this
    ->assertSession()
    ->addressEquals('some-path');
}