Update RootController and test so that a Request is passed to UrlMap::Evaluate()
authorRobert Sesek <rsesek@bluestatic.org>
Sat, 18 Jun 2011 19:25:17 +0000 (15:25 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Sat, 18 Jun 2011 19:25:17 +0000 (15:25 -0400)
http/root_controller.php
testing/tests/http/root_controller_test.php

index e2e90ae7ce86e9d1ac0c2edb4a68ff2b55a678d9..f420c7f5f44e10e03a62a2200122092ae0d9622d 100644 (file)
@@ -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)
index c499fe1ae5c40b9f95d7e070e9bc85af8ee287c0..2135db57e5368c6ed9a7d876189dd48270b9b496 100644 (file)
@@ -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);
   }