3 namespace Drupal\FunctionalJavascriptTests\Ajax;
5 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
8 * Tests that form elements in groups work correctly with AJAX.
12 class AjaxInGroupTest extends WebDriverTestBase {
17 protected static $modules = ['ajax_forms_test'];
22 protected function setUp() {
25 $this->drupalLogin($this->drupalCreateUser(['access content']));
29 * Submits forms with select and checkbox elements via Ajax.
31 public function testSimpleAjaxFormValue() {
32 $this->drupalGet('/ajax_forms_test_get_form');
34 $assert_session = $this->assertSession();
35 $assert_session->responseContains('Test group');
36 $assert_session->responseContains('AJAX checkbox in a group');
38 $session = $this->getSession();
39 $checkbox_original = $session->getPage()->findField('checkbox_in_group');
40 $this->assertNotNull($checkbox_original, 'The checkbox_in_group is on the page.');
41 $original_id = $checkbox_original->getAttribute('id');
43 // Triggers a AJAX request/response.
44 $checkbox_original->check();
46 // The response contains a new nested "test group" form element, similar
47 // to the one already in the DOM except for a change in the form build id.
48 $checkbox_new = $assert_session->waitForElement('xpath', "//input[@name='checkbox_in_group' and not(@id='$original_id')]");
49 $this->assertNotNull($checkbox_new, 'DOM update: clicking the checkbox refreshed the checkbox_in_group structure');
51 $assert_session->responseContains('Test group');
52 $assert_session->responseContains('AJAX checkbox in a group');
53 $assert_session->responseContains('AJAX checkbox in a nested group');
54 $assert_session->responseContains('Another AJAX checkbox in a nested group');