public function AjaxFormCacheTest::testBlockForms in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormCacheTest.php \Drupal\FunctionalJavascriptTests\Ajax\AjaxFormCacheTest::testBlockForms()
- 10 core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormCacheTest.php \Drupal\FunctionalJavascriptTests\Ajax\AjaxFormCacheTest::testBlockForms()
Tests AJAX forms in blocks.
File
- core/
tests/ Drupal/ FunctionalJavascriptTests/ Ajax/ AjaxFormCacheTest.php, line 51
Class
- AjaxFormCacheTest
- Tests the usage of form caching for AJAX forms.
Namespace
Drupal\FunctionalJavascriptTests\AjaxCode
public function testBlockForms() {
$this->container
->get('module_installer')
->install([
'block',
'search',
]);
$this
->rebuildContainer();
$this->container
->get('router.builder')
->rebuild();
$this
->drupalLogin($this->rootUser);
$this
->drupalPlaceBlock('search_form_block', [
'weight' => -5,
]);
$this
->drupalPlaceBlock('ajax_forms_test_block');
$this
->drupalGet('');
$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', "select[data-drupal-selector='edit-test1'] option:contains('Option 1!!!')");
$this
->assertNotEmpty($opt1_selector);
$this
->assertTrue($opt1_selector
->isSelected());
// Confirm option 3 exists.
$page = $session
->getPage();
$opt3_selector = $page
->find('xpath', '//select[@data-drupal-selector="edit-test1"]//option[@value="option3"]');
$this
->assertNotEmpty($opt3_selector);
// Confirm success message appears after a submit.
$page
->findButton('edit-submit')
->click();
$this
->assertSession()
->waitForButton('edit-submit');
$updated_page = $session
->getPage();
$updated_page
->hasContent('Submission successful.');
}