public function testRuntimeServiceRegistry()
 {
     $this->app->map->any('/')->execute(function () {
     });
     $exe = $this->app->request(\Exedra\Http\ServerRequest::createFromArray(array('method' => 'GET', 'uri' => '/')));
     $this->assertTrue($exe->url instanceof \Exedra\Factory\Url);
     $this->assertTrue($exe->redirect instanceof \Exedra\Runtime\Redirect);
     // $this->assertTrue($exe->module instanceof \Exedra\Module\Registry && $exe->module === $exe->app->module);
     // $this->assertTrue($exe->view instanceof \Exedra\View\Factory && $exe->view === $exe->module['Application']->view);
     // $this->assertTrue($exe->controller instanceof \Exedra\Factory\Controller && $exe->controller === $exe->module['Application']->controller);
 }
Beispiel #2
0
 public function testUriParts()
 {
     $request = \Exedra\Http\ServerRequest::createFromArray(array('method' => 'GET', 'uri' => 'http://google.com:80/foo/bar?baz=bad#fragman', 'headers' => array('referer' => array('http://foo.com'))));
     $uri = $request->getUri();
     $this->assertEquals('http://google.com:80/foo/bar?baz=bad#fragman', (string) $uri);
     $this->assertEquals('google.com', $uri->getHost());
     $this->assertEquals('http', $uri->getScheme());
     $this->assertEquals(80, $uri->getPort());
     $this->assertEquals('google.com:80', $uri->getAuthority());
     $this->assertEquals('/foo/bar', $uri->getPath());
     $this->assertEquals('baz=bad', $uri->getQuery());
     $this->assertEquals('fragman', $uri->getFragment());
     $this->assertEquals($uri->getQuery(), http_build_query($request->getQueryParams()));
 }
Beispiel #3
0
 public function testPrevious()
 {
     $this->app->request = \Exedra\Http\ServerRequest::createFromArray(array('method' => 'GET', 'uri' => 'http://example.com/hello/world', 'headers' => array('Referer' => array('http://example.com/previous'))));
     $this->assertEquals('http://example.com/previous', $this->app->url->previous());
 }
Beispiel #4
0
 public function testMultioptional()
 {
     $this->map['foo']->get('mult/[:foo?]/[:bar?]/[:baz?]')->execute(function ($exe) {
         return 'qux' . $exe->param('foo', 'hug') . $exe->param('bar', 'tiz') . $exe->param('baz', 'rel');
     })->group(function ($mult) {
         $mult->get('/opt/[:dst?]/[:tst?]/[:rdt?]')->execute(function ($exe) {
             $pre = implode('', $exe->params(['foo', 'bar', 'baz']));
             return $pre . 'lud' . $exe->param('dst', 'jux') . $exe->param('tst', 'jid') . $exe->param('rdt', 'kit');
         });
     });
     $exe1 = $this->app->request(ServerRequest::createFromArray(['uri' => ['path' => '/mult']]));
     $exe2 = $this->app->request(ServerRequest::createFromArray(['uri' => ['path' => '/mult/baz']]));
     $exe3 = $this->app->request(ServerRequest::createFromArray(['uri' => ['path' => '/mult/baz/bad']]));
     $exe4 = $this->app->request(ServerRequest::createFromArray(['uri' => ['path' => '/mult/baz/bad/lux']]));
     $exe5 = $this->app->request(ServerRequest::createFromArray(['uri' => ['path' => '/mult/baz/bad/lux/opt']]));
     $exe6 = $this->app->request(ServerRequest::createFromArray(['uri' => ['path' => '/mult/baz/bad/lux/opt/nop']]));
     $exe7 = $this->app->request(ServerRequest::createFromArray(['uri' => ['path' => '/mult/baz/bad/lux/opt/nop/top']]));
     $exe8 = $this->app->request(ServerRequest::createFromArray(['uri' => ['path' => '/mult/baz/bad/lux/opt/nop/top/qef']]));
     $this->assertEquals('quxhugtizrel', $exe1->response->getBody());
     $this->assertEquals('quxbaztizrel', $exe2->response->getBody());
     $this->assertEquals('quxbazbadrel', $exe3->response->getBody());
     $this->assertEquals('quxbazbadlux', $exe4->response->getBody());
     $this->assertEquals('bazbadluxludjuxjidkit', $exe5->response->getBody());
     $this->assertEquals('bazbadluxludnopjidkit', $exe6->response->getBody());
     $this->assertEquals('bazbadluxludnoptopkit', $exe7->response->getBody());
     $this->assertEquals('bazbadluxludnoptopqef', $exe8->response->getBody());
 }
Beispiel #5
0
 public function testFailedDispatch()
 {
     $request = \Exedra\Http\ServerRequest::createFromArray(array('method' => 'GET', 'uri' => 'http://google.com:80/foo/bar/bat?baz=bad#fragman', 'headers' => array('referer' => array('http://foo.com'))));
     $app = new \Exedra\Application(__DIR__);
     $app->map->any('/foo/bar')->execute(function () {
         return 'baz';
     });
     $response = $app->respond($request);
     $this->assertEquals(404, $response->getStatusCode());
     $this->assertEquals('Route does not exist', $response->getBody());
 }