diff --git a/t/Asset/File/GalleryFile/Photo/edit.t b/t/Asset/File/GalleryFile/Photo/edit.t index 1330c84d5..012724944 100644 --- a/t/Asset/File/GalleryFile/Photo/edit.t +++ b/t/Asset/File/GalleryFile/Photo/edit.t @@ -17,6 +17,7 @@ use Test::More; use Test::Deep; use WebGUI::Test; # Must use this before any other WebGUI modules +use WebGUI::Test::Mechanize; use WebGUI::Asset; use WebGUI::Asset::Wobject::Gallery; use WebGUI::Asset::Wobject::GalleryAlbum; @@ -24,8 +25,6 @@ use WebGUI::Asset::File::GalleryFile::Photo; use WebGUI::VersionTag; use WebGUI::Session; -plan skip_all => 'set WEBGUI_LIVE to enable this test' unless $ENV{WEBGUI_LIVE}; - #---------------------------------------------------------------------------- # Init @@ -36,21 +35,10 @@ my $node = WebGUI::Asset->getImportNode( $session ); my $versionTag = WebGUI::VersionTag->getWorking($session); WebGUI::Test->addToCleanup($versionTag); -# Override some settings to make things easier to test -# userFunctionStyleId -$session->setting->set( 'userFunctionStyleId', 'PBtmpl0000000000000132' ); -# specialState -$session->setting->set( 'specialState', '' ); - # Create a user for testing purposes my $user = WebGUI::User->new( $session, "new" ); WebGUI::Test->addToCleanup($user); $user->username( 'dufresne' . time ); -my $identifier = 'ritahayworth'; -my $auth = WebGUI::Operation::Auth::getInstance( $session, $user->authMethod, $user->userId ); -$auth->saveParams( $user->userId, $user->authMethod, { - 'identifier' => Digest::MD5::md5_base64( $identifier ), -}); # Create gallery and a single album my $gallery @@ -75,43 +63,25 @@ my $album # Commit assets for testing $versionTag->commit; -# Get the site's base URL -my $baseUrl = 'http://' . $session->config->get('sitename')->[0]; - -# Common variables -my ( $mech, $photo ); - #---------------------------------------------------------------------------- # Tests -if ( !eval { require Test::WWW::Mechanize; 1; } ) { - plan skip_all => 'Cannot load Test::WWW::Mechanize. Will not test.'; -} -$mech = Test::WWW::Mechanize->new; -$mech->get( $baseUrl ); -if ( !$mech->success ) { - plan skip_all => "Cannot load URL '$baseUrl'. Will not test."; -} - -plan tests => 10; # Increment this number for each test you create - - #---------------------------------------------------------------------------- # Test permissions for new photos -$mech = Test::WWW::Mechanize->new; +my $mech = WebGUI::Test::Mechanize->new(config => WebGUI::Test->file); # Save a new photo -$mech->get( $baseUrl . $album->getUrl("func=add;class=WebGUI::Asset::File::GalleryFile::Photo") ); +$mech->get( $album->getUrl("func=add;className=WebGUI::Asset::File::GalleryFile::Photo") ); $mech->content_lacks( 'value="editSave"' ); - +$mech->content_contains( 'value="addSave"' ); #---------------------------------------------------------------------------- # Test editing existing photo # Create single photo inside the album -$photo +my $photo = $album->addChild({ className => "WebGUI::Asset::File::GalleryFile::Photo", ownerUserId => $user->getId, @@ -137,10 +107,11 @@ my %properties = ( ); # Log in -$mech = getMechLogin( $baseUrl, $user, $identifier ); +$mech->get('/'); ##Prime the pump to get a session; +$mech->session->user({ user => $user }); # Request photo edit view -$mech->get_ok( $baseUrl . $photo->getUrl('func=edit'), 'Request Photo edit view' ); +$mech->get_ok( $photo->getUrl('func=edit'), 'Request Photo edit view' ); # Try to submit edit form $mech->submit_form_ok({ form_name => 'photoEdit', @@ -170,7 +141,7 @@ $photo->setFile( WebGUI::Test->getTestCollateralPath("rotation_test.png") ); # Request photo edit view -$mech->get_ok( $baseUrl . $photo->getUrl('func=edit;proceed=editParent'), 'Request Photo edit view with "proceed=editParent"' ); +$mech->get_ok( $photo->getUrl('func=edit;proceed=editParent'), 'Request Photo edit view with "proceed=editParent"' ); # Submit changes $mech->submit_form( form_name => 'photoEdit' ); # 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 SKIP: { skip "File control needs to be fixed to be more 508-compliant before this can be used", 4; - $mech = getMechLogin( $baseUrl, $user, $identifier ); - $mech->get_ok( $baseUrl . $album->getUrl("func=add;class=WebGUI::Asset::File::GalleryFile::Photo") ); + my $mech = WebGUI::Test::Mechanize->new(config => WebGUI::Test->file); + $mech->get('/'); ##Prime the pump to get a session; + $mech->session->user({ user => $user }); + $mech->get_ok( $album->getUrl("func=add;className=WebGUI::Asset::File::GalleryFile::Photo") ); open my $file, '<', WebGUI::Test->getTestCollateralPath( 'lamp.jpg' ) or die( "Couldn't open test collateral 'lamp.jpg' for reading: $!" ); @@ -222,25 +195,4 @@ SKIP: { ); } - -#---------------------------------------------------------------------------- -# getMechLogin( baseUrl, WebGUI::User, "identifier" ) -# Returns a Test::WWW::Mechanize session after logging in the given user using -# the given identifier (password) -# baseUrl is a fully-qualified URL to the site to login to -sub getMechLogin { - my $baseUrl = shift; - my $user = shift; - my $identifier = shift; - - my $mech = Test::WWW::Mechanize->new; - $mech->get( $baseUrl . '?op=auth;method=displayLogin' ); - $mech->submit_form( - with_fields => { - username => $user->username, - identifier => $identifier, - }, - ); - - return $mech; -} +done_testing;