summaryrefslogtreecommitdiffstatshomepage
path: root/core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php
diff options
context:
space:
mode:
authorAlex Pott <alex.a.pott@googlemail.com>2018-07-30 12:01:13 +0100
committerAlex Pott <alex.a.pott@googlemail.com>2018-07-30 12:01:13 +0100
commitd1eee651bedcf1ad1cb64988948240227d4eebd6 (patch)
tree356b18a31c5d9b7e72c39657a1b1bfb050bb8241 /core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php
parente4146aa44f12ed99f8e70e145279898f5de20670 (diff)
downloaddrupal-d1eee651bedcf1ad1cb64988948240227d4eebd6.tar.gz
drupal-d1eee651bedcf1ad1cb64988948240227d4eebd6.zip
Issue #2942314 by Lendude: Move JavascriptGetDrupalSettingsTest, BrowserWithJavascriptTest out of simpletest module
Diffstat (limited to 'core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php')
-rw-r--r--core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php63
1 files changed, 63 insertions, 0 deletions
diff --git a/core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php b/core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php
new file mode 100644
index 000000000000..98a3b9726228
--- /dev/null
+++ b/core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php
@@ -0,0 +1,63 @@
+<?php
+
+namespace Drupal\FunctionalJavascriptTests;
+
+/**
+ * Tests if we can execute JavaScript in the browser.
+ *
+ * @group javascript
+ */
+class BrowserWithJavascriptTest extends WebDriverTestBase {
+
+ public function testJavascript() {
+ $this->drupalGet('<front>');
+ $session = $this->getSession();
+
+ $session->resizeWindow(400, 300);
+ $javascript = <<<JS
+ (function(){
+ var w = window,
+ d = document,
+ e = d.documentElement,
+ g = d.getElementsByTagName('body')[0],
+ x = w.innerWidth || e.clientWidth || g.clientWidth,
+ y = w.innerHeight || e.clientHeight|| g.clientHeight;
+ return x == 400 && y == 300;
+ }());
+JS;
+ $this->assertJsCondition($javascript);
+ }
+
+ public function testAssertJsCondition() {
+ $this->drupalGet('<front>');
+ $session = $this->getSession();
+
+ $session->resizeWindow(500, 300);
+ $javascript = <<<JS
+ (function(){
+ var w = window,
+ d = document,
+ e = d.documentElement,
+ g = d.getElementsByTagName('body')[0],
+ x = w.innerWidth || e.clientWidth || g.clientWidth,
+ y = w.innerHeight || e.clientHeight|| g.clientHeight;
+ return x == 400 && y == 300;
+ }());
+JS;
+
+ // We expected the following assertion to fail because the window has been
+ // re-sized to have a width of 500 not 400.
+ $this->setExpectedException(\PHPUnit_Framework_AssertionFailedError::class);
+ $this->assertJsCondition($javascript, 100);
+ }
+
+ /**
+ * Tests creating screenshots.
+ */
+ public function testCreateScreenshot() {
+ $this->drupalGet('<front>');
+ $this->createScreenshot('public://screenshot.jpg');
+ $this->assertFileExists('public://screenshot.jpg');
+ }
+
+}