예제 #1
0
 public function testUrlForIfNoSuchRoute()
 {
     $this->setExpectedException('RuntimeException');
     $router = new \Slim\Router();
     $router->urlFor('foo', array('abc' => '123'));
 }
예제 #2
0
 /**
  * Router::urlFor
  */
 public function testRouterUrlFor()
 {
     $router = new \Slim\Router();
     $router->setResourceUri($this->req->getResourceUri());
     $route1 = $router->map('/foo/bar', function () {
     })->via('GET');
     $route2 = $router->map('/foo/:one/:two', function () {
     })->via('GET');
     $route3 = $router->map('/foo/:one(/:two)', function () {
     })->via('GET');
     $route4 = $router->map('/foo/:one/(:two/)', function () {
     })->via('GET');
     $route5 = $router->map('/foo/:one/(:two/(:three/))', function () {
     })->via('GET');
     $route6 = $router->map('/foo/:path+/bar', function () {
     })->via('GET');
     $route7 = $router->map('/foo/:path+/:path2+/bar', function () {
     })->via('GET');
     $route8 = $router->map('/foo/:path+', function () {
     })->via('GET');
     $route9 = $router->map('/foo/:var/:var2', function () {
     })->via('GET');
     $route1->setName('route1');
     $route2->setName('route2');
     $route3->setName('route3');
     $route4->setName('route4');
     $route5->setName('route5');
     $route6->setName('route6');
     $route7->setName('route7');
     $route8->setName('route8');
     $route9->setName('route9');
     //Route
     $this->assertEquals('/foo/bar', $router->urlFor('route1'));
     //Route with params
     $this->assertEquals('/foo/foo/bar', $router->urlFor('route2', array('one' => 'foo', 'two' => 'bar')));
     $this->assertEquals('/foo/foo/:two', $router->urlFor('route2', array('one' => 'foo')));
     $this->assertEquals('/foo/:one/bar', $router->urlFor('route2', array('two' => 'bar')));
     //Route with params and optional segments
     $this->assertEquals('/foo/foo/bar', $router->urlFor('route3', array('one' => 'foo', 'two' => 'bar')));
     $this->assertEquals('/foo/foo', $router->urlFor('route3', array('one' => 'foo')));
     $this->assertEquals('/foo/:one/bar', $router->urlFor('route3', array('two' => 'bar')));
     $this->assertEquals('/foo/:one', $router->urlFor('route3'));
     //Route with params and optional segments
     $this->assertEquals('/foo/foo/bar/', $router->urlFor('route4', array('one' => 'foo', 'two' => 'bar')));
     $this->assertEquals('/foo/foo/', $router->urlFor('route4', array('one' => 'foo')));
     $this->assertEquals('/foo/:one/bar/', $router->urlFor('route4', array('two' => 'bar')));
     $this->assertEquals('/foo/:one/', $router->urlFor('route4'));
     //Route with params and optional segments
     $this->assertEquals('/foo/foo/bar/what/', $router->urlFor('route5', array('one' => 'foo', 'two' => 'bar', 'three' => 'what')));
     $this->assertEquals('/foo/foo/', $router->urlFor('route5', array('one' => 'foo')));
     $this->assertEquals('/foo/:one/bar/', $router->urlFor('route5', array('two' => 'bar')));
     $this->assertEquals('/foo/:one/bar/what/', $router->urlFor('route5', array('two' => 'bar', 'three' => 'what')));
     $this->assertEquals('/foo/:one/', $router->urlFor('route5'));
     //Route with wildcard params
     $this->assertEquals('/foo/bar/bar', $router->urlFor('route6', array('path' => 'bar')));
     $this->assertEquals('/foo/foo/bar/bar', $router->urlFor('route7', array('path' => 'foo', 'path2' => 'bar')));
     $this->assertEquals('/foo/bar', $router->urlFor('route8', array('path' => 'bar')));
     //Route with similar param names, test greedy matching
     $this->assertEquals('/foo/1/2', $router->urlFor('route9', array('var2' => '2', 'var' => '1')));
     $this->assertEquals('/foo/1/2', $router->urlFor('route9', array('var' => '1', 'var2' => '2')));
 }