- moved Gallery utility methods to WebGUI::Utility::Gallery

- Added tests for GalleryAlbum RSS
- More tests for comments
- Test International Macro sprintf as third+ arguments
- Add Gallery search limiting by user ID
- Remaining i18n for Gallery templates
- Fix: Search form now visible in Photo assets
Moved a lot of stuff from Photo to GalleryFile
This commit is contained in:
Doug Bell 2008-03-20 18:51:44 +00:00
parent 38256af5f6
commit ab6f4defe3
25 changed files with 1386 additions and 905 deletions

View file

@ -50,7 +50,7 @@ $versionTags[-1]->commit;
#----------------------------------------------------------------------------
# Tests
plan tests => 29;
plan tests => 32;
#----------------------------------------------------------------------------
# Test with no comments
@ -184,11 +184,70 @@ ok(
);
#----------------------------------------------------------------------------
# Test appendTemplateVarsForCommentForm
TODO: {
local $TODO = "Test appendTemplateVarsForCommentForm";
ok(0, "Test template variable generation");
}
# Test appendTemplateVarsForCommentForm for a new comment
my $var = {};
my $newVar = $photo->appendTemplateVarsCommentForm( $var );
is ( $var, $newVar, "appendTemplateVarsCommentForm returns the same hashref it's given" );
cmp_deeply(
$var,
superhashof( {
commentForm_start => all(
re( qr/<input[^>]+name="func"[^>]+value="editCommentSave"[^>]+>/ ),
re( qr/<input[^>]+name="commentId"[^>]+value="new"[^>]+>/ ),
),
commentForm_end => all(
re( qr{</form>} ),
),
commentForm_bodyText => all(
re( qr{<textarea[^>]+>} ),
re( qr{TinyMCE}i ),
),
commentForm_submit => all(
re( qr/<input[^>]+type="submit"[^>]+name="submit"[^>]+value="Save Comment"[^>]+>/ ),
),
} ),
"appendTemplateVarsCommentForm returns the correct structure",
);
#----------------------------------------------------------------------------
# Test appendTemplateVarsForCommentForm for an existing comment
$var = {};
my $comment = {
commentId => "new",
bodyText => "New comment",
creationDate => WebGUI::DateTime->new( $session, time )->toDatabase,
userId => "3",
};
my $commentId = $photo->setComment( $comment );
$newVar = $photo->appendTemplateVarsCommentForm( $var, $photo->getComment( $commentId ) );
is ( $var, $newVar, "appendTemplateVarsCommentForm returns the same hashref it's given" );
cmp_deeply(
$var,
superhashof( {
commentForm_start => all(
re( qr/<input[^>]+name="func"[^>]+value="editCommentSave"[^>]+>/ ),
re( qr/<input[^>]+name="commentId"[^>]+value="$commentId"[^>]+>/ ),
re( qr/<input[^>]+name="creationDate"[^>]+value="$comment->{creationDate}"[^>]+>/ ),
re( qr/<input[^>]+name="userId"[^>]+value="$comment->{userId}"[^>]+>/ ),
),
commentForm_end => all(
re( qr{</form>} ),
),
commentForm_bodyText => all(
re( qr{<textarea[^>]+>} ),
re( qr{TinyMCE}i ),
re( qr{$comment->{bodyText}} ),
),
commentForm_submit => all(
re( qr/<input[^>]+type="submit"[^>]+name="submit"[^>]+value="Save Comment"[^>]+>/ ),
),
} ),
"appendTemplateVarsCommentForm returns the correct structure",
);
#----------------------------------------------------------------------------
# Test www_editCommentSave page sanity checks

View file

@ -19,6 +19,7 @@ use Scalar::Util qw( blessed );
use WebGUI::Test;
use WebGUI::Session;
use Test::More;
use Test::Deep;
use WebGUI::Asset::File::GalleryFile::Photo;
#----------------------------------------------------------------------------
@ -35,6 +36,7 @@ my $gallery
= $node->addChild({
className => "WebGUI::Asset::Wobject::Gallery",
imageResolutions => "100\n200\n300",
groupIdView => 7,
});
my $album
= $gallery->addChild({
@ -46,7 +48,7 @@ my $album
skipAutoCommitWorkflows => 1,
});
my $photo
= $gallery->addChild({
= $album->addChild({
className => "WebGUI::Asset::File::GalleryFile::Photo",
},
undef,
@ -59,12 +61,30 @@ $versionTags[-1]->commit;
#----------------------------------------------------------------------------
# Tests
plan tests => 1;
plan tests => 3;
#----------------------------------------------------------------------------
# getResolutions returns an array reference of available resolutions
$photo->setFile( WebGUI::Test->getTestCollateralPath( "lamp.jpg" ) );
cmp_deeply(
$photo->getResolutions,
bag( "100.jpg", "200.jpg", "300.jpg" ),
"getResolutions returns the correct array reference",
);
#----------------------------------------------------------------------------
# getDownloadFileUrl returns the URL to download the resolution
is(
$photo->getDownloadFileUrl("100"),
$photo->getStorageLocation->getUrl( "100.jpg" ),
"getDownloadFileUrl returns the URL to download the resolution",
);
ok(
!eval{ $photo->getDownloadFileUrl("400"); 1 },
"getDownloadFileUrl croaks if resolution doesn't exist",
);
TODO: {
local $TODO = 'Write some tests for download testing';
ok(0, 'No tests yet');
}
#----------------------------------------------------------------------------
# Cleanup

View file

@ -19,7 +19,6 @@ use Scalar::Util qw( blessed );
use WebGUI::Test;
use WebGUI::Session;
use Test::More;
use WebGUI::Test::Maker::HTML;
use WebGUI::Asset::File::GalleryFile::Photo;
#----------------------------------------------------------------------------
@ -33,10 +32,20 @@ $versionTags[-1]->set({name=>"Photo Test, add Gallery, Album and 1 Photo"});
$session->user( { userId => 3 } ); # Admins can do everything
my $maker = WebGUI::Test::Maker::HTML->new;
# Create a user for testing purposes
my $user = WebGUI::User->new( $session, "new" );
$user->username( 'dufresne' );
$user->addToGroups( ['3'] );
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 ),
});
my $gallery
= $node->addChild({
className => "WebGUI::Asset::Wobject::Gallery",
groupIdAddFile => 3, # Admins
});
my $album
= $gallery->addChild({
@ -61,67 +70,58 @@ $versionTags[-1]->commit;
#----------------------------------------------------------------------------
# Tests
plan skip_all => "Tests are not working yet.";
plan skip_all => "Tests not working yet";
#plan tests => 1;
use_ok("Test::WWW::Mechanize");
my $mech;
#----------------------------------------------------------------------------
# Test permissions
$mech = Test::WWW::Mechanize->new;
# Edit an existing photo
$maker->prepare({
object => $photo,
method => "www_edit",
userId => "1",
test_privilege => "insufficient",
})->run;
$mech->get( $session->url->getSiteURL . $photo->getUrl("func=edit") );
$mech->content_contains("permission denied");
$mech->get( $session->url->getSiteURL . $photo->getUrl("func=editSave") );
$mech->content_contains("permission denied");
# Save a new photo
$maker->prepare({
object => $photo,
method => "www_editSave",
userId => "1",
test_privilege => "insufficient",
})->run;
$mech->get( $session->url->getSiteURL . $album->getUrl("func=add;class=WebGUI::Asset::File::GalleryFile::Photo") );
$mech->content_contains("permission denied");
$mech->get( $session->url->getSiteURL . $album->getUrl("func=editSave;assetId=new;class=WebGUI::Asset::File::GalleryFile::Photo") );
$mech->content_contains("permission denied");
#----------------------------------------------------------------------------
# Test processPropertiesFromFormPost errors
# TODO: This test should use i18n.
# TODO: This error / test should occur in File, not Photo
$maker->prepare({
object => $album,
method => "www_editSave",
formParams => {
assetId => "new",
className => "WebGUI::Asset::File::GalleryFile::Photo",
$mech = Test::WWW::Mechanize->new;
# Login mech object
$mech->get( $session->url->getSiteURL . '?op=auth;method=login;username=dufresne;identifier=ritahayworth' );
$mech->get_ok( $album->getUrl('func=add;class=WebGUI::Asset::File::GalleryFile::Photo') );
$mech->submit_form(
with_fields => {
title => '',
newFile_file => '',
},
test_regex => [
qr/You must select a file/,
qr/You must enter a title/,
],
})->run;
);
#----------------------------------------------------------------------------
# Test editSave success result
# TODO: This test should use i18n
$maker->prepare({
object => $album,
method => "www_editSave",
formParams => {
assetId => "new",
className => "WebGUI::Asset::File::GalleryFile::Photo",
},
test_regex => [
qr/awaiting approval and commit/,
],
})->run;
#----------------------------------------------------------------------------
# Cleanup
END {
$gallery->purge;
foreach my $versionTag (@versionTags) {
$versionTag->rollback;
}
$user->delete;
}

View file

@ -19,6 +19,7 @@ use Scalar::Util qw( blessed );
use WebGUI::Test;
use WebGUI::Session;
use Test::More;
use Test::Deep;
use WebGUI::Test::Maker::HTML;
use WebGUI::Asset::File::GalleryFile::Photo;
@ -48,7 +49,7 @@ $versionTag->commit;
#----------------------------------------------------------------------------
# Tests
plan tests => 11;
plan tests => 10;
#----------------------------------------------------------------------------
# makeShortcut argument checking
@ -76,7 +77,7 @@ ok(
);
is(
blessed $shortcut, "WebGUI::Asset::Shortcut",
Scalar::Util::blessed($shortcut), "WebGUI::Asset::Shortcut",
"Photo->makeShortcut returns a WebGUI::Shortcut asset",
);
@ -96,7 +97,7 @@ ok(
);
is(
blessed $shortcut, "WebGUI::Asset::Shortcut",
Scalar::Util::blessed($shortcut), "WebGUI::Asset::Shortcut",
"Photo->makeShortcut returns a WebGUI::Shortcut asset",
);
@ -105,26 +106,15 @@ is(
"Photo->makeShortcut makes a shortcut to the correct asset",
);
SKIP: {
skip "Asset::Shortcut does not have a getShortcutOverrides method", 1;
is_deeply(
{$shortcut->getShortcutOverrides}, $overrides,
"Photo->makeShortcut makes a shortcut with the correct overrides",
);
}
my %shortcutOverrides = $shortcut->getOverrides;
cmp_deeply(
{ map({ $_ => $shortcutOverrides{overrides}->{$_}->{newValue} } keys %{ $overrides }) },
$overrides,
"Photo->makeShortcut makes a shortcut with the correct overrides",
);
#----------------------------------------------------------------------------
# www_makeShortcut is only available to those who can edit the photo
SKIP: {
skip "test_privilege has a bug", 1;
$maker->prepare({
object => $photo,
method => "www_makeShortcut",
userId => 1,
test_privilege => "insufficient",
});
$maker->run;
}
#----------------------------------------------------------------------------
# www_makeShortcut

View file

@ -67,7 +67,7 @@ cmp_deeply(
);
ok(
-e $storage->getPath($gallery->get('imageResolutions') . '.jpg'),
-e $storage->getPath($gallery->getImageResolutions->[0] . '.jpg'),
"Generated resolution file exists on the filesystem",
);

View file

@ -18,7 +18,7 @@ use Scalar::Util qw( blessed );
use WebGUI::Test;
use WebGUI::Session;
use Test::More;
use WebGUI::Test::Maker::HTML;
use Test::Deep;
use WebGUI::Asset::File::GalleryFile::Photo;
#----------------------------------------------------------------------------
@ -27,10 +27,11 @@ my $session = WebGUI::Test->session;
my $node = WebGUI::Asset->getImportNode($session);
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Photo Test"});
my $maker = WebGUI::Test::Maker::HTML->new;
my $gallery
= $node->addChild({
className => "WebGUI::Asset::Wobject::Gallery",
groupIdAddComment => 7, # Everyone
groupIdAddFile => 2, # Registered Users
});
my $album
= $gallery->addChild({
@ -44,6 +45,7 @@ my $album
my $photo
= $album->addChild({
className => "WebGUI::Asset::File::GalleryFile::Photo",
ownerUserId => 3,
},
undef,
undef,
@ -57,10 +59,47 @@ $photo->setFile( WebGUI::Test->getTestCollateralPath('page_title.jpg') );
# Tests
plan tests => 1;
TODO: {
local $TODO = "Write some tests";
ok(0, 'No tests here, move on');
#----------------------------------------------------------------------------
# Test getTemplateVars
$session->user( { userId => 1 } );
my $testTemplateVars = {
%{ $photo->get },
synopsis => '', # Synopsis is not undef, is changed to empty string
canComment => bool( 1 ),
canEdit => bool( 0 ),
ownerUsername => WebGUI::User->new( $session, 3 )->username,
url => $photo->getUrl,
url_addArchive => $album->getUrl('func=addArchive'),
url_delete => $photo->getUrl('func=delete'),
url_demote => $photo->getUrl('func=demote'),
url_edit => $photo->getUrl('func=edit'),
url_gallery => $gallery->getUrl,
url_makeShortcut => $photo->getUrl('func=makeShortcut'),
url_listFilesForOwner
=> $gallery->getUrl('func=listFilesForUser;userId=3'),
url_promote => $photo->getUrl('func=promote'),
fileUrl => $photo->getFileUrl,
thumbnailUrl => $photo->getThumbnailUrl,
numberOfComments => scalar @{ $photo->getCommentIds },
resolutions_loop => ignore(), # Tested elsewhere
exifLoop => ignore(), # Tested elsewhere
# Gallery stuff
url_search => $gallery->getUrl('func=search'),
url_listFilesForCurrentUser => $gallery->getUrl('func=listFilesForUser'),
};
# Ignore all EXIF tags
for my $tag ( keys %{ $photo->getExifData } ) {
$testTemplateVars->{ 'exif_' . $tag } = ignore();
}
# Add search vars
$gallery->appendTemplateVarsSearchForm( $testTemplateVars );
cmp_deeply(
$photo->getTemplateVars,
$testTemplateVars,
"getTemplateVars is correct and complete",
);
#----------------------------------------------------------------------------
# Cleanup