1 package CXGN
::VHost
::Test
;
11 use CXGN
::DB
::Connection
;
15 CXGN::VHost::Test - Test CXGN web applications.
20 SGN_TEST_SERVER='http://sgn.localhost.localdomain/' prove -r -l lib/ t/
23 use CXGN::VHost::Test;
24 request('index.html');
30 Test CXGN web applications. This is basically a copy of
31 Catalyst::Test, tweaked to work with current CXGN web applications, if
32 you use this module your test script should be completely
41 my $content = get('foo/bar?test=1');
43 Note that this method doesn't follow redirects, so to test for a
44 correctly redirecting page you'll need to use a combination of this
45 method and the L<request> method below:
47 my $res = request('/'); # redirects to /y
48 warn $res->header('location');
50 my $uri = URI->new($res->header('location'));
51 is ( $uri->path , '/y');
52 my $content = get($uri->path);
56 Returns a C<HTTP::Response> object.
58 my $res = request('foo/bar?test=1');
63 use base qw
/Exporter/;
64 our @EXPORT = qw
/ request get /;
66 #< copied from Catalyst::Test
76 unless( $ENV{SGN_TEST_SERVER
} ) {
77 croak
"the SGN_TEST_SERVER environment variable must be set to use ".__PACKAGE__
;
80 die "SGN_TEST_SERVER env var must begin with http://\n"
81 unless $ENV{SGN_TEST_SERVER
} =~ m!^http://!;
83 ## Added an enviromental variable SGN_SERVER_TIMEOUT. In some machines load some pages
84 ## needs more than 60 s, so if it is better if it can be changed
86 my $timeout = $ENV{SGN_SERVER_TIMEOUT
} || 60;
88 require LWP
::UserAgent
;
90 my $request = Catalyst
::Utils
::request
( shift(@_) );
91 my $server = URI
->new( $ENV{SGN_TEST_SERVER
} );
93 if ( $server->path =~ m
|^(.+)?
/$| ) {
95 $server->path("$path") if $path; # need to be quoted
98 # the request path needs to be sanitised if $server is using a
99 # non-root path due to potential overlap between request path and
102 # If request path is '/', we have to add a trailing slash to the
104 my $add_trailing = $request->uri->path eq '/';
106 my @sp = split '/', $server->path;
107 my @rp = split '/', $request->uri->path;
108 shift @sp;shift @rp; # leading /
110 foreach my $sp (@sp) {
111 $sp eq $rp[0] ?
shift @rp : last
114 $request->uri->path(join '/', @rp);
118 if ( $add_trailing ) {
119 $request->uri->path( $request->uri->path . '/' );
123 $request->uri->scheme( $server->scheme );
124 $request->uri->host( $server->host );
125 $request->uri->port( $server->port );
126 $request->uri->path( $server->path . $request->uri->path );
130 $agent = LWP
::UserAgent
->new(
139 return $agent->request($request);
155 Robert Buels, E<lt>rmb32@cornell.eduE<gt>
157 =head1 COPYRIGHT & LICENSE
159 Copyright 2009 Boyce Thompson Institute for Plant Research
161 This program is free software; you can redistribute it and/or modify
162 it under the same terms as Perl itself.