3 namespace Zumba\GastonJS\Tests;
6 * Class BrowserCookiesTest
7 * @package Zumba\GastonJS\Tests
9 class BrowserCookiesTest extends BrowserCommandsTestCase {
11 public function testCookiesAreEmpty() {
12 $this->assertEmpty($this->browser->cookies());
15 public function testCookiesAreNotEmpty() {
16 $this->visitUrl($this->getTestPageBaseUrl() . "/testCookiesAreNotEmpty/");
17 $cookies = $this->browser->cookies();
18 $this->assertCount(2, $cookies);
19 foreach ($cookies as $cookie) {
20 $this->assertInstanceOf('Zumba\GastonJS\Cookie', $cookie);
24 public function testClearCookies() {
25 //First we visit the page with cookies
26 $this->testCookiesAreNotEmpty();
27 //Then we issue a cookie clear
28 $this->assertTrue($this->browser->clearCookies());
29 //Then if we ask again it should be empty
30 $this->assertEmpty($this->browser->cookies());
31 //Then if we ask the basic page it should be empty
32 $this->visitUrl($this->getTestPageBaseUrl() . "/static/basic.html");
33 $this->assertEmpty($this->browser->cookies());
36 public function testRemoveCookie() {
37 //First we visit the page with cookies
38 $this->testCookiesAreNotEmpty();
39 //Then we issue the cookie removal with something that does not exists
40 $this->assertTrue($this->browser->removeCookie("DOES_NOT_EXITS"));
41 $this->assertCount(2, $this->browser->cookies());
42 //Now we issue a cookie removal that exists
43 $this->assertTrue($this->browser->removeCookie("a_cookie"));
44 $this->visitUrl($this->getTestPageBaseUrl() . "/static/basic.html");
45 $this->assertCount(1, $this->browser->cookies());
48 public function testSetCookie() {
49 $cookie = array("name" => "mycookie", "value" => "myvalue", "path" => "/", "domain" => "127.0.0.1");
50 $this->visitUrl($this->getTestPageBaseUrl() . "/static/basic.html");
51 $this->assertEmpty($this->browser->cookies());
52 $this->assertTrue($this->browser->setCookie($cookie));
53 $this->browser->reload();
54 $this->assertArrayHasKey("mycookie", $this->browser->cookies());
57 public function testSetCookieWithSemicolon() {
58 $cookie = array("name" => "mycookie", "value" => "simpletest217107;1443979275;5611600b7875f9.10349470;mDbNZYl4biS9JAGaPLizxz2tcMxIUA429gqcYaYxijM", "path" => "/", "domain" => "127.0.0.1");
59 $this->visitUrl($this->getTestPageBaseUrl() . "/static/basic.html");
60 $this->assertEmpty($this->browser->cookies());
61 $this->assertTrue($this->browser->setCookie($cookie));
62 $this->browser->reload();
63 $this->assertArrayHasKey("mycookie", $this->browser->cookies());
64 $this->assertEquals('simpletest217107;1443979275;5611600b7875f9.10349470;mDbNZYl4biS9JAGaPLizxz2tcMxIUA429gqcYaYxijM', $this->browser->cookies()['mycookie']->getValue());
67 public function testCookiesDisabled() {
68 $this->assertTrue($this->browser->cookiesEnabled(false));
69 $this->visitUrl($this->getTestPageBaseUrl() . "/testCookiesAreNotEmpty/");
70 //Should be zero since we have disabled the cookies
71 $this->assertEmpty($this->browser->cookies());
74 public function testCookiesEnabled(){
75 $this->assertTrue($this->browser->cookiesEnabled(true));
76 $this->testCookiesAreNotEmpty();