diff --git a/core/modules/system/src/Tests/Ajax/AjaxInGroupTest.php b/core/modules/system/src/Tests/Ajax/AjaxInGroupTest.php deleted file mode 100644 index 4116f5f892..0000000000 --- a/core/modules/system/src/Tests/Ajax/AjaxInGroupTest.php +++ /dev/null @@ -1,32 +0,0 @@ -drupalLogin($this->drupalCreateUser(['access content'])); - } - - /** - * Submits forms with select and checkbox elements via Ajax. - */ - public function testSimpleAjaxFormValue() { - $this->drupalGet('/ajax_forms_test_get_form'); - $this->assertText('Test group'); - $this->assertText('AJAX checkbox in a group'); - - $this->drupalPostAjaxForm(NULL, ['checkbox_in_group' => TRUE], 'checkbox_in_group'); - $this->assertText('Test group'); - $this->assertText('AJAX checkbox in a group'); - $this->assertText('AJAX checkbox in a nested group'); - $this->assertText('Another AJAX checkbox in a nested group'); - } - -} diff --git a/core/modules/system/src/Tests/Ajax/AjaxTestBase.php b/core/modules/system/src/Tests/Ajax/AjaxTestBase.php index 66e06c88a4..859bbbed41 100644 --- a/core/modules/system/src/Tests/Ajax/AjaxTestBase.php +++ b/core/modules/system/src/Tests/Ajax/AjaxTestBase.php @@ -2,10 +2,16 @@ namespace Drupal\system\Tests\Ajax; +@trigger_error(__FILE__ . ' is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. See https://www.drupal.org/node/2862510'); + use Drupal\simpletest\WebTestBase; /** * Provides a base class for Ajax tests. + * + * @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. + * + * @see https://www.drupal.org/node/2862510 */ abstract class AjaxTestBase extends WebTestBase { diff --git a/core/modules/system/src/Tests/Ajax/ElementValidationTest.php b/core/modules/system/src/Tests/Ajax/ElementValidationTest.php deleted file mode 100644 index d20f453be4..0000000000 --- a/core/modules/system/src/Tests/Ajax/ElementValidationTest.php +++ /dev/null @@ -1,38 +0,0 @@ - t('some dumb text')]; - - // Post with 'drivertext' as the triggering element. - $this->drupalPostAjaxForm('ajax_validation_test', $edit, 'drivertext'); - // Look for a validation failure in the resultant JSON. - $this->assertNoText(t('Error message'), 'No error message in resultant JSON'); - $this->assertText('ajax_forms_test_validation_form_callback invoked', 'The correct callback was invoked'); - - $this->drupalGet('ajax_validation_test'); - $edit = ['drivernumber' => 12345]; - - // Post with 'drivernumber' as the triggering element. - $this->drupalPostAjaxForm('ajax_validation_test', $edit, 'drivernumber'); - // Look for a validation failure in the resultant JSON. - $this->assertNoText(t('Error message'), 'No error message in resultant JSON'); - $this->assertText('ajax_forms_test_validation_number_form_callback invoked', 'The correct callback was invoked'); - } - -} diff --git a/core/modules/system/src/Tests/Ajax/AjaxFormCacheTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormCacheTest.php similarity index 54% rename from core/modules/system/src/Tests/Ajax/AjaxFormCacheTest.php rename to core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormCacheTest.php index 11a4044e07..2f36e0d48d 100644 --- a/core/modules/system/src/Tests/Ajax/AjaxFormCacheTest.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormCacheTest.php @@ -1,17 +1,25 @@ drupalPlaceBlock('ajax_forms_test_block'); $this->drupalGet(''); - $this->drupalPostAjaxForm(NULL, ['test1' => 'option1'], 'test1'); - $this->assertOptionSelectedWithDrupalSelector('edit-test1', 'option1'); - $this->assertOptionWithDrupalSelector('edit-test1', 'option3'); - $this->drupalPostForm(NULL, ['test1' => 'option1'], 'Submit'); - $this->assertText('Submission successful.'); + $session = $this->getSession(); + + // Select first option and trigger ajax update. + $session->getPage()->selectFieldOption('edit-test1', 'option1'); + + // Wait for 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.'); } /** @@ -65,7 +90,16 @@ public function testQueryString() { $url = Url::fromRoute('entity.user.canonical', ['user' => $this->rootUser->id()], ['query' => ['foo' => 'bar']]); $this->drupalGet($url); - $this->drupalPostAjaxForm(NULL, ['test1' => 'option1'], 'test1'); + + $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, diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxInGroupTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxInGroupTest.php new file mode 100644 index 0000000000..621e113ac6 --- /dev/null +++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxInGroupTest.php @@ -0,0 +1,50 @@ +drupalLogin($this->drupalCreateUser(['access content'])); + } + + /** + * Submits forms with select and checkbox elements via Ajax. + */ + public function testSimpleAjaxFormValue() { + $this->drupalGet('/ajax_forms_test_get_form'); + $this->assertText('Test group'); + $this->assertText('AJAX checkbox in a group'); + + $session = $this->getSession(); + $checkbox_original = $session->getPage()->findField('checkbox_in_group'); + $this->assertNotNull($checkbox_original, 'The checkbox_in_group is on the page.'); + $original_id = $checkbox_original->getAttribute('id'); + + // Triggers a AJAX request/response. + $checkbox_original->check(); + + // The reponse contains a new nested "test group" form element, similar + // to the one already in the DOM except for a change in the form build id. + $checkbox_new = $this->assertSession()->waitForElement('xpath', "//input[@name='checkbox_in_group' and not(@id='$original_id')]"); + $this->assertNotNull($checkbox_new, 'DOM update: clicking the checkbox refreshed the checkbox_in_group structure'); + + $this->assertText('Test group'); + $this->assertText('AJAX checkbox in a group'); + $this->assertText('AJAX checkbox in a nested group'); + $this->assertText('Another AJAX checkbox in a nested group'); + } + +} diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTestBase.php b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTestBase.php new file mode 100644 index 0000000000..908864c03c --- /dev/null +++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTestBase.php @@ -0,0 +1,63 @@ +assertTrue($found, $message); + } + +} diff --git a/core/modules/system/src/Tests/Ajax/DialogTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/DialogTest.php similarity index 99% rename from core/modules/system/src/Tests/Ajax/DialogTest.php rename to core/tests/Drupal/FunctionalJavascriptTests/Ajax/DialogTest.php index ec947825fe..258b9f68f4 100644 --- a/core/modules/system/src/Tests/Ajax/DialogTest.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/DialogTest.php @@ -1,6 +1,6 @@ drupalGet('ajax_validation_test'); + + // Partially complete the form with a string. + $this->getSession()->getPage()->fillField('drivertext', 'some dumb text'); + + // When the AJAX command updates the DOM a