diff --git a/core/modules/system/tests/modules/test_page_test/js/test_javascript.js b/core/modules/system/tests/modules/test_page_test/js/test_javascript.js new file mode 100644 index 0000000000..b0150cf953 --- /dev/null +++ b/core/modules/system/tests/modules/test_page_test/js/test_javascript.js @@ -0,0 +1,14 @@ +(function ($, Drupal, settings) { + Drupal.behaviors.testJavascriptBehaviour = { + attach: function attach(context) { + // Does some interaction stuff. + const $link = $('a.testLink'); + $link.click(function(e) { + e.preventDefault(); + $.get(settings.basePath, function(result) { + $link.append('Hallo welt'); + }); + }); + } + } +})(jQuery, Drupal, drupalSettings); diff --git a/core/modules/system/tests/modules/test_page_test/src/Controller/Test.php b/core/modules/system/tests/modules/test_page_test/src/Controller/Test.php index e754eaf0c2..27a395f5bd 100644 --- a/core/modules/system/tests/modules/test_page_test/src/Controller/Test.php +++ b/core/modules/system/tests/modules/test_page_test/src/Controller/Test.php @@ -123,4 +123,13 @@ public function metaRefresh() { return new RedirectResponse(Url::fromRoute('test_page_test.test_page', [], ['absolute' => TRUE])->toString(), 302); } + /** + * Embeds some JS which says "Hallo welt". + */ + public function testJavascript() { + $build['#markup'] = 'click here'; + $build['#attached']['library'][] = 'test_page_test/test_javascript'; + return $build; + } + } diff --git a/core/modules/system/tests/modules/test_page_test/test_page_test.libraries.yml b/core/modules/system/tests/modules/test_page_test/test_page_test.libraries.yml new file mode 100644 index 0000000000..00f6c8cd9d --- /dev/null +++ b/core/modules/system/tests/modules/test_page_test/test_page_test.libraries.yml @@ -0,0 +1,8 @@ +test_javascript: + js: + js/test_javascript.js: {} + dependencies: + - core/jquery + - core/drupal + - core/drupalSettings + diff --git a/core/modules/system/tests/modules/test_page_test/test_page_test.routing.yml b/core/modules/system/tests/modules/test_page_test/test_page_test.routing.yml index e64a88d003..ea7c1e39f7 100644 --- a/core/modules/system/tests/modules/test_page_test/test_page_test.routing.yml +++ b/core/modules/system/tests/modules/test_page_test/test_page_test.routing.yml @@ -90,3 +90,10 @@ test_page_test.meta_refresh: _controller: '\Drupal\test_page_test\Controller\Test::metaRefresh' requirements: _access: 'TRUE' + +test_page_test.test_javascript: + path: '/test-javascript' + defaults: + _controller: '\Drupal\test_page_test\Controller\Test::testJavascript' + requirements: + _access: 'TRUE' diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Tests/JavascriptTestBaseTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Tests/JavascriptTestBaseTest.php index 57acc02992..b02ad6793c 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/Tests/JavascriptTestBaseTest.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/Tests/JavascriptTestBaseTest.php @@ -11,6 +11,11 @@ */ class JavascriptTestBaseTest extends JavascriptTestBase { + /** + * {@inheritdoc} + */ + public static $modules = ['test_page_test']; + /** * @covers ::markCurrentPage * @covers ::assertPageReloaded @@ -28,9 +33,13 @@ public function testAssertPageReloaded() { * @covers ::assertPageNotReloaded */ public function testAssertPageNotReloaded() { - $this->drupalGet(''); + $this->drupalGet('test-javascript'); $this->markCurrentPage(); + $this->assertSession()->pageTextNotContains('Hallo welt'); + + $this->clickLink('click here'); $this->assertPageNotReloaded(); + $this->assertSession()->pageTextContains('Hallo welt'); } }