X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fsystem%2Ftests%2Fsrc%2FFunctional%2FCommon%2FNoJavaScriptAnonymousTest.php;fp=web%2Fcore%2Fmodules%2Fsystem%2Ftests%2Fsrc%2FFunctional%2FCommon%2FNoJavaScriptAnonymousTest.php;h=2be4d79ad5414ceca978f5c29ddd53661b88a984;hp=0000000000000000000000000000000000000000;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/modules/system/tests/src/Functional/Common/NoJavaScriptAnonymousTest.php b/web/core/modules/system/tests/src/Functional/Common/NoJavaScriptAnonymousTest.php new file mode 100644 index 000000000..2be4d79ad --- /dev/null +++ b/web/core/modules/system/tests/src/Functional/Common/NoJavaScriptAnonymousTest.php @@ -0,0 +1,67 @@ +drupalCreateNode([ + 'promote' => NodeInterface::PROMOTED, + ]); + $user = $this->drupalCreateUser(); + + // Test frontpage. + $this->drupalGet(''); + $this->assertNoJavaScriptExceptHtml5Shiv(); + + // Test node page. + $this->drupalGet('node/1'); + $this->assertNoJavaScriptExceptHtml5Shiv(); + + // Test user profile page. + $this->drupalGet('user/' . $user->id()); + $this->assertNoJavaScriptExceptHtml5Shiv(); + } + + /** + * Passes if no JavaScript is found on the page except the HTML5 shiv. + * + * The HTML5 shiv is necessary for e.g. the
tag which Drupal 8 uses + * to work in older browsers like Internet Explorer 8. + */ + protected function assertNoJavaScriptExceptHtml5Shiv() { + // Ensure drupalSettings is not set. + $settings = $this->getDrupalSettings(); + $this->assertTrue(empty($settings), 'drupalSettings is not set.'); + + // Ensure the HTML5 shiv exists. + $this->assertRaw('html5shiv/html5shiv.min.js', 'HTML5 shiv JavaScript exists.'); + + // Ensure no other JavaScript file exists on the page, while ignoring the + // HTML5 shiv. + $this->assertNoPattern('/(?