X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FTest.pm;h=f3d4de32c725214d47ee8263235b6c5edd61ea97;hb=e73e3bad5248d5d16e6b32024ca341d1208e7bcb;hp=196a4d916eac5f511a8142a80ebb0a52811b2f74;hpb=c20c7349141fbf5dab2219fbf9ff809893be93db;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Test.pm b/lib/Catalyst/Test.pm index 196a4d9..f3d4de3 100644 --- a/lib/Catalyst/Test.pm +++ b/lib/Catalyst/Test.pm @@ -21,6 +21,12 @@ Catalyst::Test - Test Catalyst Applications request('index.html'); get('index.html'); + use HTTP::Request::Common; + my $response = request POST '/foo', [ + bar => 'baz', + something => 'else' + ]; + # Run tests against a remote server CATALYST_SERVER='http://localhost:3000/' prove -r -l lib/ t/ @@ -45,7 +51,13 @@ Catalyst::Test - Test Catalyst Applications =head1 DESCRIPTION -Test Catalyst Applications. +This module allows you to make requests to a Catalyst application either without +a server, by simulating the environment of an HTTP request using +L or remotely if you define the CATALYST_SERVER +environment variable. + +The and functions take either a URI or an L +object. =head2 METHODS @@ -104,6 +116,8 @@ sub import { =head2 local_request +Simulate a request using L. + =cut sub local_request { @@ -135,22 +149,8 @@ sub remote_request { my $server = URI->new( $ENV{CATALYST_SERVER} ); if ( $server->path =~ m|^(.+)?/$| ) { - $server->path("$1"); # need to be quoted - } - - # the request path needs to be sanitised if $server is using a - # non-root path due to potential overlap between request path and - # response path. - if ($server->path) { - my @sp = split '/', $server->path; - my @rp = split '/', $request->uri->path; - shift @sp;shift @rp; # leading / - if (@rp) { - foreach my $sp (@sp) { - $sp eq $rp[0] ? shift @rp : last - } - } - $request->uri->path(join '/', @rp); + my $path = $1; + $server->path("$path") if $path; # need to be quoted } # the request path needs to be sanitised if $server is using a @@ -187,6 +187,10 @@ sub remote_request { keep_alive => 1, max_redirect => 0, timeout => 60, + + # work around newer LWP max_redirect 0 bug + # http://rt.cpan.org/Ticket/Display.html?id=40260 + requests_redirectable => [], ); $agent->env_proxy; @@ -197,11 +201,12 @@ sub remote_request { =head1 SEE ALSO -L. +L, L, +L, L, L -=head1 AUTHOR +=head1 AUTHORS -Sebastian Riedel, C +Catalyst Contributors, see Catalyst.pm =head1 COPYRIGHT