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