2 namespace Zumba\GastonJS\Tests;
5 * Class BrowserPageTest
6 * @package Zumba\GastonJS\Tests
8 class BrowserPageTest extends BrowserCommandsTestCase {
10 public function testGetStatusCodeNoPage() {
12 $this->browser->getStatusCode();
13 } catch (\Exception $e) {
14 $this->assertInstanceOf("Zumba\\GastonJS\\Exception\\StatusFailError", $e);
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());
25 public function testGetBodyNoPage() {
26 $expectedBody = "<html><head></head><body></body></html>";
27 $this->assertEquals($expectedBody, $this->browser->getBody());
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;
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;
43 $this->assertXmlStringEqualsXmlString($pageDom->saveXML(), $expectedDom->saveXML());
46 public function testGetSourceNoPage() {
47 $this->assertNull($this->browser->getSource());
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;
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;
63 $this->assertXmlStringEqualsXmlString($pageDom->saveXML(), $expectedDom->saveXML());
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());
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