Merge branch 'WebGUI8' of github.com:plainblack/webgui into 8

Conflicts:
	lib/WebGUI.pm
	lib/WebGUI/Auth/WebGUI.pm
	sbin/findBrokenAssets.pl
	sbin/testEnvironment.pl
This commit is contained in:
Doug Bell 2011-05-13 18:20:52 -05:00
commit 677ac978b6
89 changed files with 1064 additions and 448 deletions

View file

@ -45,6 +45,8 @@ use Scope::Guard;
use WebGUI::Paths -inc;
use namespace::clean;
use WebGUI::User;
use WebGUI::Test::Mechanize;
use HTTP::Request::Common;
our @EXPORT = qw(cleanupGuard addToCleanup);
our @EXPORT_OK = qw(session config collateral);
@ -378,6 +380,7 @@ below.
# I think that getPage should be entirely replaced with calles to Plack::Test::test_psgi
# - testing with the callback is better and it means we can run on any backend
# I agree.
sub getPage {
my $class = shift;
my $actor = shift; # The actor to work on
@ -432,6 +435,82 @@ sub getPage {
return join '', @{$session->response->body};
}
=head2 getPage2 ( request|url [, opts] )
Get the entire response from a page request using L<WebGUI::Test::Mechanize>.
This is a wrapper around L<WebGUI::Test::Mechanize> for the purpose of easing conversion of tests that use C<getPage>.
Accepts an L<HTTP::Request> object as an argument, which cooked up auth info will be added to.
An L<HTTP::Request> will be constructed from a simple relative URL such as C<home> if a string is passed instead.
Returns a string containing the body of the requested page.
C<options> is a hash reference of options with keys outlined below.
user => A user object to set for this request
userId => A userId to set for this request
formParams => A hash reference of form parameters
Compared to C<getPage> above, these are not yet supported:
uploads
args
=cut
sub getPage2 {
my $class = shift;
my $request = shift;
my $optionsRef = shift; # A hashref of options
# args => Array ref of args to the page sub
# user => A user object to set
# userId => A user ID to set, "user" takes
# precedence
die "not supported" if exists $optionsRef->{args};
die "not supported" if exists $optionsRef->{uploads};
my $session = $CLASS->session;
# Save state
my $oldUser = $session->user;
my $oldRequest = $session->request;
my $mech = WebGUI::Test::Mechanize->new( config => WebGUI::Test->file );
# Set the appropriate user
if ($optionsRef->{user}) {
$mech->session->user({ user => $optionsRef->{user} });
}
elsif ($optionsRef->{userId}) {
$mech->session->user({ userId => $optionsRef->{userId} });
}
$session->user->uncache;
$mech->session or die; # force a session to be created for the request
my $session_id = $mech->sessionId or die;
# Build or fix up a request object
if( ! eval { $request->isa('HTTP::Request') } ) {
if( $optionsRef->{formParams} ) {
$request = HTTP::Request::Common::POST( "http://127.0.0.1/$request", [ %{ $optionsRef->{formParams} } ] ) or die;
}
else {
$request = HTTP::Request->new( GET => "http://127.0.0.1/$request" ) or die;
}
}
$request->header( 'Set-Cookie3' => qq{wgSession=$session_id; path="/"; domain=127.0.0.1; path_spec; discard; version=0} );
$mech->request( $request );
# Restore the former user and request
$session->user({ user => $oldUser });
$session->{_request} = $oldRequest; # dubious about this; if we're going to try to support requests inside of other requests, it should be tested and actually supported rather than just some optimistic arm waving done
return $mech->response->decoded_content;
}
#----------------------------------------------------------------------------
=head2 getTestCollateralPath ( [filename] )