Convert this from a WEBGUI_LIVE test to using Test::WWW::Mechanize::PSGI.

This commit is contained in:
Colin Kuskie 2011-12-01 12:09:34 -08:00
parent 7f912931d5
commit 0b144dd89c

View file

@ -19,18 +19,12 @@ use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Asset; use WebGUI::Asset;
use WebGUI::VersionTag; use WebGUI::VersionTag;
use WebGUI::Session; use WebGUI::Session;
plan skip_all => 'set WEBGUI_LIVE to enable this test' unless $ENV{WEBGUI_LIVE}; use WebGUI::Test::Mechanize;
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
# Init # Init
my $session = WebGUI::Test->session; my $session = WebGUI::Test->session;
# Override some settings to make things easier to test
# userFunctionStyleId
$session->setting->set( 'userFunctionStyleId', 'PBtmpl0000000000000132' );
# specialState
$session->setting->set( 'specialState', '' );
# Create a user for testing purposes # Create a user for testing purposes
my $user = WebGUI::User->new( $session, "new" ); my $user = WebGUI::User->new( $session, "new" );
WebGUI::Test->addToCleanup($user); WebGUI::Test->addToCleanup($user);
@ -58,34 +52,33 @@ my $redirectToAsset
url => $snippetUrl, url => $snippetUrl,
snippet => $testContent, snippet => $testContent,
); );
my $tag1 = WebGUI::VersionTag->getWorking($session);
WebGUI::Test->addToCleanup($tag1);
$tag1->commit;
$redirectToAsset = $redirectToAsset->cloneFromDb;
my $count = time; # A known count for url uniqueness my $count = time; # A known count for url uniqueness
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
# Tests # Tests
if ( !eval { require Test::WWW::Mechanize; 1; } ) {
plan skip_all => 'Cannot load Test::WWW::Mechanize. Will not test.';
}
$mech = Test::WWW::Mechanize->new;
$mech->get( $baseUrl );
if ( !$mech->success ) {
plan skip_all => "Cannot load URL '$baseUrl'. Will not test.";
}
plan tests => 12; # Increment this number for each test you create
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
# Test operation with a public Redirect # Test operation with a public Redirect
$redirect $redirect
= WebGUI::Test->asset( = WebGUI::Test->asset(
className => 'WebGUI::Asset::Redirect', className => 'WebGUI::Asset::Redirect',
redirectUrl => $redirectToUrl, redirectUrl => $redirectToUrl,
url => $redirectUrl . $count++, url => $redirectUrl . ++$count,
); );
my $tag2 = WebGUI::VersionTag->getWorking($session);
WebGUI::Test->addToCleanup($tag2);
$tag2->commit;
$redirect = $redirect->cloneFromDb;
$mech = Test::WWW::Mechanize->new; $mech = WebGUI::Test::Mechanize->new( config => WebGUI::Test->file );
$mech->get_ok( $baseUrl . $redirectUrl . $count, "We get the redirect" ); $mech->get_ok('/', 'initialize mech object with session');
$mech->get_ok($snippetUrl, 'snippet can be fetched');
$mech->get_ok( $redirectUrl . $count, "We get the redirect" );
$mech->content_contains( $testContent, "We made it to the snippet" ); $mech->content_contains( $testContent, "We made it to the snippet" );
$response = $mech->res->previous; $response = $mech->res->previous;
@ -102,12 +95,17 @@ $redirect
= WebGUI::Test->asset( = WebGUI::Test->asset(
className => 'WebGUI::Asset::Redirect', className => 'WebGUI::Asset::Redirect',
redirectUrl => $redirectToUrl, redirectUrl => $redirectToUrl,
url => $redirectUrl . $count++, url => $redirectUrl . ++$count,
groupIdView => 2, groupIdView => 2,
groupIdEdit => 3, groupIdEdit => 3,
); );
$mech = Test::WWW::Mechanize->new; my $tag = WebGUI::VersionTag->getWorking($session);
$tag->commit;
WebGUI::Test->addToCleanup($tag);
$redirect = $redirect->cloneFromDb;
$mech = WebGUI::Test::Mechanize->new( config => WebGUI::Test->file );
$mech->get( $baseUrl . $redirectUrl . $count ); $mech->get( $baseUrl . $redirectUrl . $count );
$mech->submit_form_ok( { $mech->submit_form_ok( {
with_fields => { with_fields => {
@ -133,14 +131,19 @@ $redirect
= WebGUI::Test->asset( = WebGUI::Test->asset(
className => 'WebGUI::Asset::Redirect', className => 'WebGUI::Asset::Redirect',
redirectUrl => $redirectToUrl, redirectUrl => $redirectToUrl,
url => $redirectUrl . $count++, url => $redirectUrl . ++$count,
groupIdView => 2, groupIdView => 2,
groupIdEdit => 3, groupIdEdit => 3,
forwardQueryParams => 1, forwardQueryParams => 1,
); );
my $tag = WebGUI::VersionTag->getWorking($session);
$tag->commit;
WebGUI::Test->addToCleanup($tag);
$redirect = $redirect->cloneFromDb;
my $extraParams = 'extra=hi'; my $extraParams = 'extra=hi';
$mech = Test::WWW::Mechanize->new; $mech = WebGUI::Test::Mechanize->new( config => WebGUI::Test->file );
$mech->get( $baseUrl . $redirectUrl . $count . '?' . $extraParams ); $mech->get( $baseUrl . $redirectUrl . $count . '?' . $extraParams );
$mech->submit_form_ok( { $mech->submit_form_ok( {
with_fields => { with_fields => {
@ -161,4 +164,6 @@ TODO: {
); );
}; };
done_testing;
#vim:ft=perl #vim:ft=perl