17
17
use strict;
18
18
use Test::More;
19
19
use WebGUI::Test; # Must use this before any other WebGUI modules
20
+ use WebGUI::Test::Mechanize; # Must use this before any other WebGUI modules
20
21
use WebGUI::Session;
21
22
use Test::Deep;
22
- plan skip_all => ' set WEBGUI_LIVE to enable this test' unless $ENV {WEBGUI_LIVE };
23
23
24
24
# ----------------------------------------------------------------------------
25
25
# Init
26
26
my $session = WebGUI::Test-> session;
27
27
my $node = WebGUI::Asset-> getImportNode( $session );
28
28
my @versionTags = ( WebGUI::VersionTag-> getWorking( $session ) );
29
29
30
- # Override some settings to make things easier to test
31
- # userFunctionStyleId
32
- $session -> setting-> set( ' userFunctionStyleId' , ' PBtmpl0000000000000132' );
33
- # specialState
34
- $session -> setting-> set( ' specialState' , ' ' );
35
-
36
30
# Create a user for testing purposes
37
31
my $user = WebGUI::User-> new( $session , " new" );
38
32
WebGUI::Test-> addToCleanup($user );
@@ -43,11 +37,6 @@ $auth->saveParams( $user->userId, $user->authMethod, {
43
37
' identifier' => Digest::MD5::md5_base64( $identifier ),
44
38
});
45
39
46
- my ($mech , $redirect , $response );
47
-
48
- # Get the site's base URL
49
- my $baseUrl = ' http://' . $session -> config-> get(' sitename' )-> [0];
50
-
51
40
my $i18n = WebGUI::International-> new( $session , ' Asset_GalleryAlbum' );
52
41
53
42
my $gallery
@@ -66,42 +55,41 @@ WebGUI::Test->addToCleanup(@versionTags);
66
55
if ( !eval { require Test::WWW::Mechanize; 1; } ) {
67
56
plan skip_all => ' Cannot load Test::WWW::Mechanize. Will not test.' ;
68
57
}
69
- $mech = Test::WWW::Mechanize-> new;
70
- $mech -> get( $baseUrl );
71
- if ( !$mech -> success ) {
72
- plan skip_all => " Cannot load URL '$baseUrl '. Will not test." ;
73
- }
58
+ my $mech = WebGUI::Test::Mechanize-> new( config => WebGUI::Test-> file );
59
+ $mech -> get_ok( ' /' );
74
60
75
61
# ----------------------------------------------------------------------------
76
62
# Visitor user cannot add albums
77
- $mech = Test::WWW::Mechanize-> new;
78
- $mech -> get( $baseUrl . $gallery -> getUrl(' func=add;class=WebGUI::Asset::Wobject::GalleryAlbum' ) );
79
-
80
- # Should contain the Log In form
63
+ $mech -> get( $gallery -> getUrl(' func=add;className=WebGUI::Asset::Wobject::GalleryAlbum' ) );
64
+ ok $mech -> res-> is_error, ' HTTP error returned from server' ;
81
65
$mech -> content_contains( " Permission Denied" );
82
66
83
67
# ----------------------------------------------------------------------------
84
68
# Registered User can add albums
85
- $mech = getMechLogin( $baseUrl , $user , $identifier );
69
+ $mech -> session-> user({ user => $user });
70
+ WebGUI::Test-> addToCleanup($mech -> session);
86
71
87
72
# Complete the GalleryAlbum edit form
88
73
my $properties = {
89
74
title => ' Gallery Album' ,
90
75
description => ' This is a new Gallery Album' ,
91
76
};
92
77
93
- $mech -> get_ok( $baseUrl . $ gallery-> getUrl(' func=add;class =WebGUI::Asset::Wobject::GalleryAlbum' ) );
78
+ $mech -> get_ok( $gallery -> getUrl(' func=add;className =WebGUI::Asset::Wobject::GalleryAlbum' ) );
94
79
$mech -> submit_form_ok( {
95
80
with_fields => $properties ,
96
81
}, ' Sent GalleryAlbum edit form' );
97
82
83
+ my $added_tag = WebGUI::VersionTag-> getWorking($mech -> session);
84
+ WebGUI::Test-> addToCleanup($added_tag );
85
+
98
86
# Shows the confirmation page
99
87
$mech -> content_contains(
100
88
$i18n -> get( ' what next' ),
101
89
' Shows message about what next' ,
102
90
);
103
91
$mech -> content_contains(
104
- q{ func=add;class =WebGUI::Asset::File::GalleryFile::Photo} ,
92
+ q{ func=add;className =WebGUI::Asset::File::GalleryFile::Photo} ,
105
93
' Shows link to add a Photo' ,
106
94
);
107
95
@@ -121,11 +109,14 @@ my $album = $gallery->getFirstChild;
121
109
122
110
# Add single photo to this album. No need to commit since auto-commit was
123
111
# enabled for the Gallery asset.
112
+ my $tag = WebGUI::VersionTag-> getWorking($session );
124
113
my $photo
125
114
= $album -> addChild({
126
115
className => " WebGUI::Asset::File::GalleryFile::Photo" ,
127
116
});
128
117
my $photoId = $photo -> getId;
118
+ $tag -> commit;
119
+ WebGUI::Test-> addToCleanup($tag );
129
120
130
121
# Attach image file to photo asset (setFile also makes download versions)
131
122
$photo -> setFile( WebGUI::Test-> getTestCollateralPath(" rotation_test.png" ) );
@@ -138,7 +129,7 @@ foreach my $file ( @{$storage->getFiles('showAll') } ) {
138
129
}
139
130
140
131
# Rotate photo (i.e. all attached images) by 90° CW
141
- $mech -> get_ok( $baseUrl . $ album-> getUrl(' func=edit' ), ' Request GalleryAlbum edit screen' );
132
+ $mech -> get_ok( $album -> getUrl(' func=edit' ), ' Request GalleryAlbum edit screen' );
142
133
# Select the proper form
143
134
$mech -> form_name( ' galleryAlbumEdit' );
144
135
# Try to click the "rotate right" button
@@ -175,25 +166,3 @@ cmp_deeply( \@oldDims, \@newerDims, "Check if all files were rotated by 90° CCW
175
166
}
176
167
177
168
done_testing;
178
-
179
- # ----------------------------------------------------------------------------
180
- # getMechLogin( baseUrl, WebGUI::User, "identifier" )
181
- # Returns a Test::WWW::Mechanize session after logging in the given user using
182
- # the given identifier (password)
183
- # baseUrl is a fully-qualified URL to the site to login to
184
- sub getMechLogin {
185
- my $baseUrl = shift ;
186
- my $user = shift ;
187
- my $identifier = shift ;
188
-
189
- my $mech = Test::WWW::Mechanize-> new;
190
- $mech -> get( $baseUrl . ' ?op=auth;method=displayLogin' );
191
- $mech -> submit_form(
192
- with_fields => {
193
- username => $user -> username,
194
- identifier => $identifier ,
195
- },
196
- );
197
-
198
- return $mech ;
199
- }
0 commit comments