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::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);
|
||||||
|
|
@ -38,7 +32,7 @@ $user->username( 'dufresne' );
|
||||||
my $identifier = 'ritahayworth';
|
my $identifier = 'ritahayworth';
|
||||||
my $auth = WebGUI::Operation::Auth::getInstance( $session, $user->authMethod, $user->userId );
|
my $auth = WebGUI::Operation::Auth::getInstance( $session, $user->authMethod, $user->userId );
|
||||||
$auth->saveParams( $user->userId, $user->authMethod, {
|
$auth->saveParams( $user->userId, $user->authMethod, {
|
||||||
'identifier' => Digest::MD5::md5_base64( $identifier ),
|
'identifier' => Digest::MD5::md5_base64( $identifier ),
|
||||||
});
|
});
|
||||||
|
|
||||||
my ($mech, $redirect, $response);
|
my ($mech, $redirect, $response);
|
||||||
|
|
@ -52,40 +46,39 @@ my $redirectUrl = time . "shawshank";
|
||||||
my $testContent = "Perhaps if you've gone this far, you'd be willing to go further.";
|
my $testContent = "Perhaps if you've gone this far, you'd be willing to go further.";
|
||||||
my $snippetUrl = time . "zejuatenejo";
|
my $snippetUrl = time . "zejuatenejo";
|
||||||
my $redirectToUrl = $snippetUrl . "?name=value";
|
my $redirectToUrl = $snippetUrl . "?name=value";
|
||||||
my $redirectToAsset
|
my $redirectToAsset
|
||||||
= WebGUI::Test->asset(
|
= WebGUI::Test->asset(
|
||||||
className => 'WebGUI::Asset::Snippet',
|
className => 'WebGUI::Asset::Snippet',
|
||||||
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,13 +95,18 @@ $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);
|
||||||
$mech->get( $baseUrl . $redirectUrl . $count );
|
$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( {
|
$mech->submit_form_ok( {
|
||||||
with_fields => {
|
with_fields => {
|
||||||
username => $user->username,
|
username => $user->username,
|
||||||
|
|
@ -127,21 +125,26 @@ is(
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Test operation with a private Redirect through a login with translate
|
# Test operation with a private Redirect through a login with translate
|
||||||
# query params
|
# query params
|
||||||
$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,
|
||||||
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 => {
|
||||||
username => $user->username,
|
username => $user->username,
|
||||||
|
|
@ -161,4 +164,6 @@ TODO: {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
done_testing;
|
||||||
|
|
||||||
#vim:ft=perl
|
#vim:ft=perl
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue