From cff8a4ed3df411ee3fc07822e2e0295b11132a52 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 18 Jun 2011 15:25:17 -0400 Subject: [PATCH] Update RootController and test so that a Request is passed to UrlMap::Evaluate() --- http/root_controller.php | 8 ++++---- testing/tests/http/root_controller_test.php | 16 +++++++++------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/http/root_controller.php b/http/root_controller.php index e2e90ae..f420c7f 100644 --- a/http/root_controller.php +++ b/http/root_controller.php @@ -90,7 +90,7 @@ class RootController $this->request->http_method = $this->request->data['_SERVER']['REQUEST_METHOD']; // Dispatch the request to an Action. - $this->RouteRequest($url); + $this->RouteRequest($this->request); // When control returns here, all actions have been invoked and it's time // to start the output filter and exit. @@ -118,11 +118,11 @@ class RootController /*! Invoked by Run() and can be invoked by others to evaluate and perform the lookup in the UrlMap. This then calls InvokeAction(). - @param string The URL fragment to look up in the + @param Request The Request whose URL will be routed */ - public function RouteRequest($url_fragment) + public function RouteRequest(Request $request) { - $url_map_value = $this->url_map->Evaluate($url_fragment); + $url_map_value = $this->url_map->Evaluate($request); $action = NULL; if ($url_map_value) diff --git a/testing/tests/http/root_controller_test.php b/testing/tests/http/root_controller_test.php index c499fe1..2135db5 100644 --- a/testing/tests/http/root_controller_test.php +++ b/testing/tests/http/root_controller_test.php @@ -66,9 +66,11 @@ class RootControllerTest extends \PHPUnit_Framework_TestCase )); $mock = $this->ConfigureMock(array('RouteRequest', 'Stop'), $globals); + $mock->request()->url = 'some/action/42'; + $mock->expects($this->once()) ->method('RouteRequest') - ->with($this->equalTo('some/action/42')); + ->with($this->equalTo($mock->request())); $mock->expects($this->once()) ->method('Stop'); @@ -99,7 +101,7 @@ class RootControllerTest extends \PHPUnit_Framework_TestCase $globals = array(); $mock = $this->ConfigureMock(array('Stop', 'InvokeAction'), $globals); - $fragment = 'some/action/42'; + $mock->request()->url = 'some/action/42'; $map_value = 'ActionReporter'; $action = new ActionReporter($mock); @@ -110,7 +112,7 @@ class RootControllerTest extends \PHPUnit_Framework_TestCase $url_map = $this->getMock('hoplite\http\UrlMap', array(), array($mock)); $url_map->expects($this->once()) ->method('Evaluate') - ->with($this->equalTo($fragment)) + ->with($this->equalTo($mock->request())) ->will($this->returnValue($map_value)); $url_map->expects($this->once()) ->method('LookupAction') @@ -118,7 +120,7 @@ class RootControllerTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue($action)); $mock->set_url_map($url_map); - $mock->RouteRequest($fragment); + $mock->RouteRequest($mock->request()); } public function testRouteRequestInvalid() @@ -126,7 +128,7 @@ class RootControllerTest extends \PHPUnit_Framework_TestCase $globals = array(); $mock = $this->ConfigureMock(array('Stop'), $globals); - $fragment = 'another/action'; + $mock->request()->url = 'another/action'; $mock->expects($this->once()) ->method('Stop'); @@ -134,10 +136,10 @@ class RootControllerTest extends \PHPUnit_Framework_TestCase $url_map = $this->getMock('hoplite\http\UrlMap', array(), array($mock)); $url_map->expects($this->once()) ->method('Evaluate') - ->with($this->equalTo($fragment)); + ->with($this->equalTo($mock->request())); $mock->set_url_map($url_map); - $mock->RouteRequest($fragment); + $mock->RouteRequest($mock->request()); $this->assertEquals(http\ResponseCode::NOT_FOUND, $mock->response()->response_code); } -- 2.22.5