1 package Catalyst::Test;
6 use Catalyst::Exception;
8 use UNIVERSAL::require;
10 $ENV{CATALYST_ENGINE} ||= 'CGI';
14 Catalyst::Test - Test Catalyst Applications
22 use Catalyst::Test 'TestApp';
23 request('index.html');
26 # Run tests against a remote server
27 CATALYST_SERVER='http://localhost:3000/' prove -r -l lib/ t/
29 # Tests with inline apps need to use Catalyst::Engine::Test
35 my ( $self, $c ) = @_;
36 $c->res->output('bar');
43 use Test::More tests => 1;
44 use Catalyst::Test 'TestApp';
46 ok( get('/foo') =~ /bar/ );
50 Test Catalyst Applications.
60 my $content = get('foo/bar?test=1');
64 Returns a C<HTTP::Response> object.
66 my $res = request('foo/bar?test=1');
74 my ( $get, $request );
76 if ( $ENV{CATALYST_SERVER} ) {
77 $request = sub { remote_request(@_) };
78 $get = sub { remote_request(@_)->content };
83 die if $@ && $@ !~ /^Can't locate /;
86 $request = sub { local_request( $class, @_ ) };
87 $get = sub { local_request( $class, @_ )->content };
91 my $caller = caller(0);
92 *{"$caller\::request"} = $request;
93 *{"$caller\::get"} = $get;
103 require HTTP::Request::AsCGI;
105 my $request = Catalyst::Utils::request( shift(@_) );
106 my $cgi = HTTP::Request::AsCGI->new( $request, %ENV )->setup;
108 $class->handle_request;
110 return $cgi->restore->response;
117 Do an actual remote request using LWP.
123 require LWP::UserAgent;
125 my $request = Catalyst::Utils::request( shift(@_) );
126 my $server = URI->new( $ENV{CATALYST_SERVER} );
128 if ( $server->path =~ m|^(.+)?/$| ) {
129 $server->path("$1"); # need to be quoted
132 $request->uri->scheme( $server->scheme );
133 $request->uri->host( $server->host );
134 $request->uri->port( $server->port );
135 $request->uri->path( $server->path . $request->uri->path );
139 $agent = LWP::UserAgent->new(
148 return $agent->request($request);
159 Sebastian Riedel, C<sri@cpan.org>
163 This program is free software, you can redistribute it and/or modify it under
164 the same terms as Perl itself.