Skip to content

Commit

Permalink
Update the GalleryFile/Photo/edit test for WEBGUI_LIVE.
Browse files Browse the repository at this point in the history
  • Loading branch information
perlDreamer committed Dec 2, 2011
1 parent e1f8b1d commit 7d75bf5
Showing 1 changed file with 14 additions and 62 deletions.
76 changes: 14 additions & 62 deletions t/Asset/File/GalleryFile/Photo/edit.t
Expand Up @@ -17,15 +17,14 @@ 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;
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

Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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',
Expand Down Expand Up @@ -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
Expand All @@ -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: $!" );
Expand Down Expand Up @@ -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;

0 comments on commit 7d75bf5

Please sign in to comment.