public function ExposedFilterAJAXTest::testExposedFilteringWithButtonElement in Drupal 9
Tests exposed filtering via AJAX with a button element.
File
- core/
modules/ views/ tests/ src/ FunctionalJavascript/ ExposedFilterAJAXTest.php, line 157
Class
- ExposedFilterAJAXTest
- Tests the basic AJAX functionality of Views exposed forms.
Namespace
Drupal\Tests\views\FunctionalJavascriptCode
public function testExposedFilteringWithButtonElement() {
// 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',
], t('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);
}