function ExposedFilterAJAXTest::testExposedFilteringWithButtonElement

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/FunctionalJavascript/ExposedFilterAJAXTest.php \Drupal\Tests\views\FunctionalJavascript\ExposedFilterAJAXTest::testExposedFilteringWithButtonElement()
  2. 10 core/modules/views/tests/src/FunctionalJavascript/ExposedFilterAJAXTest.php \Drupal\Tests\views\FunctionalJavascript\ExposedFilterAJAXTest::testExposedFilteringWithButtonElement()

Tests exposed filtering via AJAX with a button element.

File

core/modules/views/tests/src/FunctionalJavascript/ExposedFilterAJAXTest.php, line 200

Class

ExposedFilterAJAXTest
Tests the basic AJAX functionality of Views exposed forms.

Namespace

Drupal\Tests\views\FunctionalJavascript

Code

public function testExposedFilteringWithButtonElement() : void {
    // Install theme to test with template system.
    \Drupal::service('theme_installer')->install([
        'views_test_theme',
    ]);
    // Make base theme default then test for hook invocations.
    $this->config('system.theme')
        ->set('default', 'views_test_theme')
        ->save();
    $this->drupalGet('admin/content');
    $session = $this->getSession();
    // Ensure that the Content we're testing for is present.
    $html = $session->getPage()
        ->getHtml();
    $this->assertStringContainsString('Page One', $html);
    $this->assertStringContainsString('Page Two', $html);
    $button_tag = $session->getPage()
        ->findButton('edit-submit-content')
        ->getTagName();
    // Make sure the submit button has been transformed to a button element.
    $this->assertEquals('button', $button_tag);
    $drupal_settings = $this->getDrupalSettings();
    $ajax_views_before = $drupal_settings['views']['ajaxViews'];
    // Search for "Page One".
    $this->submitForm([
        'title' => 'Page One',
    ], 'Filter');
    $this->assertSession()
        ->assertWaitOnAjaxRequest();
    // Verify that only the "Page One" Node is present.
    $html = $session->getPage()
        ->getHtml();
    $this->assertStringContainsString('Page One', $html);
    $this->assertStringNotContainsString('Page Two', $html);
    $drupal_settings = $this->getDrupalSettings();
    $ajax_views_after = $drupal_settings['views']['ajaxViews'];
    // Make sure that the views_dom_id didn't change, which would indicate that
    // the page reloaded instead of doing an AJAX update.
    $this->assertSame($ajax_views_before, $ajax_views_after);
}

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