Added userDefined fields to GalleryAlbum assets. Modified Gallery::Utility to migrate userDefined fields from Threads to GalleryAlbums. Added tests for the previous.
This commit is contained in:
parent
b6324d17a5
commit
f56c0873d8
4 changed files with 63 additions and 4 deletions
|
|
@ -160,6 +160,11 @@ CREATE TABLE IF NOT EXISTS GalleryAlbum (
|
|||
revisionDate BIGINT NOT NULL,
|
||||
allowComments INT,
|
||||
assetIdThumbnail VARCHAR(22) BINARY,
|
||||
userDefined1 TEXT,
|
||||
userDefined2 TEXT,
|
||||
userDefined3 TEXT,
|
||||
userDefined4 TEXT,
|
||||
userDefined5 TEXT,
|
||||
othersCanAdd INT,
|
||||
PRIMARY KEY (assetId, revisionDate)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -167,6 +167,11 @@ sub addAlbumFromThread {
|
|||
menuTitle => $thread->get('menuTitle'),
|
||||
description => $thread->get('bodyText'),
|
||||
synopsis => $thread->get('synopsis'),
|
||||
userDefined1 => $thread->get('userDefined1'),
|
||||
userDefined2 => $thread->get('userDefined2'),
|
||||
userDefined3 => $thread->get('userDefined3'),
|
||||
userDefined4 => $thread->get('userDefined4'),
|
||||
userDefined5 => $thread->get('userDefined5'),
|
||||
}, undef, $thread->get('revisionDate'), $addOptions );
|
||||
|
||||
# Add a new Photo asset for each photo in the storage locations
|
||||
|
|
|
|||
|
|
@ -63,6 +63,13 @@ sub definition {
|
|||
},
|
||||
);
|
||||
|
||||
# UserDefined Fields
|
||||
for my $i (1 .. 5) {
|
||||
$properties{"userDefined".$i} = {
|
||||
defaultValue => undef,
|
||||
};
|
||||
}
|
||||
|
||||
push @{$definition}, {
|
||||
assetName => $i18n->get('assetName'),
|
||||
autoGenerateForms => 0,
|
||||
|
|
|
|||
|
|
@ -45,9 +45,18 @@ my $collab
|
|||
});
|
||||
|
||||
my @threads;
|
||||
for (1..3) {
|
||||
for (0..2) {
|
||||
push @threads, $collab->addChild({
|
||||
className => 'WebGUI::Asset::Post::Thread',
|
||||
title => "title$_",
|
||||
menuTitle => "menuTitle$_",
|
||||
bodyText => "bodyText$_",
|
||||
synopsis => "synopsis$_",
|
||||
userDefined1 => "userDefined1$_",
|
||||
userDefined2 => "userDefined2$_",
|
||||
userDefined3 => "userDefined3$_",
|
||||
userDefined4 => "userDefined4$_",
|
||||
userDefined5 => "userDefined5$_",
|
||||
}, @addArgs);
|
||||
$threads[-1]->getStorageLocation->addFileFromFilesystem(
|
||||
WebGUI::Test->getTestCollateralPath('lamp.jpg')
|
||||
|
|
@ -57,19 +66,44 @@ for (1..3) {
|
|||
# Add a post to one of the threads, with an image
|
||||
my @posts;
|
||||
push @{$posts[0]}, $threads[0]->addChild({
|
||||
className => 'WebGUI::Asset::Post',
|
||||
className => 'WebGUI::Asset::Post',
|
||||
title => "title",
|
||||
menuTitle => "menuTitle00",
|
||||
bodyText => "bodyText00",
|
||||
synopsis => "synopsis00",
|
||||
userDefined1 => "userDefined100",
|
||||
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 = (
|
||||
title => "title",
|
||||
menuTitle => "menuTitle",
|
||||
bodyText => "description",
|
||||
synopsis => "synopsis",
|
||||
userDefined1 => "userDefined1",
|
||||
userDefined2 => "userDefined2",
|
||||
userDefined3 => "userDefined3",
|
||||
userDefined4 => "userDefined4",
|
||||
userDefined5 => "userDefined5",
|
||||
);
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
# addAlbumFromThread tests $thread[0] and @{$posts[0]}
|
||||
my $threadTests = 4 * ( 1 + scalar @{ $posts[0] } );
|
||||
my $threadPostTests = 4 * ( 1 + scalar @{ $posts[0] } );
|
||||
|
||||
plan tests => 9 + $threadTests;
|
||||
# addAlbumFromThread adds 1 test for each field in %threadFields
|
||||
my $threadFieldTests = 1 * scalar keys %threadFields;
|
||||
|
||||
plan tests => 9 + $threadPostTests + $threadFieldTests;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test use
|
||||
|
|
@ -104,12 +138,20 @@ is(
|
|||
"addAlbumFromThread creates album with same revisionDate as thread",
|
||||
);
|
||||
|
||||
# 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",
|
||||
);
|
||||
|
||||
# 4 tests for each post/file
|
||||
# TODO: Test that post-to-file fields are migrated properly, but how?
|
||||
for my $fileId ( @{$album->getFileIds} ) {
|
||||
my $file = WebGUI::Asset->newByDynamicClass( $session, $fileId );
|
||||
is(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue