public function testDispatchWithoutCallable() { Slim_Environment::mock(array('REQUEST_METHOD' => 'GET', 'REMOTE_ADDR' => '127.0.0.1', 'SCRIPT_NAME' => '', 'PATH_INFO' => '/hello/josh', 'QUERY_STRING' => 'one=1&two=2&three=3', 'SERVER_NAME' => 'slim', 'SERVER_PORT' => 80, 'slim.url_scheme' => 'http', 'slim.input' => '', 'slim.errors' => fopen('php://stderr', 'w'), 'HTTP_HOST' => 'slim')); $env = Slim_Environment::getInstance(); $req = new Slim_Http_Request($env); $res = new Slim_Http_Response(); $router = new Slim_Router($req, $res); $route = new Slim_Route('/hello/:name', 'foo'); $route->setRouter($router); $route->matches($req->getResourceUri()); //<-- Extracts params from resource URI $this->assertFalse($route->dispatch()); }
/** * Route does not match URI with wildcard */ public function testRouteDoesNotMatchResourceWithWildcard() { $resource = '/hello'; $route = new Slim_Route('/hello/:path+', function () { }); $result = $route->matches($resource); $this->assertFalse($result); $this->assertEquals(array(), $route->getParams()); }
/** * Route optional parameters * * Pre-conditions: * Route pattern requires :year, optionally accepts :month and :day * * Post-conditions: * All: Year is 2010 * Case A: Month and day default values are used * Case B: Month is "05" and day default value is used * Case C: Month is "05" and day is "13" */ public function testRouteOptionalParameters() { $pattern = '/archive/:year(/:month(/:day))'; //Case A $routeA = new Slim_Route($pattern, function () { }); $resourceA = '/archive/2010'; $resultA = $routeA->matches($resourceA); $this->assertTrue($resultA); $this->assertEquals(array('year' => '2010'), $routeA->getParams()); //Case B $routeB = new Slim_Route($pattern, function () { }); $resourceB = '/archive/2010/05'; $resultB = $routeB->matches($resourceB); $this->assertTrue($resultB); $this->assertEquals(array('year' => '2010', 'month' => '05'), $routeB->getParams()); //Case C $routeC = new Slim_Route($pattern, function () { }); $resourceC = '/archive/2010/05/13'; $resultC = $routeC->matches($resourceC); $this->assertTrue($resultC); $this->assertEquals(array('year' => '2010', 'month' => '05', 'day' => '13'), $routeC->getParams()); }