Skip to content

Commit 4e8884c

Browse files
committedDec 1, 2011
WebGUI_LIVE test upgrade. Note, this test is leaking a version tag.
1 parent b242236 commit 4e8884c

File tree

1 file changed

+16
-47
lines changed
  • t/Asset/Wobject/GalleryAlbum

1 file changed

+16
-47
lines changed
 

‎t/Asset/Wobject/GalleryAlbum/edit.t

+16-47
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,16 @@
1717
use strict;
1818
use Test::More;
1919
use WebGUI::Test; # Must use this before any other WebGUI modules
20+
use WebGUI::Test::Mechanize; # Must use this before any other WebGUI modules
2021
use WebGUI::Session;
2122
use Test::Deep;
22-
plan skip_all => 'set WEBGUI_LIVE to enable this test' unless $ENV{WEBGUI_LIVE};
2323

2424
#----------------------------------------------------------------------------
2525
# Init
2626
my $session = WebGUI::Test->session;
2727
my $node = WebGUI::Asset->getImportNode( $session );
2828
my @versionTags = ( WebGUI::VersionTag->getWorking( $session ) );
2929

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-
3630
# Create a user for testing purposes
3731
my $user = WebGUI::User->new( $session, "new" );
3832
WebGUI::Test->addToCleanup($user);
@@ -43,11 +37,6 @@ $auth->saveParams( $user->userId, $user->authMethod, {
4337
'identifier' => Digest::MD5::md5_base64( $identifier ),
4438
});
4539

46-
my ($mech, $redirect, $response);
47-
48-
# Get the site's base URL
49-
my $baseUrl = 'http://' . $session->config->get('sitename')->[0];
50-
5140
my $i18n = WebGUI::International->new( $session, 'Asset_GalleryAlbum' );
5241

5342
my $gallery
@@ -66,42 +55,41 @@ WebGUI::Test->addToCleanup(@versionTags);
6655
if ( !eval { require Test::WWW::Mechanize; 1; } ) {
6756
plan skip_all => 'Cannot load Test::WWW::Mechanize. Will not test.';
6857
}
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( '/' );
7460

7561
#----------------------------------------------------------------------------
7662
# 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';
8165
$mech->content_contains( "Permission Denied" );
8266

8367
#----------------------------------------------------------------------------
8468
# Registered User can add albums
85-
$mech = getMechLogin( $baseUrl, $user, $identifier );
69+
$mech->session->user({ user => $user });
70+
WebGUI::Test->addToCleanup($mech->session);
8671

8772
# Complete the GalleryAlbum edit form
8873
my $properties = {
8974
title => 'Gallery Album',
9075
description => 'This is a new Gallery Album',
9176
};
9277

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') );
9479
$mech->submit_form_ok( {
9580
with_fields => $properties,
9681
}, 'Sent GalleryAlbum edit form' );
9782

83+
my $added_tag = WebGUI::VersionTag->getWorking($mech->session);
84+
WebGUI::Test->addToCleanup($added_tag);
85+
9886
# Shows the confirmation page
9987
$mech->content_contains(
10088
$i18n->get( 'what next' ),
10189
'Shows message about what next',
10290
);
10391
$mech->content_contains(
104-
q{func=add;class=WebGUI::Asset::File::GalleryFile::Photo},
92+
q{func=add;className=WebGUI::Asset::File::GalleryFile::Photo},
10593
'Shows link to add a Photo',
10694
);
10795

@@ -121,11 +109,14 @@ my $album = $gallery->getFirstChild;
121109

122110
# Add single photo to this album. No need to commit since auto-commit was
123111
# enabled for the Gallery asset.
112+
my $tag = WebGUI::VersionTag->getWorking($session);
124113
my $photo
125114
= $album->addChild({
126115
className => "WebGUI::Asset::File::GalleryFile::Photo",
127116
});
128117
my $photoId = $photo->getId;
118+
$tag->commit;
119+
WebGUI::Test->addToCleanup($tag);
129120

130121
# Attach image file to photo asset (setFile also makes download versions)
131122
$photo->setFile( WebGUI::Test->getTestCollateralPath("rotation_test.png") );
@@ -138,7 +129,7 @@ foreach my $file ( @{$storage->getFiles('showAll') } ) {
138129
}
139130

140131
# 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' );
142133
# Select the proper form
143134
$mech->form_name( 'galleryAlbumEdit' );
144135
# Try to click the "rotate right" button
@@ -175,25 +166,3 @@ cmp_deeply( \@oldDims, \@newerDims, "Check if all files were rotated by 90° CCW
175166
}
176167

177168
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

Comments
 (0)
Please sign in to comment.