AjaxInGroupTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace Drupal\FunctionalJavascriptTests\Ajax;
  3. use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
  4. /**
  5. * Tests that form elements in groups work correctly with AJAX.
  6. *
  7. * @group Ajax
  8. */
  9. class AjaxInGroupTest extends WebDriverTestBase {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. protected static $modules = ['ajax_forms_test'];
  14. /**
  15. * {@inheritdoc}
  16. */
  17. protected function setUp() {
  18. parent::setUp();
  19. $this->drupalLogin($this->drupalCreateUser(['access content']));
  20. }
  21. /**
  22. * Submits forms with select and checkbox elements via Ajax.
  23. */
  24. public function testSimpleAjaxFormValue() {
  25. $this->drupalGet('/ajax_forms_test_get_form');
  26. $assert_session = $this->assertSession();
  27. $assert_session->responseContains('Test group');
  28. $assert_session->responseContains('AJAX checkbox in a group');
  29. $session = $this->getSession();
  30. $checkbox_original = $session->getPage()->findField('checkbox_in_group');
  31. $this->assertNotNull($checkbox_original, 'The checkbox_in_group is on the page.');
  32. $original_id = $checkbox_original->getAttribute('id');
  33. // Triggers a AJAX request/response.
  34. $checkbox_original->check();
  35. // The response contains a new nested "test group" form element, similar
  36. // to the one already in the DOM except for a change in the form build id.
  37. $checkbox_new = $assert_session->waitForElement('xpath', "//input[@name='checkbox_in_group' and not(@id='$original_id')]");
  38. $this->assertNotNull($checkbox_new, 'DOM update: clicking the checkbox refreshed the checkbox_in_group structure');
  39. $assert_session->responseContains('Test group');
  40. $assert_session->responseContains('AJAX checkbox in a group');
  41. $assert_session->responseContains('AJAX checkbox in a nested group');
  42. $assert_session->responseContains('Another AJAX checkbox in a nested group');
  43. }
  44. }