You are here

public function AjaxFormCacheTest::testQueryString in Drupal 8

Same name and namespace in other branches
  1. 9 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 87

Class

AjaxFormCacheTest
Tests the usage of form caching for AJAX forms.

Namespace

Drupal\FunctionalJavascriptTests\Ajax

Code

public function testQueryString() {
  $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',
    FormBuilderInterface::AJAX_FORM_REQUEST => 1,
    MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax',
  ]);
  $this
    ->assertUrl($url);
}