From: Christian Hansen Date: Wed, 23 Mar 2005 00:19:56 +0000 (+0000) Subject: added t/16uri.t X-Git-Tag: 5.7099_04~1728 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=c10563323dadc3194743c5e460840380e8c07703 added t/16uri.t --- diff --git a/lib/Catalyst/Test.pm b/lib/Catalyst/Test.pm index affc9f7..824c577 100644 --- a/lib/Catalyst/Test.pm +++ b/lib/Catalyst/Test.pm @@ -92,7 +92,7 @@ sub request { $ENV{QUERY_STRING} ||= $request->uri->query || ''; $ENV{REQUEST_METHOD} ||= $request->method; $ENV{PATH_INFO} ||= $request->uri->path || '/'; - $ENV{SCRIPT_NAME} ||= $request->uri->path || '/'; + $ENV{SCRIPT_NAME} ||= '/'; $ENV{SERVER_NAME} ||= $request->uri->host || 'localhost'; $ENV{SERVER_PORT} ||= $request->uri->port; $ENV{SERVER_PROTOCOL} ||= 'HTTP/1.1'; diff --git a/t/16uri.t b/t/16uri.t new file mode 100644 index 0000000..86278ed --- /dev/null +++ b/t/16uri.t @@ -0,0 +1,53 @@ +package TestApp; + +use Catalyst; + +TestApp->action( '!default' => \&default ); +TestApp->action( 'index/a/b' => \&default ); + +sub default { + my ( $self, $c ) = @_; + $c->res->headers->header( 'X-Arguments' => $c->req->arguments ); + $c->res->headers->header( 'X-Base' => $c->req->base ); + $c->res->headers->header( 'X-Path' => $c->req->path ); + $c->res->headers->content_type('text/plain'); + $c->res->output('ok'); +} + +package main; + +use Test::More tests => 9; +use Catalyst::Test 'TestApp'; + +{ + local %ENV; + + $ENV{SCRIPT_NAME} = '/nph-catalyst.cgi'; + $ENV{PATH_INFO} = '/index'; + + my $response = request('/nph-catalyst.cgi/index'); + + ok( $response->headers->header('X-Base') eq 'http://localhost/nph-catalyst.cgi' ); + ok( $response->headers->header('X-Arguments') eq 'index' ); + ok( $response->headers->header('X-Path') eq 'index' ); +} + +{ + local %ENV; + + my $response = request('/index?a=a&b=b'); + + ok( $response->headers->header('X-Base') eq 'http://localhost/' ); + ok( $response->headers->header('X-Arguments') eq 'index' ); + ok( $response->headers->header('X-Path') eq 'index' ); +} + +{ + local %ENV; + + my $response = request('http://localhost:8080/index/a/b/c'); + + ok( $response->headers->header('X-Base') eq 'http://localhost:8080/' ); + ok( $response->headers->header('X-Arguments') eq 'c' ); + ok( $response->headers->header('X-Path') eq 'index/a/b/c' ); +}