- 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

View file

@ -51,7 +51,13 @@ isa_ok(
);
#----------------------------------------------------------------------------
# Test deleting a album
# Test adding children to Gallery
# Only GalleryAlbums may be added
#----------------------------------------------------------------------------
# Test deleting a gallery
my $properties = $gallery->get;
$gallery->purge;

View file

@ -1,258 +0,0 @@
# $vim:syntax=perl
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2008 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#------------------------------------------------------------------
# Test the addAlbum* methods from the Gallery::Utility class
#
#
use strict;
use FindBin;
use lib "$FindBin::Bin/../../../../../lib";
use lib "$FindBin::Bin/../../../../lib";
use Test::More;
use Test::Deep;
use WebGUI::Asset;
use WebGUI::Session;
use WebGUI::Test;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
my $node = WebGUI::Asset->getImportNode( $session );
# Add arguments to avoid autocommit workflows
my @addArgs = ( undef, undef, { skipAutoCommitWorkflows => 1 } );
my @versionTags;
push @versionTags, WebGUI::VersionTag->getWorking( $session );
# Generate a Gallery to import into
my $gallery;
my $album;
# Generate a collaboration system to import
my $collab
= $node->addChild({
className => 'WebGUI::Asset::Wobject::Collaboration',
});
my @threads;
for (0..2) {
push @threads, $collab->addChild({
className => 'WebGUI::Asset::Post::Thread',
content => "content$_",
menuTitle => "menuTitle$_",
ownerUserId => "3$_",
synopsis => "synopsis$_",
title => "title$_",
userDefined1 => "$_", # This is important. Used to detect which File is from which Thread
userDefined2 => "userDefined2$_",
userDefined3 => "userDefined3$_",
userDefined4 => "userDefined4$_",
userDefined5 => "userDefined5$_",
}, @addArgs);
$threads[-1]->getStorageLocation->addFileFromFilesystem(
WebGUI::Test->getTestCollateralPath('lamp.jpg')
);
}
# Add a post to one of the threads, with an image
my @posts;
push @{$posts[0]}, $threads[0]->addChild({
className => 'WebGUI::Asset::Post',
content => "content00",
menuTitle => "menuTitle00",
synopsis => "synopsis00",
title => "title00",
userDefined1 => "00", # This is important. Used to detect which File is from which Post
userDefined2 => "userDefined200",
userDefined3 => "userDefined300",
userDefined4 => "userDefined400",
userDefined5 => "userDefined500",
}, @addArgs);
$posts[0][0]->getStorageLocation->addFileFromFilesystem(
WebGUI::Test->getTestCollateralPath('lamp.jpg')
);
# Thread fields mapped to album fields that should be migrated
my %threadFields = (
content => "description",
createdBy => 'createdBy',
creationDate => 'creationDate',
menuTitle => "menuTitle",
ownerUserId => "ownerUserId",
synopsis => "synopsis",
title => "title",
userDefined1 => "userDefined1",
userDefined2 => "userDefined2",
userDefined3 => "userDefined3",
userDefined4 => "userDefined4",
userDefined5 => "userDefined5",
);
# Post fields mapped to photo fields that should be migrated
my %postFields = (
content => "synopsis",
createdBy => 'createdBy',
creationDate => 'creationDate',
ownerUserId => "ownerUserId",
userDefined1 => "userDefined1",
userDefined2 => "userDefined2",
userDefined3 => "userDefined3",
userDefined4 => "userDefined4",
userDefined5 => "userDefined5",
);
#----------------------------------------------------------------------------
# Tests
# addAlbumFromThread adds 6 tests for $thread[0] and @{$posts[0]}
my $threadPostTests = 6 * ( 1 + scalar @{ $posts[0] } );
# addAlbumFromThread adds 1 test for each field in %threadFields
my $threadFieldTests = 1 * scalar keys %threadFields;
# addAlbumFromThread adds 1 test for each field in %postFields
my $postFieldTests = 1 * ( scalar keys %postFields )
* ( 1 + scalar @{ $posts[0] } );
plan tests => 10
+ $threadPostTests
+ $threadFieldTests
+ $postFieldTests
;
#----------------------------------------------------------------------------
# Test use
my $utility = 'WebGUI::Asset::Wobject::Gallery::Utility';
use_ok($utility);
#----------------------------------------------------------------------------
# Test addAlbumFromThread
$gallery = $node->addChild({ className => 'WebGUI::Asset::Wobject::Gallery' });
ok(
!eval{ $utility->addAlbumFromThread( "", $threads[0] ); 1},
"addAlbumFromThread croaks if first argument is not a Gallery asset",
);
ok(
!eval{ $utility->addAlbumFromThread( $gallery, "" ); 1},
"addAlbumFromThread croaks if second argument is not a Thread asset",
);
$utility->addAlbumFromThread( $gallery, $threads[0] );
is(
scalar @{ $gallery->getAlbumIds }, 1,
"addAlbumFromThread creates a new album",
);
$album = WebGUI::Asset->newByDynamicClass( $session, $gallery->getAlbumIds->[0] );
is(
$album->get('revisionDate'), $threads[0]->get('revisionDate'),
"addAlbumFromThread creates album with same revisionDate as thread",
);
my $galleryUrl = $gallery->get('url');
like(
$album->get('url'), qr/^$galleryUrl/,
"addAlbumFromThread creates album with url that begins with gallery's url",
);
# 1 test for each field in %threadFields
for my $oldField ( sort keys %threadFields ) {
is( $album->get( $threadFields{ $oldField } ), $threads[0]->get( $oldField ),
"addAlbumFromThread migrates Thread $oldField to GalleryAlbum $threadFields{$oldField}",
);
}
is(
scalar @{ $album->getFileIds }, 2,
"addAlbumFromThread adds one file for each attachment to the thread or posts of the thread",
);
# 6 tests for each post/file + postFields tests
my $albumUrl = $album->get('url');
for my $fileId ( @{$album->getFileIds} ) {
my $file = WebGUI::Asset->newByDynamicClass( $session, $fileId );
# Find which Thread or Post this file corresponds to
my $post;
if ( length $file->get('userDefined1') == 1 ) {
# Is a thread, get it
$post = $threads[ $file->get('userDefined1') ];
}
else {
my @index = split //, $file->get('userDefined1');
$post = $posts[ $index[0] ][ $index[1] ];
}
for my $oldField ( sort keys %postFields ) {
is ( $file->get( $postFields{ $oldField } ), $post->get( $oldField ),
"addAlbumFromThread migrates Post $oldField to File $postFields{$oldField}",
);
}
like(
$file->get('url'), qr/^$albumUrl/,
"addAlbumFromThread add files with urls that begin with GalleryAlbum url",
);
isa_ok( $file->getStorageLocation, 'WebGUI::Storage', 'Storage location exists' );
ok( $file->get('filename'), '"filename" property was set' );
cmp_deeply(
$file->getStorageLocation->getFiles, superbagof($file->get('filename')),
"Storage location contains the filename"
);
# Test that title and menuTitle do not contain file extention
my ($title) = $file->get('filename') =~ m{(.*)\.[^.]*$};
is( $file->get('title'), $title,
"Title doesn't contain the file extention"
);
is( $file->get('menuTitle'), $title,
"Menu title doesn't contain the file extention"
);
}
#----------------------------------------------------------------------------
# Test addAlbumFromCollaboration
$gallery = $node->addChild({ className => 'WebGUI::Asset::Wobject::Gallery' });
ok(
!eval{ $utility->addAlbumFromCollaboration( "", $collab ); 1},
"addAlbumFromCollaboration croaks if first argument is not a Gallery asset",
);
ok(
!eval{ $utility->addAlbumFromCollaboration( $gallery, "" ); 1},
"addAlbumFromCollaboration croaks if second argument is not a Collaboration asset",
);
$utility->addAlbumFromCollaboration( $gallery, $collab );
is(
scalar @{ $gallery->getAlbumIds }, scalar @threads,
"addAlbumFromCollaboration creates one album per thread",
);
#----------------------------------------------------------------------------
# Test addAlbumFromFilesystem
# TODO!!!
#----------------------------------------------------------------------------
# Cleanup
END {
for my $tag ( @versionTags ) {
$tag->rollback;
}
}

View file

@ -0,0 +1,83 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2007 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use FindBin;
use strict;
use lib "$FindBin::Bin/../../../lib";
## The goal of this test is to test permissions inside Gallerys
use Scalar::Util qw( blessed );
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Test::Maker::Permission;
use Test::More;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
my $node = WebGUI::Asset->getImportNode($session);
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Gallery Test"});
my $maker = WebGUI::Test::Maker::Permission->new;
my $gallery;
my $nonAdmin = WebGUI::User->new( $session, "new" );
#----------------------------------------------------------------------------
# Tests
# Plan is delayed until all tests are prepared
#----------------------------------------------------------------------------
my $gallery
= $node->addChild({
className => 'WebGUI::Asset::Wobject::Gallery',
groupIdAddComment => '7', # Everyone
groupIdAddFile => '2', # Registered Users
groupIdEdit => '3', # Admins
groupIdView => '7', # Everyone
ownerUserId => '3', # Admin
});
$maker->prepare(
{
object => $gallery,
method => "canView",
pass => [ '1', '3', $nonAdmin->userId ],
},
{
object => $gallery,
method => 'canEdit',
pass => [ '3' ],
fail => [ '1', $nonAdmin->userId ],
},
{
object => $gallery,
method => 'canAddFile',
pass => [ '3', $nonAdmin->userId ],
fail => [ '1' ],
},
{
object => $gallery,
method => 'canComment',
pass => [ '1', '3', $nonAdmin->userId ],
}
);
plan tests => $maker->plan;
$maker->run;
#----------------------------------------------------------------------------
# Cleanup
END {
$versionTag->rollback;
}

View file

@ -52,7 +52,7 @@ $versionTag->commit;
#----------------------------------------------------------------------------
# Tests
plan tests => 2;
plan tests => 5;
#----------------------------------------------------------------------------
# Test the addArchive sub
@ -65,11 +65,30 @@ cmp_deeply(
bag( "Aana1.jpg", "Aana2.jpg", "Aana3.jpg" ),
);
cmp_deeply(
[ map { $_->get("title") } @$images ],
bag( "Aana1", "Aana2", "Aana3" ),
);
cmp_deeply(
[ map { $_->get("menuTitle") } @$images ],
bag( "Aana1", "Aana2", "Aana3" ),
);
cmp_deeply(
[ map { $_->get("url") } @$images ],
bag(
$session->url->urlize( $album->getUrl . "/Aana1" ),
$session->url->urlize( $album->getUrl . "/Aana2" ),
$session->url->urlize( $album->getUrl . "/Aana3" ),
),
);
#----------------------------------------------------------------------------
# Test the www_addArchive page
#----------------------------------------------------------------------------
# Cleanup
END {
$versionTag->rollback();
$versionTag->rollback;
}

View file

@ -19,11 +19,11 @@ use Scalar::Util qw( blessed );
use WebGUI::Test;
use WebGUI::Session;
use Test::More;
use WebGUI::Test::Maker::HTML;
use Test::Deep;
use XML::Simple;
#----------------------------------------------------------------------------
# Init
my $maker = WebGUI::Test::Maker::HTML->new;
my $session = WebGUI::Test->session;
my $node = WebGUI::Asset->getImportNode($session);
my $versionTag = WebGUI::VersionTag->getWorking($session);
@ -41,6 +41,7 @@ my $album
= $gallery->addChild({
className => "WebGUI::Asset::Wobject::GalleryAlbum",
ownerUserId => "3", # Admin
description => "An RSS Description",
},
undef,
undef,
@ -53,6 +54,7 @@ for my $i ( 0 .. 5 ) {
= $album->addChild({
className => "WebGUI::Asset::File::GalleryFile::Photo",
filename => "$i.jpg",
synopsis => "This is a description for $i.jpg",
},
undef,
undef,
@ -65,15 +67,38 @@ $versionTag->commit;
#----------------------------------------------------------------------------
# Tests
plan tests => 1;
plan tests => 2;
use_ok("Test::WWW::Mechanize");
my $mech;
#----------------------------------------------------------------------------
# Test www_viewRss
TODO: {
local $TODO = "Write some tests";
ok(0, "No tests here");
}
$mech = Test::WWW::Mechanize->new;
my $url = $session->url->getSiteURL . $session->url->makeAbsolute( $album->getUrl('func=viewRss') );
$mech->get( $url );
cmp_deeply(
XMLin( $mech->content ),
{
version => '2.0',
channel => {
link => $session->url->getSiteURL . $album->getUrl,
description => $album->get("description"),
title => $album->get("title"),
item => bag(
map {
superhashof({
link => $session->url->getSiteURL . $_->getUrl,
title => $_->get("title"),
pubDate => $session->datetime->epochToMail( $_->get("revisionDate") ),
description => $_->get("synopsis"),
})
} @photos
),
},
},
"RSS Datastructure is complete and correct",
);
#----------------------------------------------------------------------------
# Cleanup