@@ -17,15 +17,14 @@ use Test::More;
17
17
use Test::Deep;
18
18
19
19
use WebGUI::Test; # Must use this before any other WebGUI modules
20
+ use WebGUI::Test::Mechanize;
20
21
use WebGUI::Asset;
21
22
use WebGUI::Asset::Wobject::Gallery;
22
23
use WebGUI::Asset::Wobject::GalleryAlbum;
23
24
use WebGUI::Asset::File::GalleryFile::Photo;
24
25
use WebGUI::VersionTag;
25
26
use WebGUI::Session;
26
27
27
- plan skip_all => ' set WEBGUI_LIVE to enable this test' unless $ENV {WEBGUI_LIVE };
28
-
29
28
# ----------------------------------------------------------------------------
30
29
# Init
31
30
@@ -36,21 +35,10 @@ my $node = WebGUI::Asset->getImportNode( $session );
36
35
my $versionTag = WebGUI::VersionTag-> getWorking($session );
37
36
WebGUI::Test-> addToCleanup($versionTag );
38
37
39
- # Override some settings to make things easier to test
40
- # userFunctionStyleId
41
- $session -> setting-> set( ' userFunctionStyleId' , ' PBtmpl0000000000000132' );
42
- # specialState
43
- $session -> setting-> set( ' specialState' , ' ' );
44
-
45
38
# Create a user for testing purposes
46
39
my $user = WebGUI::User-> new( $session , " new" );
47
40
WebGUI::Test-> addToCleanup($user );
48
41
$user -> username( ' dufresne' . time );
49
- my $identifier = ' ritahayworth' ;
50
- my $auth = WebGUI::Operation::Auth::getInstance( $session , $user -> authMethod, $user -> userId );
51
- $auth -> saveParams( $user -> userId, $user -> authMethod, {
52
- ' identifier' => Digest::MD5::md5_base64( $identifier ),
53
- });
54
42
55
43
# Create gallery and a single album
56
44
my $gallery
@@ -75,43 +63,25 @@ my $album
75
63
# Commit assets for testing
76
64
$versionTag -> commit;
77
65
78
- # Get the site's base URL
79
- my $baseUrl = ' http://' . $session -> config-> get(' sitename' )-> [0];
80
-
81
- # Common variables
82
- my ( $mech , $photo );
83
-
84
66
85
67
# ----------------------------------------------------------------------------
86
68
# Tests
87
69
88
- if ( !eval { require Test::WWW::Mechanize; 1; } ) {
89
- plan skip_all => ' Cannot load Test::WWW::Mechanize. Will not test.' ;
90
- }
91
- $mech = Test::WWW::Mechanize-> new;
92
- $mech -> get( $baseUrl );
93
- if ( !$mech -> success ) {
94
- plan skip_all => " Cannot load URL '$baseUrl '. Will not test." ;
95
- }
96
-
97
- plan tests => 10; # Increment this number for each test you create
98
-
99
-
100
70
# ----------------------------------------------------------------------------
101
71
# Test permissions for new photos
102
72
103
- $mech = Test::WWW ::Mechanize-> new;
73
+ my $mech = WebGUI::Test ::Mechanize-> new( config => WebGUI::Test -> file) ;
104
74
105
75
# Save a new photo
106
- $mech -> get( $baseUrl . $ album-> getUrl(" func=add;class =WebGUI::Asset::File::GalleryFile::Photo" ) );
76
+ $mech -> get( $album -> getUrl(" func=add;className =WebGUI::Asset::File::GalleryFile::Photo" ) );
107
77
$mech -> content_lacks( ' value="editSave"' );
108
-
78
+ $mech -> content_contains( ' value="addSave" ' );
109
79
110
80
# ----------------------------------------------------------------------------
111
81
# Test editing existing photo
112
82
113
83
# Create single photo inside the album
114
- $photo
84
+ my $photo
115
85
= $album -> addChild({
116
86
className => " WebGUI::Asset::File::GalleryFile::Photo" ,
117
87
ownerUserId => $user -> getId,
@@ -137,10 +107,11 @@ my %properties = (
137
107
);
138
108
139
109
# Log in
140
- $mech = getMechLogin( $baseUrl , $user , $identifier );
110
+ $mech -> get(' /' ); # #Prime the pump to get a session;
111
+ $mech -> session-> user({ user => $user });
141
112
142
113
# Request photo edit view
143
- $mech -> get_ok( $baseUrl . $ photo-> getUrl(' func=edit' ), ' Request Photo edit view' );
114
+ $mech -> get_ok( $photo -> getUrl(' func=edit' ), ' Request Photo edit view' );
144
115
# Try to submit edit form
145
116
$mech -> submit_form_ok({
146
117
form_name => ' photoEdit' ,
@@ -170,7 +141,7 @@ $photo->setFile( WebGUI::Test->getTestCollateralPath("rotation_test.png") );
170
141
171
142
172
143
# Request photo edit view
173
- $mech -> get_ok( $baseUrl . $ photo-> getUrl(' func=edit;proceed=editParent' ), ' Request Photo edit view with "proceed=editParent"' );
144
+ $mech -> get_ok( $photo -> getUrl(' func=edit;proceed=editParent' ), ' Request Photo edit view with "proceed=editParent"' );
174
145
# Submit changes
175
146
$mech -> submit_form( form_name => ' photoEdit' );
176
147
# Currently, a redirect using the proceed parameter will not change the URL
@@ -183,8 +154,10 @@ $mech->content_contains( 'name="galleryAlbumEdit"', "Redirected to parent's edit
183
154
184
155
SKIP: {
185
156
skip " File control needs to be fixed to be more 508-compliant before this can be used" , 4;
186
- $mech = getMechLogin( $baseUrl , $user , $identifier );
187
- $mech -> get_ok( $baseUrl . $album -> getUrl(" func=add;class=WebGUI::Asset::File::GalleryFile::Photo" ) );
157
+ my $mech = WebGUI::Test::Mechanize-> new(config => WebGUI::Test-> file);
158
+ $mech -> get(' /' ); # #Prime the pump to get a session;
159
+ $mech -> session-> user({ user => $user });
160
+ $mech -> get_ok( $album -> getUrl(" func=add;className=WebGUI::Asset::File::GalleryFile::Photo" ) );
188
161
189
162
open my $file , ' <' , WebGUI::Test-> getTestCollateralPath( ' lamp.jpg' )
190
163
or die ( " Couldn't open test collateral 'lamp.jpg' for reading: $! " );
@@ -222,25 +195,4 @@ SKIP: {
222
195
);
223
196
}
224
197
225
-
226
- # ----------------------------------------------------------------------------
227
- # getMechLogin( baseUrl, WebGUI::User, "identifier" )
228
- # Returns a Test::WWW::Mechanize session after logging in the given user using
229
- # the given identifier (password)
230
- # baseUrl is a fully-qualified URL to the site to login to
231
- sub getMechLogin {
232
- my $baseUrl = shift ;
233
- my $user = shift ;
234
- my $identifier = shift ;
235
-
236
- my $mech = Test::WWW::Mechanize-> new;
237
- $mech -> get( $baseUrl . ' ?op=auth;method=displayLogin' );
238
- $mech -> submit_form(
239
- with_fields => {
240
- username => $user -> username,
241
- identifier => $identifier ,
242
- },
243
- );
244
-
245
- return $mech ;
246
- }
198
+ done_testing;
0 commit comments