Convert this from a WEBGUI_LIVE test to using Test::WWW::Mechanize::PSGI.
This commit is contained in:
parent
7f912931d5
commit
0b144dd89c
1 changed files with 37 additions and 32 deletions
|
|
@ -19,18 +19,12 @@ use WebGUI::Test; # Must use this before any other WebGUI modules
|
|||
use WebGUI::Asset;
|
||||
use WebGUI::VersionTag;
|
||||
use WebGUI::Session;
|
||||
plan skip_all => 'set WEBGUI_LIVE to enable this test' unless $ENV{WEBGUI_LIVE};
|
||||
use WebGUI::Test::Mechanize;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Init
|
||||
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
|
||||
my $user = WebGUI::User->new( $session, "new" );
|
||||
WebGUI::Test->addToCleanup($user);
|
||||
|
|
@ -58,34 +52,33 @@ my $redirectToAsset
|
|||
url => $snippetUrl,
|
||||
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
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# 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
|
||||
$redirect
|
||||
= WebGUI::Test->asset(
|
||||
className => 'WebGUI::Asset::Redirect',
|
||||
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->get_ok( $baseUrl . $redirectUrl . $count, "We get the redirect" );
|
||||
$mech = WebGUI::Test::Mechanize->new( config => WebGUI::Test->file );
|
||||
$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" );
|
||||
|
||||
$response = $mech->res->previous;
|
||||
|
|
@ -102,12 +95,17 @@ $redirect
|
|||
= WebGUI::Test->asset(
|
||||
className => 'WebGUI::Asset::Redirect',
|
||||
redirectUrl => $redirectToUrl,
|
||||
url => $redirectUrl . $count++,
|
||||
url => $redirectUrl . ++$count,
|
||||
groupIdView => 2,
|
||||
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->submit_form_ok( {
|
||||
with_fields => {
|
||||
|
|
@ -133,14 +131,19 @@ $redirect
|
|||
= WebGUI::Test->asset(
|
||||
className => 'WebGUI::Asset::Redirect',
|
||||
redirectUrl => $redirectToUrl,
|
||||
url => $redirectUrl . $count++,
|
||||
url => $redirectUrl . ++$count,
|
||||
groupIdView => 2,
|
||||
groupIdEdit => 3,
|
||||
forwardQueryParams => 1,
|
||||
);
|
||||
|
||||
my $tag = WebGUI::VersionTag->getWorking($session);
|
||||
$tag->commit;
|
||||
WebGUI::Test->addToCleanup($tag);
|
||||
$redirect = $redirect->cloneFromDb;
|
||||
|
||||
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->submit_form_ok( {
|
||||
with_fields => {
|
||||
|
|
@ -161,4 +164,6 @@ TODO: {
|
|||
);
|
||||
};
|
||||
|
||||
done_testing;
|
||||
|
||||
#vim:ft=perl
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue