Skip to content

Commit

Permalink
Implement referrer for Kohana driver
Browse files Browse the repository at this point in the history
  • Loading branch information
ivank committed Jun 23, 2015
1 parent 28c68a5 commit 9a2c432
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
class Driver_Kohana_RequestFactory_Kohana implements Driver_Simple_RequestFactory {

protected static $_previous_url;

protected $_request;
protected $_response;
protected $_max_redirects = 5;
Expand Down Expand Up @@ -65,6 +67,12 @@ public function execute($method, $url, array $post = array())
->post($post)
->body(http_build_query($post));

if (Driver_Kohana_RequestFactory_Kohana::$_previous_url) {
$this->_request->referrer(Driver_Kohana_RequestFactory_Kohana::$_previous_url);
}

Driver_Kohana_RequestFactory_Kohana::$_previous_url = $this->current_url();

\Request::$initial = $this->_request;

$this->_response = $this->_request->execute();
Expand Down
9 changes: 9 additions & 0 deletions tests/tests/Driver/KohanaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ public function test_redirect()
$this->assertSame(Request::$initial, $driver->request_factory()->request());
}

public function test_referrer()
{
$driver = new Driver_Kohana();
$driver->get('/test/index');
$this->assertEquals('', $driver->request_factory()->request()->referrer());
$driver->get('/test/action_final');
$this->assertEquals('http://example.com/test/index', $driver->request_factory()->request()->referrer());
}

public function test_too_many_redirects()
{
$this->setExpectedException('Openbuildings\Spiderling\Exception_Toomanyredirects');
Expand Down

0 comments on commit 9a2c432

Please sign in to comment.