- 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

@ -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