1 package Catalyst::Test;
6 use Catalyst::Exception;
9 use UNIVERSAL::require;
13 Catalyst::Test - Test Catalyst Applications
21 use Catalyst::Test 'TestApp';
22 request('index.html');
25 # Run tests against a remote server
26 CATALYST_SERVER='http://localhost:3000/' prove -r -l lib/ t/
28 # Tests with inline apps need to use Catalyst::Engine::Test
34 my ( $self, $c ) = @_;
35 $c->res->output('bar');
42 use Test::More tests => 1;
43 use Catalyst::Test 'TestApp';
45 ok( get('/foo') =~ /bar/ );
49 Test Catalyst Applications.
57 my $content = get('foo/bar?test=1');
61 Returns a C<HTTP::Response> object.
63 my $res = request('foo/bar?test=1');
71 my ( $get, $request );
73 if ( $ENV{CATALYST_SERVER} ) {
74 $request = sub { remote_request(@_) };
75 $get = sub { remote_request(@_)->content };
79 unless( Class::Inspector->loaded( $class ) ) {
85 $request = sub { local_request( $class, @_ ) };
86 $get = sub { local_request( $class, @_ )->content };
90 my $caller = caller(0);
91 *{"$caller\::request"} = $request;
92 *{"$caller\::get"} = $get;
102 require HTTP::Request::AsCGI;
104 my $request = Catalyst::Utils::request( shift(@_) );
105 my $cgi = HTTP::Request::AsCGI->new( $request, %ENV )->setup;
107 $class->handle_request;
109 return $cgi->restore->response;
114 =head2 remote_request
116 Do an actual remote request using LWP.
122 require LWP::UserAgent;
124 my $request = Catalyst::Utils::request( shift(@_) );
125 my $server = URI->new( $ENV{CATALYST_SERVER} );
127 if ( $server->path =~ m|^(.+)?/$| ) {
128 $server->path("$1"); # need to be quoted
131 $request->uri->scheme( $server->scheme );
132 $request->uri->host( $server->host );
133 $request->uri->port( $server->port );
134 $request->uri->path( $server->path . $request->uri->path );
138 $agent = LWP::UserAgent->new(
147 return $agent->request($request);
156 Sebastian Riedel, C<sri@cpan.org>
160 This program is free software, you can redistribute it and/or modify it under
161 the same terms as Perl itself.