public function testNesting() { $route1 = new UrlRoute('foo'); $route2 = new UrlRoute('bar'); $route3 = new UrlRoute('baz'); $route4 = new UrlRoute('bazbar'); $router = new \Jivoo\Http\Router(); $nested1 = $router->match('foo', $route1); $nested2 = $nested1->match('bar', $route2); $nested2->error($route4); $nested2->match(['baz' => $route3]); $match = $router->findMatch(['foo'], 'GET'); $this->assertInstanceOf('Jivoo\\Http\\Route\\UrlRoute', $match); $this->assertEquals('foo', $match->getUrl()); $match = $router->findMatch(['foo', 'bar'], 'GET'); $this->assertInstanceOf('Jivoo\\Http\\Route\\UrlRoute', $match); $this->assertEquals('bar', $match->getUrl()); $match = $router->findMatch(['foo', 'bar', 'baz'], 'GET'); $this->assertInstanceOf('Jivoo\\Http\\Route\\UrlRoute', $match); $this->assertEquals('baz', $match->getUrl()); $match = $router->findMatch(['foo', 'bar', 'ba'], 'GET'); $this->assertInstanceOf('Jivoo\\Http\\Route\\UrlRoute', $match); $this->assertEquals('bazbar', $match->getUrl()); $match = $router->findMatch(['foo', 'bar', 'baz', 'foo'], 'GET'); $this->assertInstanceOf('Jivoo\\Http\\Route\\UrlRoute', $match); $this->assertEquals('bazbar', $match->getUrl()); }
public function testRouting() { $router = new \Jivoo\Http\Router(); $assets = new AssetScheme('tests/data/assets'); $router->addScheme($assets); $router->match('assets/**', 'asset:'); $route = $router->findMatch(['assets', 'css', 'foo.css'], 'GET'); $this->assertInstanceOf('Jivoo\\Http\\Route\\AssetRoute', $route); $this->assertEquals(['css', 'foo.css'], $route->getParameters()); $this->assertEquals('asset:css/foo.css', $route->__toString()); $response = $router(\Jivoo\Http\Message\Request::create('/index.php/assets/css/foo.css'), new Response(Status::OK)); $this->assertEquals('/* Empty test file used in AssetSchemeTest */', $response->getBody()->getContents()); $this->assertEquals('text/css', $response->getHeaderLine('Content-Type')); }