Skip to content

Commit 0b144dd

Browse files
committedDec 1, 2011
Convert this from a WEBGUI_LIVE test to using Test::WWW::Mechanize::PSGI.
1 parent 7f91293 commit 0b144dd

File tree

1 file changed

+38
-33
lines changed

1 file changed

+38
-33
lines changed
 

‎t/Asset/Redirect/mech.t

+38-33
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,20 @@ use WebGUI::Test; # Must use this before any other WebGUI modules
1919
use WebGUI::Asset;
2020
use WebGUI::VersionTag;
2121
use WebGUI::Session;
22-
plan skip_all => 'set WEBGUI_LIVE to enable this test' unless $ENV{WEBGUI_LIVE};
22+
use WebGUI::Test::Mechanize;
2323

2424
#----------------------------------------------------------------------------
2525
# Init
2626
my $session = WebGUI::Test->session;
2727

28-
# Override some settings to make things easier to test
29-
# userFunctionStyleId
30-
$session->setting->set( 'userFunctionStyleId', 'PBtmpl0000000000000132' );
31-
# specialState
32-
$session->setting->set( 'specialState', '' );
33-
3428
# Create a user for testing purposes
3529
my $user = WebGUI::User->new( $session, "new" );
3630
WebGUI::Test->addToCleanup($user);
3731
$user->username( 'dufresne' );
3832
my $identifier = 'ritahayworth';
3933
my $auth = WebGUI::Operation::Auth::getInstance( $session, $user->authMethod, $user->userId );
4034
$auth->saveParams( $user->userId, $user->authMethod, {
41-
'identifier' => Digest::MD5::md5_base64( $identifier ),
35+
'identifier' => Digest::MD5::md5_base64( $identifier ),
4236
});
4337

4438
my ($mech, $redirect, $response);
@@ -52,40 +46,39 @@ my $redirectUrl = time . "shawshank";
5246
my $testContent = "Perhaps if you've gone this far, you'd be willing to go further.";
5347
my $snippetUrl = time . "zejuatenejo";
5448
my $redirectToUrl = $snippetUrl . "?name=value";
55-
my $redirectToAsset
49+
my $redirectToAsset
5650
= WebGUI::Test->asset(
57-
className => 'WebGUI::Asset::Snippet',
51+
className => 'WebGUI::Asset::Snippet',
5852
url => $snippetUrl,
5953
snippet => $testContent,
6054
);
55+
my $tag1 = WebGUI::VersionTag->getWorking($session);
56+
WebGUI::Test->addToCleanup($tag1);
57+
$tag1->commit;
58+
$redirectToAsset = $redirectToAsset->cloneFromDb;
6159

6260
my $count = time; # A known count for url uniqueness
6361

6462
#----------------------------------------------------------------------------
6563
# Tests
6664

67-
if ( !eval { require Test::WWW::Mechanize; 1; } ) {
68-
plan skip_all => 'Cannot load Test::WWW::Mechanize. Will not test.';
69-
}
70-
$mech = Test::WWW::Mechanize->new;
71-
$mech->get( $baseUrl );
72-
if ( !$mech->success ) {
73-
plan skip_all => "Cannot load URL '$baseUrl'. Will not test.";
74-
}
75-
76-
plan tests => 12; # Increment this number for each test you create
77-
7865
#----------------------------------------------------------------------------
7966
# Test operation with a public Redirect
80-
$redirect
67+
$redirect
8168
= WebGUI::Test->asset(
8269
className => 'WebGUI::Asset::Redirect',
8370
redirectUrl => $redirectToUrl,
84-
url => $redirectUrl . $count++,
71+
url => $redirectUrl . ++$count,
8572
);
86-
87-
$mech = Test::WWW::Mechanize->new;
88-
$mech->get_ok( $baseUrl . $redirectUrl . $count, "We get the redirect" );
73+
my $tag2 = WebGUI::VersionTag->getWorking($session);
74+
WebGUI::Test->addToCleanup($tag2);
75+
$tag2->commit;
76+
$redirect = $redirect->cloneFromDb;
77+
78+
$mech = WebGUI::Test::Mechanize->new( config => WebGUI::Test->file );
79+
$mech->get_ok('/', 'initialize mech object with session');
80+
$mech->get_ok($snippetUrl, 'snippet can be fetched');
81+
$mech->get_ok( $redirectUrl . $count, "We get the redirect" );
8982
$mech->content_contains( $testContent, "We made it to the snippet" );
9083

9184
$response = $mech->res->previous;
@@ -102,13 +95,18 @@ $redirect
10295
= WebGUI::Test->asset(
10396
className => 'WebGUI::Asset::Redirect',
10497
redirectUrl => $redirectToUrl,
105-
url => $redirectUrl . $count++,
98+
url => $redirectUrl . ++$count,
10699
groupIdView => 2,
107100
groupIdEdit => 3,
108101
);
109102

110-
$mech = Test::WWW::Mechanize->new;
111-
$mech->get( $baseUrl . $redirectUrl . $count );
103+
my $tag = WebGUI::VersionTag->getWorking($session);
104+
$tag->commit;
105+
WebGUI::Test->addToCleanup($tag);
106+
$redirect = $redirect->cloneFromDb;
107+
108+
$mech = WebGUI::Test::Mechanize->new( config => WebGUI::Test->file );
109+
$mech->get( $baseUrl . $redirectUrl . $count );
112110
$mech->submit_form_ok( {
113111
with_fields => {
114112
username => $user->username,
@@ -127,21 +125,26 @@ is(
127125

128126

129127
#----------------------------------------------------------------------------
130-
# Test operation with a private Redirect through a login with translate
128+
# Test operation with a private Redirect through a login with translate
131129
# query params
132130
$redirect
133131
= WebGUI::Test->asset(
134132
className => 'WebGUI::Asset::Redirect',
135133
redirectUrl => $redirectToUrl,
136-
url => $redirectUrl . $count++,
134+
url => $redirectUrl . ++$count,
137135
groupIdView => 2,
138136
groupIdEdit => 3,
139137
forwardQueryParams => 1,
140138
);
141139

140+
my $tag = WebGUI::VersionTag->getWorking($session);
141+
$tag->commit;
142+
WebGUI::Test->addToCleanup($tag);
143+
$redirect = $redirect->cloneFromDb;
144+
142145
my $extraParams = 'extra=hi';
143-
$mech = Test::WWW::Mechanize->new;
144-
$mech->get( $baseUrl . $redirectUrl . $count . '?' . $extraParams );
146+
$mech = WebGUI::Test::Mechanize->new( config => WebGUI::Test->file );
147+
$mech->get( $baseUrl . $redirectUrl . $count . '?' . $extraParams );
145148
$mech->submit_form_ok( {
146149
with_fields => {
147150
username => $user->username,
@@ -161,4 +164,6 @@ TODO: {
161164
);
162165
};
163166

167+
done_testing;
168+
164169
#vim:ft=perl

0 commit comments

Comments
 (0)
Please sign in to comment.