コード例 #1
0
ファイル: RouterTest.php プロジェクト: jivoo/http
 public function testInvoke()
 {
     $router = new Router();
     $router->enableRewrite();
     $router->addScheme(new Route\UrlScheme());
     $router->match('foo/bar', 'http://example.com/bar');
     $request1 = Message\Request::create('/foo/bar');
     $response1 = new Message\Response(Message\Status::OK);
     $response2 = $router($request1, $response1);
     $this->assertEquals(Message\Status::SEE_OTHER, $response2->getStatusCode());
     $this->assertEquals('http://example.com/bar', $response2->getHeaderLine('Location'));
     $request2 = Message\Request::create('/foo');
     $this->assertThrows('Jivoo\\Http\\Route\\RouteException', function () use($router, $request2, $response1) {
         $router($request2, $response1);
     });
     // Test removal of trailing slash
     $request3 = Message\Request::create('/foo/');
     $response3 = $router($request3, $response1);
     $this->assertEquals(Message\Status::MOVED_PERMANENTLY, $response3->getStatusCode());
     $this->assertEquals('/foo', $response3->getHeaderLine('Location'));
     $router->disableRewrite();
     // Test index.php redirects
     $request4 = Message\Request::create('/foo/bar')->withServerParams(['SCRIPT_NAME' => '/index.php']);
     $response4 = $router($request4, $response1);
     $this->assertEquals(Message\Status::MOVED_PERMANENTLY, $response4->getStatusCode());
     $this->assertEquals('/index.php/foo/bar', $response4->getHeaderLine('Location'));
     // Test index.php removal from path
     $request5 = Message\Request::create('/index.php/foo/bar')->withServerParams(['SCRIPT_NAME' => '/index.php']);
     $response5 = $router($request5, $response1);
     $this->assertEquals(Message\Status::SEE_OTHER, $response5->getStatusCode());
     $this->assertEquals('http://example.com/bar', $response5->getHeaderLine('Location'));
 }
コード例 #2
0
ファイル: ActionRequestTest.php プロジェクト: jivoo/http
 public function testFindPath()
 {
     $request = Message\Request::create('/foo/index.php/foo/bar');
     $this->assertEquals(['foo', 'index.php', 'foo', 'bar'], ActionRequest::findPath($request));
     $request = $request->withServerParams(['SCRIPT_NAME' => '/foo/index.php']);
     $this->assertEquals(['index.php', 'foo', 'bar'], ActionRequest::findPath($request));
     $request = $request->withUri(new Message\Uri('/foo'));
     $this->assertEquals([], ActionRequest::findPath($request));
     $request = $request->withUri(new Message\Uri('/foo/'));
     $this->assertEquals([], ActionRequest::findPath($request));
 }
コード例 #3
0
ファイル: AssetSchemeTest.php プロジェクト: jivoo/http
 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'));
 }