@@ -19,26 +19,20 @@ use WebGUI::Test; # Must use this before any other WebGUI modules
19
19
use WebGUI::Asset;
20
20
use WebGUI::VersionTag;
21
21
use WebGUI::Session;
22
- plan skip_all => ' set WEBGUI_LIVE to enable this test ' unless $ENV { WEBGUI_LIVE } ;
22
+ use WebGUI::Test::Mechanize ;
23
23
24
24
# ----------------------------------------------------------------------------
25
25
# Init
26
26
my $session = WebGUI::Test-> session;
27
27
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
-
34
28
# Create a user for testing purposes
35
29
my $user = WebGUI::User-> new( $session , " new" );
36
30
WebGUI::Test-> addToCleanup($user );
37
31
$user -> username( ' dufresne' );
38
32
my $identifier = ' ritahayworth' ;
39
33
my $auth = WebGUI::Operation::Auth::getInstance( $session , $user -> authMethod, $user -> userId );
40
34
$auth -> saveParams( $user -> userId, $user -> authMethod, {
41
- ' identifier' => Digest::MD5::md5_base64( $identifier ),
35
+ ' identifier' => Digest::MD5::md5_base64( $identifier ),
42
36
});
43
37
44
38
my ($mech , $redirect , $response );
@@ -52,40 +46,39 @@ my $redirectUrl = time . "shawshank";
52
46
my $testContent = " Perhaps if you've gone this far, you'd be willing to go further." ;
53
47
my $snippetUrl = time . " zejuatenejo" ;
54
48
my $redirectToUrl = $snippetUrl . " ?name=value" ;
55
- my $redirectToAsset
49
+ my $redirectToAsset
56
50
= WebGUI::Test-> asset(
57
- className => ' WebGUI::Asset::Snippet' ,
51
+ className => ' WebGUI::Asset::Snippet' ,
58
52
url => $snippetUrl ,
59
53
snippet => $testContent ,
60
54
);
55
+ my $tag1 = WebGUI::VersionTag-> getWorking($session );
56
+ WebGUI::Test-> addToCleanup($tag1 );
57
+ $tag1 -> commit;
58
+ $redirectToAsset = $redirectToAsset -> cloneFromDb;
61
59
62
60
my $count = time ; # A known count for url uniqueness
63
61
64
62
# ----------------------------------------------------------------------------
65
63
# Tests
66
64
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
-
78
65
# ----------------------------------------------------------------------------
79
66
# Test operation with a public Redirect
80
- $redirect
67
+ $redirect
81
68
= WebGUI::Test-> asset(
82
69
className => ' WebGUI::Asset::Redirect' ,
83
70
redirectUrl => $redirectToUrl ,
84
- url => $redirectUrl . $count ++ ,
71
+ url => $redirectUrl . ++ $count ,
85
72
);
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" );
89
82
$mech -> content_contains( $testContent , " We made it to the snippet" );
90
83
91
84
$response = $mech -> res-> previous;
@@ -102,13 +95,18 @@ $redirect
102
95
= WebGUI::Test-> asset(
103
96
className => ' WebGUI::Asset::Redirect' ,
104
97
redirectUrl => $redirectToUrl ,
105
- url => $redirectUrl . $count ++ ,
98
+ url => $redirectUrl . ++ $count ,
106
99
groupIdView => 2,
107
100
groupIdEdit => 3,
108
101
);
109
102
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 );
112
110
$mech -> submit_form_ok( {
113
111
with_fields => {
114
112
username => $user -> username,
@@ -127,21 +125,26 @@ is(
127
125
128
126
129
127
# ----------------------------------------------------------------------------
130
- # Test operation with a private Redirect through a login with translate
128
+ # Test operation with a private Redirect through a login with translate
131
129
# query params
132
130
$redirect
133
131
= WebGUI::Test-> asset(
134
132
className => ' WebGUI::Asset::Redirect' ,
135
133
redirectUrl => $redirectToUrl ,
136
- url => $redirectUrl . $count ++ ,
134
+ url => $redirectUrl . ++ $count ,
137
135
groupIdView => 2,
138
136
groupIdEdit => 3,
139
137
forwardQueryParams => 1,
140
138
);
141
139
140
+ my $tag = WebGUI::VersionTag-> getWorking($session );
141
+ $tag -> commit;
142
+ WebGUI::Test-> addToCleanup($tag );
143
+ $redirect = $redirect -> cloneFromDb;
144
+
142
145
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 );
145
148
$mech -> submit_form_ok( {
146
149
with_fields => {
147
150
username => $user -> username,
@@ -161,4 +164,6 @@ TODO: {
161
164
);
162
165
};
163
166
167
+ done_testing;
168
+
164
169
# vim:ft=perl
0 commit comments