1 package Catalyst::Test;
6 use Catalyst::Exception;
12 Catalyst::Test - Test Catalyst Applications
20 use Catalyst::Test 'TestApp';
21 request('index.html');
24 # Run tests against a remote server
25 CATALYST_SERVER='http://localhost:3000/' prove -r -l lib/ t/
27 # Tests with inline apps need to use Catalyst::Engine::Test
33 my ( $self, $c ) = @_;
34 $c->res->output('bar');
41 use Test::More tests => 1;
42 use Catalyst::Test 'TestApp';
44 ok( get('/foo') =~ /bar/ );
48 Test Catalyst Applications.
56 my $content = get('foo/bar?test=1');
60 Returns a C<HTTP::Response> object.
62 my $res = request('foo/bar?test=1');
70 my ( $get, $request );
72 if ( $ENV{CATALYST_SERVER} ) {
73 $request = sub { remote_request(@_) };
74 $get = sub { remote_request(@_)->content };
78 unless( Class::Inspector->loaded( $class ) ) {
79 require Class::Inspector->filename( $class );
83 $request = sub { local_request( $class, @_ ) };
84 $get = sub { local_request( $class, @_ )->content };
88 my $caller = caller(0);
89 *{"$caller\::request"} = $request;
90 *{"$caller\::get"} = $get;
100 require HTTP::Request::AsCGI;
102 my $request = Catalyst::Utils::request( shift(@_) );
103 my $cgi = HTTP::Request::AsCGI->new( $request, %ENV )->setup;
105 $class->handle_request;
107 return $cgi->restore->response;
112 =head2 remote_request
114 Do an actual remote request using LWP.
120 require LWP::UserAgent;
122 my $request = Catalyst::Utils::request( shift(@_) );
123 my $server = URI->new( $ENV{CATALYST_SERVER} );
125 if ( $server->path =~ m|^(.+)?/$| ) {
126 $server->path("$1"); # need to be quoted
129 $request->uri->scheme( $server->scheme );
130 $request->uri->host( $server->host );
131 $request->uri->port( $server->port );
132 $request->uri->path( $server->path . $request->uri->path );
136 $agent = LWP::UserAgent->new(
145 return $agent->request($request);
154 Sebastian Riedel, C<sri@cpan.org>
158 This program is free software, you can redistribute it and/or modify it under
159 the same terms as Perl itself.