diff -u b/core/modules/system/tests/modules/ajax_test/js/insert-ajax.js b/core/modules/system/tests/modules/ajax_test/js/insert-ajax.js --- b/core/modules/system/tests/modules/ajax_test/js/insert-ajax.js +++ b/core/modules/system/tests/modules/ajax_test/js/insert-ajax.js @@ -20,6 +20,8 @@ var myAjaxObject = Drupal.ajax(ajaxSettings); myAjaxObject.execute(); }); + + $(context).addClass('processed'); } }; })(jQuery, window, Drupal, drupalSettings); diff -u b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTest.php --- b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTest.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTest.php @@ -83,33 +83,41 @@ } /** - * Tests that various AJAX responses are correctly wrapped. + * Tests that various AJAX responses with DOM elements are correctly inserted. + * + * After inserting DOM elements, Drupal JavaScript behaviors should be + * reattached and all 'root' elements of type Node.ELEMENT_NODE need to be + * part of the context. */ - public function testWrap() { + public function testInsert() { $assert = $this->assertSession(); $this->drupalGet('ajax-test/insert'); // Test that no additional wrapper is added when inserting already wrapped - // response data. + // response data and all root node elements (context) are processed + // correctly. $this->clickLink('Link pre-wrapped'); $assert->assertWaitOnAjaxRequest(); - $assert->responseContains('
pre-wrapped
'); + $assert->responseContains('
pre-wrapped
'); // Test that no additional empty leading div is added when the return - // value had a leading space. + // value had a leading space and all root node elements (context) are + // processed correctly. $this->clickLink('Link pre-wrapped-leading-whitespace'); $assert->assertWaitOnAjaxRequest(); - $assert->responseContains('
pre-wrapped-leading-whitespace
'); + $assert->responseContains('
pre-wrapped-leading-whitespace
'); - // Test that unwrapped response data (text node) is inserted wrapped. + // Test that unwrapped response data (text node) is inserted wrapped and all + // root node elements (context) are processed correctly. $this->clickLink('Link not-wrapped'); $assert->assertWaitOnAjaxRequest(); - $assert->responseContains('
not-wrapped
'); + $assert->responseContains('
not-wrapped
'); - // Test that wrappend and unwrapped response data is inserted correctly. + // Test that wrappend and unwrapped response data is inserted correctly and + // all root node elements (context) are processed correctly. $this->clickLink('Link mixed'); $assert->assertWaitOnAjaxRequest(); - $assert->responseContains('
foo foo bar

some string

additional wrapped strings,

final string

'); + $assert->responseContains('
foo foo bar

some string

additional wrapped strings,

final string

'); } }