3 namespace Zumba\GastonJS\Tests;
6 * Class BrowserHeadersTest
7 * @package Zumba\GastonJS\Tests
9 class BrowserHeadersTest extends BrowserCommandsTestCase {
11 public function testHeadersEmpty() {
12 $this->assertCount(0, $this->browser->getHeaders());
15 public function testHeadersNotEmpty() {
16 $this->visitUrl($this->getTestPageBaseUrl() . "/static/basic.html");
17 $responseHeaders = $this->browser->responseHeaders();
18 $this->assertTrue(is_array($responseHeaders));
19 $this->assertCount(4, $responseHeaders);
22 public function testHeaderAddPermanent() {
23 $this->assertTrue($this->browser->addHeader(array("X-Permanent-Test" => "x_permanent_value"), true));
24 $this->visitUrl($this->getTestPageBaseUrl() . "/check-request-headers/");
25 $requestResponse = json_decode(strip_tags($this->browser->getBody()), true);
26 $this->assertEquals("x_permanent_value", $requestResponse["x-permanent-test"][0]);
28 //After reload, the header should still be there
29 $this->visitUrl($this->getTestPageBaseUrl() . "/check-request-headers/");
30 $requestResponse = json_decode(strip_tags($this->browser->getBody()), true);
31 $this->assertEquals("x_permanent_value", $requestResponse["x-permanent-test"][0]);
34 public function testHeaderAddTemp() {
35 $this->assertTrue($this->browser->addHeader(array("X-Permanent-Test" => "x_permanent_value")));
36 $this->visitUrl($this->getTestPageBaseUrl() . "/check-request-headers/");
37 $requestResponse = json_decode(strip_tags($this->browser->getBody()), true);
38 $this->assertEquals("x_permanent_value", $requestResponse["x-permanent-test"][0]);
40 //After the visit the header should not be present in the request
41 $this->visitUrl($this->getTestPageBaseUrl() . "/check-request-headers/");
42 $requestResponse = json_decode(strip_tags($this->browser->getBody()), true);
43 $this->assertArrayNotHasKey("x-permanent-test", $requestResponse);
46 public function testAddHeaders() {
47 $customHeaders = array("X-Header-One" => "one", "X-Header-Two" => "two");
48 $this->assertTrue($this->browser->addHeaders($customHeaders));
49 $this->visitUrl($this->getTestPageBaseUrl() . "/check-request-headers/");
50 $requestResponse = json_decode(strip_tags($this->browser->getBody()), true);
51 $this->assertArrayHasKey("x-header-one", $requestResponse);
52 $this->assertArrayHasKey("x-header-two", $requestResponse);
54 //now we will issue another header and the previous should be there too
55 $this->assertTrue($this->browser->addHeaders(array("X-Header-Three" => "three")));
56 $this->visitUrl($this->getTestPageBaseUrl() . "/check-request-headers/");
57 $requestResponse = json_decode(strip_tags($this->browser->getBody()), true);
58 $this->assertArrayHasKey("x-header-one", $requestResponse);
59 $this->assertArrayHasKey("x-header-two", $requestResponse);
60 $this->assertArrayHasKey("x-header-three", $requestResponse);
64 public function testSetHeaders() {
65 $customHeaders = array("X-Header-One" => "one", "X-Header-Two" => "two");
66 $this->assertTrue($this->browser->setHeaders($customHeaders));
67 $this->visitUrl($this->getTestPageBaseUrl() . "/check-request-headers/");
68 $requestResponse = json_decode(strip_tags($this->browser->getBody()), true);
69 $this->assertArrayHasKey("x-header-one", $requestResponse);
70 $this->assertArrayHasKey("x-header-two", $requestResponse);
72 //now we will issue another header and the previous should NOT be here
73 $this->assertTrue($this->browser->setHeaders(array("X-Header-Three" => "three")));
74 $this->visitUrl($this->getTestPageBaseUrl() . "/check-request-headers/");
75 $requestResponse = json_decode(strip_tags($this->browser->getBody()), true);
76 $this->assertArrayHasKey("x-header-three", $requestResponse);
77 $this->assertArrayNotHasKey("x-header-one", $requestResponse);
78 $this->assertArrayNotHasKey("x-header-two", $requestResponse);