function AjaxFormCacheTest::testQueryString

Same name in other branches
  1. 9 core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormCacheTest.php \Drupal\FunctionalJavascriptTests\Ajax\AjaxFormCacheTest::testQueryString()
  2. 8.9.x core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormCacheTest.php \Drupal\FunctionalJavascriptTests\Ajax\AjaxFormCacheTest::testQueryString()
  3. 11.x core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormCacheTest.php \Drupal\FunctionalJavascriptTests\Ajax\AjaxFormCacheTest::testQueryString()

Tests AJAX forms on pages with a query string.

File

core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormCacheTest.php, line 86

Class

AjaxFormCacheTest
Tests the usage of form caching for AJAX forms.

Namespace

Drupal\FunctionalJavascriptTests\Ajax

Code

public function testQueryString() : void {
    $this->container
        ->get('module_installer')
        ->install([
        'block',
    ]);
    $this->drupalLogin($this->rootUser);
    $this->drupalPlaceBlock('ajax_forms_test_block');
    $url = Url::fromRoute('entity.user.canonical', [
        'user' => $this->rootUser
            ->id(),
    ], [
        'query' => [
            'foo' => 'bar',
        ],
    ]);
    $this->drupalGet($url);
    $session = $this->getSession();
    // Select first option and trigger ajax update.
    $session->getPage()
        ->selectFieldOption('edit-test1', 'option1');
    // DOM update: The InsertCommand in the AJAX response changes the text
    // in the option element to 'Option1!!!'.
    $opt1_selector = $this->assertSession()
        ->waitForElement('css', "option:contains('Option 1!!!')");
    $this->assertNotEmpty($opt1_selector);
    $url->setOption('query', [
        'foo' => 'bar',
    ]);
    $this->assertSession()
        ->addressEquals($url);
}

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