Skip to content

Commit 7d75bf5

Browse files
committedDec 2, 2011
Update the GalleryFile/Photo/edit test for WEBGUI_LIVE.
1 parent e1f8b1d commit 7d75bf5

File tree

1 file changed

+14
-62
lines changed
  • t/Asset/File/GalleryFile/Photo

1 file changed

+14
-62
lines changed
 

‎t/Asset/File/GalleryFile/Photo/edit.t

+14-62
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@ use Test::More;
1717
use Test::Deep;
1818

1919
use WebGUI::Test; # Must use this before any other WebGUI modules
20+
use WebGUI::Test::Mechanize;
2021
use WebGUI::Asset;
2122
use WebGUI::Asset::Wobject::Gallery;
2223
use WebGUI::Asset::Wobject::GalleryAlbum;
2324
use WebGUI::Asset::File::GalleryFile::Photo;
2425
use WebGUI::VersionTag;
2526
use WebGUI::Session;
2627

27-
plan skip_all => 'set WEBGUI_LIVE to enable this test' unless $ENV{WEBGUI_LIVE};
28-
2928
#----------------------------------------------------------------------------
3029
# Init
3130

@@ -36,21 +35,10 @@ my $node = WebGUI::Asset->getImportNode( $session );
3635
my $versionTag = WebGUI::VersionTag->getWorking($session);
3736
WebGUI::Test->addToCleanup($versionTag);
3837

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-
4538
# Create a user for testing purposes
4639
my $user = WebGUI::User->new( $session, "new" );
4740
WebGUI::Test->addToCleanup($user);
4841
$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-
});
5442

5543
# Create gallery and a single album
5644
my $gallery
@@ -75,43 +63,25 @@ my $album
7563
# Commit assets for testing
7664
$versionTag->commit;
7765

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-
8466

8567
#----------------------------------------------------------------------------
8668
# Tests
8769

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-
10070
#----------------------------------------------------------------------------
10171
# Test permissions for new photos
10272

103-
$mech = Test::WWW::Mechanize->new;
73+
my $mech = WebGUI::Test::Mechanize->new(config => WebGUI::Test->file);
10474

10575
# 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") );
10777
$mech->content_lacks( 'value="editSave"' );
108-
78+
$mech->content_contains( 'value="addSave"' );
10979

11080
#----------------------------------------------------------------------------
11181
# Test editing existing photo
11282

11383
# Create single photo inside the album
114-
$photo
84+
my $photo
11585
= $album->addChild({
11686
className => "WebGUI::Asset::File::GalleryFile::Photo",
11787
ownerUserId => $user->getId,
@@ -137,10 +107,11 @@ my %properties = (
137107
);
138108

139109
# Log in
140-
$mech = getMechLogin( $baseUrl, $user, $identifier );
110+
$mech->get('/'); ##Prime the pump to get a session;
111+
$mech->session->user({ user => $user });
141112

142113
# 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' );
144115
# Try to submit edit form
145116
$mech->submit_form_ok({
146117
form_name => 'photoEdit',
@@ -170,7 +141,7 @@ $photo->setFile( WebGUI::Test->getTestCollateralPath("rotation_test.png") );
170141

171142

172143
# 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"' );
174145
# Submit changes
175146
$mech->submit_form( form_name => 'photoEdit' );
176147
# 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
183154

184155
SKIP: {
185156
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") );
188161

189162
open my $file, '<', WebGUI::Test->getTestCollateralPath( 'lamp.jpg' )
190163
or die( "Couldn't open test collateral 'lamp.jpg' for reading: $!" );
@@ -222,25 +195,4 @@ SKIP: {
222195
);
223196
}
224197

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

Comments
 (0)
Please sign in to comment.