function BlockExposedFilterAJAXTest::testExposedFilteringAndReset

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/FunctionalJavascript/BlockExposedFilterAJAXTest.php \Drupal\Tests\views\FunctionalJavascript\BlockExposedFilterAJAXTest::testExposedFilteringAndReset()
  2. 10 core/modules/views/tests/src/FunctionalJavascript/BlockExposedFilterAJAXTest.php \Drupal\Tests\views\FunctionalJavascript\BlockExposedFilterAJAXTest::testExposedFilteringAndReset()
  3. 11.x 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',
    ], t('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([], t('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',
    ], t('Apply'));
    $this->assertSession()
        ->waitForElementRemoved('xpath', '//*[text()="Article A"]');
    $this->submitForm([], t('Reset'));
    $this->assertSession()
        ->addressEquals('some-path');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.