Pull merge.
[yaffs-website] / vendor / jcalderonzumba / gastonjs / tests / unit / BrowserPageTest.php
1 <?php
2 namespace Zumba\GastonJS\Tests;
3
4 /**
5  * Class BrowserPageTest
6  * @package Zumba\GastonJS\Tests
7  */
8 class BrowserPageTest extends BrowserCommandsTestCase {
9
10   public function testGetStatusCodeNoPage() {
11     try {
12       $this->browser->getStatusCode();
13     } catch (\Exception $e) {
14       $this->assertInstanceOf("Zumba\\GastonJS\\Exception\\StatusFailError", $e);
15     }
16   }
17
18   public function testGetStatusCodePage() {
19     $this->visitUrl($this->getTestPageBaseUrl() . "/static/basic.html");
20     $this->assertEquals(200, $this->browser->getStatusCode());
21     $this->visitUrl($this->getTestPageBaseUrl() . "/this_does_not_exists");
22     $this->assertEquals(404, $this->browser->getStatusCode());
23   }
24
25   public function testGetBodyNoPage() {
26     $expectedBody = "<html><head></head><body></body></html>";
27     $this->assertEquals($expectedBody, $this->browser->getBody());
28   }
29
30   public function testGetBodyPage() {
31     $htmlFile = sprintf("%s/Server/www/web/static/basic.html", realpath(__DIR__));
32     $expectedDom = new \DOMDocument();
33     $expectedDom->loadHTMLFile($htmlFile);
34     $expectedDom->preserveWhiteSpace = false;
35     $expectedDom->formatOutput = true;
36
37     $this->visitUrl($this->getTestPageBaseUrl() . "/static/basic.html");
38     $pageDom = new \DOMDocument();
39     $pageDom->loadHTML($this->browser->getBody());
40     $pageDom->preserveWhiteSpace = false;
41     $pageDom->formatOutput = true;
42
43     $this->assertXmlStringEqualsXmlString($pageDom->saveXML(), $expectedDom->saveXML());
44   }
45
46   public function testGetSourceNoPage() {
47     $this->assertNull($this->browser->getSource());
48   }
49
50   public function testGetSourcePage() {
51     $htmlFile = sprintf("%s/Server/www/web/static/basic.html", realpath(__DIR__));
52     $expectedDom = new \DOMDocument();
53     $expectedDom->loadHTMLFile($htmlFile);
54     $expectedDom->preserveWhiteSpace = false;
55     $expectedDom->formatOutput = true;
56
57     $this->visitUrl($this->getTestPageBaseUrl() . "/static/basic.html");
58     $pageDom = new \DOMDocument();
59     $pageDom->loadHTML($this->browser->getSource());
60     $pageDom->preserveWhiteSpace = false;
61     $pageDom->formatOutput = true;
62
63     $this->assertXmlStringEqualsXmlString($pageDom->saveXML(), $expectedDom->saveXML());
64   }
65
66   public function testGetTitle() {
67     $this->assertEmpty($this->browser->getTitle());
68     $this->visitUrl($this->getTestPageBaseUrl() . "/static/basic.html");
69     $this->assertEquals("Test", $this->browser->getTitle());
70   }
71
72   public function testReset() {
73     $this->visitUrl($this->getTestPageBaseUrl() . "/static/basic.html");
74     $this->assertTrue($this->browser->reset());
75     $this->testGetStatusCodeNoPage();
76     $this->testGetBodyNoPage();
77     $this->testGetSourceNoPage();
78     //TODO: increase reset tests by testing for example cookies
79   }
80
81
82 }