diff --git a/core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php b/core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php index 28e565c5ef..9b6a9e2cef 100644 --- a/core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php +++ b/core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php @@ -65,6 +65,9 @@ public function renderTypes($type) { /** * Returns a render array of links that directly Drupal.ajax(). + * + * @return array + * Renderable array of AJAX response contents. */ public function insertLinksBlockWrapper() { $methods = [ @@ -74,7 +77,7 @@ public function insertLinksBlockWrapper() { $build['links'] = [ 'ajax_target' => [ - '#markup' => '
Target
', + '#markup' => '
Target
', ], 'links' => [ '#theme' => 'links', @@ -99,6 +102,9 @@ public function insertLinksBlockWrapper() { /** * Returns a render array of links that directly Drupal.ajax(). + * + * @return array + * Renderable array of AJAX response contents. */ public function insertLinksInlineWrapper() { $methods = [ @@ -108,7 +114,7 @@ public function insertLinksInlineWrapper() { $build['links'] = [ 'ajax_target' => [ - '#markup' => 'Target inline', + '#markup' => '
Target inline
', ], 'links' => [ '#theme' => 'links', @@ -130,6 +136,7 @@ public function insertLinksInlineWrapper() { } return $build; } + /** * Returns a render array that will be rendered by AjaxRenderer. * @@ -329,6 +336,7 @@ protected function getRenderTypes() { 'top-level-only-pre-whitespace' => '
element #1
element #2
', 'top-level-only-middle-whitespace-span' => 'element #1 element #2', 'top-level-only-middle-whitespace-div' => '
element #1
element #2
', + 'svg' => '', 'empty' => '', ]; } diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTest.php index 7a8895c9f6..82d63d4099 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTest.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTest.php @@ -2,6 +2,7 @@ namespace Drupal\FunctionalJavascriptTests\Ajax; +use Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver; use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** @@ -11,30 +12,13 @@ */ class AjaxTest extends JavascriptTestBase { + protected $minkDefaultDriverClass = DrupalSelenium2Driver::class; + /** * {@inheritdoc} */ public static $modules = ['ajax_test']; - /** - * Wraps HTML with an AJAX target element. - * - * This reproduces recognizable parts of the wrapping markup from - * \Drupal\ajax_test\Controller\AjaxTestController::insertLinks and is not - * supposed to return valid HTML. - * - * @param string $html - * The HTML to wrap. - * - * @return string - * The HTML wrapped in the an AJAX target element. - * - * @see \Drupal\ajax_test\Controller\AjaxTestController::insertLinks - */ - protected function wrapAjaxTarget($html) { - return 'data-drupal-ajax-target="">' . $html . 'install(['stable', 'seven']); $theme_config = \Drupal::configFactory()->getEditable('system.theme'); @@ -111,19 +95,13 @@ public function testDrupalSettingsCachingRegression() { * @dataProvider providerTestInsert */ public function testInsertBlock($render_type, $expected) { - $assert = $this->assertSession(); - $this->drupalGet('ajax-test/insert-block-wrapper'); $this->clickLink("Link html $render_type"); - $assert->assertWaitOnAjaxRequest(); - // Extra span added by a second prepend command on the ajax requests. - $assert->responseContains($this->wrapAjaxTarget($expected)); + $this->assertWaitPageContains('
' . $expected . '
'); $this->drupalGet('ajax-test/insert-block-wrapper'); $this->clickLink("Link replaceWith $render_type"); - $assert->assertWaitOnAjaxRequest(); - $assert->responseContains($expected); - $assert->responseNotContains($this->wrapAjaxTarget($expected)); + $this->assertWaitPageContains('
' . $expected . '
'); } /** @@ -136,19 +114,13 @@ public function testInsertBlock($render_type, $expected) { * @dataProvider providerTestInsert */ public function testInsertInline($render_type, $expected) { - $assert = $this->assertSession(); - $this->drupalGet('ajax-test/insert-inline-wrapper'); $this->clickLink("Link html $render_type"); - $assert->assertWaitOnAjaxRequest(); - // Extra span added by a second prepend command on the ajax requests. - $assert->responseContains($this->wrapAjaxTarget($expected)); + $this->assertWaitPageContains('
' . $expected . '
'); $this->drupalGet('ajax-test/insert-inline-wrapper'); $this->clickLink("Link replaceWith $render_type"); - $assert->assertWaitOnAjaxRequest(); - $assert->responseContains($expected); - $assert->responseNotContains($this->wrapAjaxTarget($expected)); + $this->assertWaitPageContains('
' . $expected . '
'); } /** @@ -222,6 +194,11 @@ public function providerTestInsert() { 'top-level-only-middle-whitespace-span', 'element #1 element #2', ]; + // Test svg. + $test_cases['svg'] = [ + 'svg', + '', + ]; // Test that empty response data. $test_cases['empty'] = [ 'empty', @@ -231,4 +208,18 @@ public function providerTestInsert() { return $test_cases; } + /** + * Asserts that page contains a text after waiting. + * + * @param string $text + * A needle text. + */ + protected function assertWaitPageContains($text) { + $page = $this->getSession()->getPage(); + $page->waitFor(10, function () use ($page, $text) { + return stripos($page->getContent(), $text) !== FALSE; + }); + $this->assertContains($text, $page->getContent()); + } + }