bd7b18679e36c6c077a60d9ab933bec96c923106
[yaffs-website] / vendor / jcalderonzumba / gastonjs / tests / unit / BrowserPageFindTest.php
1 <?php
2 namespace Zumba\GastonJS\Tests;
3
4 use Zumba\GastonJS\Exception\BrowserError;
5 use Zumba\GastonJS\Exception\InvalidSelector;
6 use Zumba\GastonJS\Exception\ObsoleteNode;
7
8 /**
9  * Class BrowserPageFindTest
10  * @package Zumba\GastonJS\Tests
11  */
12 class BrowserPageFindTest extends BrowserCommandsTestCase {
13
14   public function testFindElementNoPage() {
15     $notFound = $this->browser->find("xpath", '//*[@id="form_1014473"]');
16     $this->assertEquals(0, $notFound["page_id"]);
17   }
18
19   public function testFindInvalidSelector() {
20     $selector = "xpath";
21     $invalidSelection = '//*INVALID_SELECTOR[@id="form_1014473"]';
22     try {
23       $this->browser->find($selector, $invalidSelection);
24     } catch (InvalidSelector $e) {
25       $this->assertEquals($selector, $e->getMethod());
26       $this->assertEquals($invalidSelection, $e->getSelector());
27     }
28   }
29
30   public function testFindElementPage() {
31     $this->visitUrl($this->getTestPageBaseUrl() . "/test/standard_form/form.html");
32     $element = $this->browser->find("xpath", '//*[@id="form_1014473"]');
33     $this->assertEquals(1, $element["page_id"]);
34     $this->assertEquals(0, $element["ids"][0]);
35     $cssElement = $this->browser->find("css", "#form_1014473 > div");
36     $this->assertEquals(1, $cssElement["page_id"]);
37     $this->assertEquals(1, $cssElement["ids"][0]);
38   }
39
40   public function testFindWithinElementNoPage() {
41     try {
42       $this->browser->findWithin(1, 0, "xpath", '//*[@id="li_1"]');
43     } catch (\Exception $e) {
44       $this->assertInstanceOf("Zumba\\GastonJS\\Exception\\ObsoleteNode", $e);
45     }
46   }
47
48   public function testFindWithinElementPage() {
49     $this->visitUrl($this->getTestPageBaseUrl() . "/test/standard_form/form.html");
50     $this->browser->find("css", "#form_1014473");
51     $withinElement = $this->browser->findWithin(1, 0, "css", "div");
52     $this->assertCount(4, $withinElement);
53   }
54
55   public function testGetParents() {
56     $this->visitUrl($this->getTestPageBaseUrl() . "/test/standard_form/form.html");
57     $this->browser->find("xpath", '//*[@id="form_1014473"]');
58     $this->assertArraySubset(array(1, 2, 3), $this->browser->getParents(1, 0));
59   }
60
61   public function testTagName() {
62     $this->visitUrl($this->getTestPageBaseUrl() . "/test/standard_form/form.html");
63     $this->browser->find("xpath", '//*[@id="form_1014473"]');
64     $this->assertEquals("form", $this->browser->tagName(1, 0));
65   }
66
67   public function testEquals() {
68     $this->visitUrl($this->getTestPageBaseUrl() . "/test/standard_form/form.html");
69     try {
70       $this->browser->equals(1, 0, 1);
71     } catch (ObsoleteNode $e) {
72     }
73     //TODO: equals method seems to be broken or i do not know how to use it
74   }
75
76   public function testIsVisible() {
77     $this->visitUrl($this->getTestPageBaseUrl() . "/static/basic.html");
78     $this->browser->find("xpath", '//*[@id="break"]');
79     $this->assertTrue($this->browser->isVisible(1, 0));
80     $this->browser->find("xpath", '/html/body/p[1]');
81     $this->assertFalse($this->browser->isVisible(1, 1));
82   }
83
84   public function testIsDisabled() {
85     $this->visitUrl($this->getTestPageBaseUrl() . "/static/basic.html");
86     $this->browser->find("xpath", '//*[@id="disabled_check"]');
87     $this->browser->find("xpath", '//*[@id="enabled_check"]');
88     $this->assertTrue($this->browser->isDisabled(1, 0));
89     $this->assertFalse($this->browser->isDisabled(1, 1));
90   }
91 }