comparison core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
1 <?php
2
3 namespace Drupal\FunctionalJavascriptTests;
4
5 /**
6 * Tests if we can execute JavaScript in the browser.
7 *
8 * @group javascript
9 */
10 class BrowserWithJavascriptTest extends WebDriverTestBase {
11
12 public function testJavascript() {
13 $this->drupalGet('<front>');
14 $session = $this->getSession();
15
16 $session->resizeWindow(400, 300);
17 $javascript = <<<JS
18 (function(){
19 var w = window,
20 d = document,
21 e = d.documentElement,
22 g = d.getElementsByTagName('body')[0],
23 x = w.innerWidth || e.clientWidth || g.clientWidth,
24 y = w.innerHeight || e.clientHeight|| g.clientHeight;
25 return x == 400 && y == 300;
26 }());
27 JS;
28 $this->assertJsCondition($javascript);
29 }
30
31 public function testAssertJsCondition() {
32 $this->drupalGet('<front>');
33 $session = $this->getSession();
34
35 $session->resizeWindow(500, 300);
36 $javascript = <<<JS
37 (function(){
38 var w = window,
39 d = document,
40 e = d.documentElement,
41 g = d.getElementsByTagName('body')[0],
42 x = w.innerWidth || e.clientWidth || g.clientWidth,
43 y = w.innerHeight || e.clientHeight|| g.clientHeight;
44 return x == 400 && y == 300;
45 }());
46 JS;
47
48 // We expected the following assertion to fail because the window has been
49 // re-sized to have a width of 500 not 400.
50 $this->setExpectedException(\PHPUnit_Framework_AssertionFailedError::class);
51 $this->assertJsCondition($javascript, 100);
52 }
53
54 /**
55 * Tests creating screenshots.
56 */
57 public function testCreateScreenshot() {
58 $this->drupalGet('<front>');
59 $this->createScreenshot('public://screenshot.jpg');
60 $this->assertFileExists('public://screenshot.jpg');
61 }
62
63 }