From f56c0873d8e24f6c586296817f56d265b0f1ec7c Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Mon, 7 Jan 2008 22:38:59 +0000 Subject: [PATCH] Added userDefined fields to GalleryAlbum assets. Modified Gallery::Utility to migrate userDefined fields from Threads to GalleryAlbums. Added tests for the previous. --- docs/upgrades/upgrade_7.4.18-7.5.0.pl | 5 +++ lib/WebGUI/Asset/Wobject/Gallery/Utility.pm | 5 +++ lib/WebGUI/Asset/Wobject/GalleryAlbum.pm | 7 +++ t/Asset/Wobject/Gallery/Utility/addAlbum.t | 50 +++++++++++++++++++-- 4 files changed, 63 insertions(+), 4 deletions(-) diff --git a/docs/upgrades/upgrade_7.4.18-7.5.0.pl b/docs/upgrades/upgrade_7.4.18-7.5.0.pl index 42ba52083..ea708dbe4 100644 --- a/docs/upgrades/upgrade_7.4.18-7.5.0.pl +++ b/docs/upgrades/upgrade_7.4.18-7.5.0.pl @@ -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) ) diff --git a/lib/WebGUI/Asset/Wobject/Gallery/Utility.pm b/lib/WebGUI/Asset/Wobject/Gallery/Utility.pm index 3e820990b..148f84a99 100644 --- a/lib/WebGUI/Asset/Wobject/Gallery/Utility.pm +++ b/lib/WebGUI/Asset/Wobject/Gallery/Utility.pm @@ -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 diff --git a/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm b/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm index 15b72da20..7562852f7 100644 --- a/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm +++ b/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm @@ -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, diff --git a/t/Asset/Wobject/Gallery/Utility/addAlbum.t b/t/Asset/Wobject/Gallery/Utility/addAlbum.t index 816a21bba..34dd4a773 100644 --- a/t/Asset/Wobject/Gallery/Utility/addAlbum.t +++ b/t/Asset/Wobject/Gallery/Utility/addAlbum.t @@ -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(