Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/JonnyW/PhantomJs/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ class Response
*/
public $console;

/**
* Session cookies
*
* @var array
* @access public
*/
public $cookies;

/**
* Import response data
*
Expand Down Expand Up @@ -247,4 +255,15 @@ public function getConsole()
{
return $this->console;
}

/**
* Get session cookies
*
* @access public
* @return array
*/
public function getCookies()
{
return $this->cookies;
}
}
8 changes: 8 additions & 0 deletions src/JonnyW/PhantomJs/Http/ResponseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,12 @@ public function isRedirect();
* @return string
*/
public function getTime();

/**
* Get session cookies
*
* @access public
* @return array
*/
public function getCookies();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ trace.forEach(function(t) {
response.status = 500;
response.content = msg;
response.console = stack;
response.cookies = phantom.cookies;

system.stdout.write(JSON.stringify(response, undefined, 4));
phantom.exit(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ if (status === 'success') {
}

response.console = logs;
response.cookies = phantom.cookies;

system.stderr.write(debug.join('\\n') + '\\n');
system.stdout.write(JSON.stringify(response, undefined, 4));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ if (status === 'success') {
}

response.console = logs;
response.cookies = phantom.cookies;

system.stderr.write(debug.join('\\n') + '\\n');
system.stdout.write(JSON.stringify(response, undefined, 4));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ if (status === 'success') {
}

response.console = logs;
response.cookies = phantom.cookies;

system.stderr.write(debug.join('\\n') + '\\n');
system.stdout.write(JSON.stringify(response, undefined, 4));
Expand Down
36 changes: 36 additions & 0 deletions src/JonnyW/PhantomJs/Tests/Integration/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,42 @@ public function testCanDeleteAllCookiesFromPersistentCookieFile()
$this->assertNotContains('test_cookie_2=TESTING_COOKIES_2; HttpOnly; expires=Mon, 16-Nov-2020 00:00:00 GMT; domain=.jonnyw.kiwi; path=/)', file_get_contents($file));
}


/**
* Test can load cookies from
* persistent cookie file
*
* @access public
* @return void
*/
public function testCookiesPresentInResponse()
{
$client = $this->getClient();

$request = $client->getMessageFactory()->createRequest();
$response = $client->getMessageFactory()->createResponse();

$expireAt = strtotime('16-Nov-2020 00:00:00');

$request->setMethod('GET');
$request->setUrl('http://www.jonnyw.kiwi/tests/test-default.php');
$request->addCookie('test_cookie', 'TESTING_COOKIES', '/', '.jonnyw.kiwi', true, false, ($expireAt * 1000));

$client->send($request, $response);

$cookies = $response->getCookies();
$this->assertEquals(array(
'domain' => '.jonnyw.kiwi',
'expires' => 'Mon, 16 Nov 2020 00:00:00 GMT',
'expiry' => '1605484800',
'httponly' => true,
'name' => 'test_cookie',
'path' => '/',
'secure' => false,
'value' => 'TESTING_COOKIES',
), $cookies[0]);
}

/**
* Test response contains console error if a
* javascript error exists on the page.
Expand Down
19 changes: 19 additions & 0 deletions src/JonnyW/PhantomJs/Tests/Unit/Http/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,25 @@ public function testIsNotRedirectIfStatusCodeIsNotRedirect()
$this->assertFalse($response->isRedirect());
}

/**
* Test if cookies can be parsed and imported
*
* @access public
* @return void
*/
public function testCookiesCanBeImported()
{
$cookie = 'cookie=TESTING; HttpOnly; expires=Mon, 16-Nov-2020 00:00:00 GMT; domain=.jonnyw.kiwi; path=/';
$data = array(
'cookies' => array($cookie)
);

$response = $this->getResponse();
$response->import($data);

$this->assertContains($cookie, $response->getCookies());
}

/** +++++++++++++++++++++++++++++++++++ **/
/** ++++++++++ TEST ENTITIES ++++++++++ **/
/** +++++++++++++++++++++++++++++++++++ **/
Expand Down