From 5140ece7317abc5faea45a0fd568d08e64543e06 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 13 May 2010 20:02:26 -0700 Subject: [PATCH] Large batch of test fixes, most for newByDynamicClass -> newById --- t/Asset/EMSSubmissionForm.t | 4 ++-- t/Asset/File/GalleryFile/Photo/edit.t | 4 ++-- t/Asset/Post.t | 3 ++- t/Asset/Post/Thread.t | 2 ++ t/Asset/Post/Thread/getAdjacentThread.t | 19 +++++++++---------- t/Asset/Post/Thread/permission.t | 6 +++--- t/Asset/Post/permission.t | 6 +++--- t/Asset/Sku/ProductCollateral.t | 2 +- t/Asset/Wobject/Collaboration/permission.t | 2 +- t/Asset/Wobject/Collaboration/unarchiveAll.t | 2 +- t/Asset/Wobject/Gallery/00base.t | 2 +- t/Asset/Wobject/GalleryAlbum/00base.t | 2 +- t/Asset/Wobject/GalleryAlbum/delete.t | 2 +- t/Asset/Wobject/GalleryAlbum/edit.t | 2 +- t/Asset/permissions.t | 10 +++++----- t/Group/resetGroupFields.t | 8 ++++---- t/lib/WebGUI/Test.pm | 4 ++-- 17 files changed, 41 insertions(+), 39 deletions(-) diff --git a/t/Asset/EMSSubmissionForm.t b/t/Asset/EMSSubmissionForm.t index 615d2fabc..12f92c226 100644 --- a/t/Asset/EMSSubmissionForm.t +++ b/t/Asset/EMSSubmissionForm.t @@ -354,7 +354,7 @@ is($approveSubmissions->run, 'done', 'approval done'); $sub1 = $sub1->cloneFromDb; is( $sub1->get('submissionStatus'),'created','approval successfull'); -my $ticket = WebGUI::Asset->newByDynamicClass($session, $sub1->get('ticketId')); +my $ticket = WebGUI::Asset->newById($session, $sub1->get('ticketId')); WebGUI::Test->assetsToPurge( $ticket ) if $ticket ; SKIP: { skip 'no ticket created', 1 unless isa_ok( $ticket, 'WebGUI::Asset::Sku::EMSTicket', 'approval created a ticket'); @@ -373,7 +373,7 @@ $cleanupSubmissions->reset; is($cleanupSubmissions->run, 'complete', 'cleanup complete'); is($cleanupSubmissions->run, 'done', 'cleanup done'); -$sub2 = WebGUI::Asset->newByDynamicClass($session, $sub2Id); +$sub2 = WebGUI::Asset->newById($session, $sub2Id); is( $sub2, undef, 'submission deleted'); } # end of workflow skip diff --git a/t/Asset/File/GalleryFile/Photo/edit.t b/t/Asset/File/GalleryFile/Photo/edit.t index 389320a9a..ff860d8ad 100644 --- a/t/Asset/File/GalleryFile/Photo/edit.t +++ b/t/Asset/File/GalleryFile/Photo/edit.t @@ -120,11 +120,11 @@ SKIP: { }; # Make sure properties were saved - my $photo = WebGUI::Asset->newByDynamicClass( $session, $album->getFileIds->[0] ); + my $photo = WebGUI::Asset->newById( $session, $album->getFileIds->[0] ); cmp_deeply( $photo->get, superhashof( $properties ), "Photo properties saved correctly" ); # First File in an album should update assetIdThumbnail - my $album = WebGUI::Asset->newByDynamicClass( $session, $album->getId ); + my $album = WebGUI::Asset->newById( $session, $album->getId ); is( $album->get('assetIdThumbnail'), $photo->getId, "Album assetIdThumbnail gets set by first File added", diff --git a/t/Asset/Post.t b/t/Asset/Post.t index ec495ae1a..6c1c2db10 100644 --- a/t/Asset/Post.t +++ b/t/Asset/Post.t @@ -84,6 +84,7 @@ my $post = $collab->addChild($props, @addArgs); $versionTag->commit(); WebGUI::Test->tagsToRollback($versionTag); +$post = $post->cloneFromDb; # Test for a sane object type isa_ok($post, 'WebGUI::Asset::Post::Thread'); @@ -120,7 +121,7 @@ $post->update({synopsis => $synopsis}); ##There is a bug in DBD::mysql with not properly encoding 8-bit characters. Also, HTML::Entities produces ##8-bit utf8 (not strict) characters. So we write a quick test to make sure our patch in splitTag works correctly. -my $dbPost = WebGUI::Asset->newByDynamicClass($session, $post->getId); +my $dbPost = WebGUI::Asset->newById($session, $post->getId); like($dbPost->get('synopsis'), qr/Brandhei.e Neuigkeiten rund um's Klettern f.r euch aus der Region /, 'patch test for DBD::Mysql and HTML::Entities'); ($synopsis, $content) = $post->getSynopsisAndContent('', q|less than < greater than >|); diff --git a/t/Asset/Post/Thread.t b/t/Asset/Post/Thread.t index b89ae98ec..06877053e 100644 --- a/t/Asset/Post/Thread.t +++ b/t/Asset/Post/Thread.t @@ -49,6 +49,8 @@ my $props = { my $thread = $collab->addChild($props, @addArgs); $versionTag->commit(); +$collab = $collab->cloneFromDb; +$thread = $thread->cloneFromDb; my $uncommittedThread = $collab->addChild($props, @addArgs); diff --git a/t/Asset/Post/Thread/getAdjacentThread.t b/t/Asset/Post/Thread/getAdjacentThread.t index 12b26890c..ed6d28cfd 100644 --- a/t/Asset/Post/Thread/getAdjacentThread.t +++ b/t/Asset/Post/Thread/getAdjacentThread.t @@ -61,6 +61,10 @@ my @threads = ( $_->setSkipNotification for @threads; $versionTags[-1]->commit; +WebGUI::Test->addToCleanup($versionTags[-1]); +foreach my $asset(@threads, $collab) { + $asset = $asset->cloneFromDb; +} #---------------------------------------------------------------------------- # Tests @@ -133,6 +137,7 @@ $collab->update({ sortOrder => 'desc', }); push @versionTags, WebGUI::VersionTag->getWorking( $session ); +WebGUI::Test->addToCleanup($versionTags[-1]); push @threads, $collab->addChild( { className => 'WebGUI::Asset::Post::Thread', title => "Abababa", @@ -146,12 +151,6 @@ testGetAdjacentThread( "sort by default from asset with version tag", $sort, [ q $session->scratch->delete($collab->getId.'_sortBy'); $session->scratch->delete($collab->getId.'_sortDir'); -#---------------------------------------------------------------------------- -# Cleanup -END { - $_->rollback for @versionTags; -} - #---------------------------------------------------------------------------- # testGetAdjacentThread ( label, sort, order, @threads ) # Performs two tests for each thread in [order] @@ -161,10 +160,10 @@ END { # @threads = all the threads sub testGetAdjacentThread { my ( $label, $sort, $order, @threads ) = @_; - + my $idxFirst = shift @{$order}; my $idxLast = pop @{$order}; - + # First is( $threads[$idxFirst]->getNextThread->getId, getNextThread( $sort, $threads[$idxFirst], @threads )->getId, @@ -220,7 +219,7 @@ sub sortThreads { sub getNextThread { my ( $sortSub, $thread, @threads ) = @_; my @sorted = @{ sortThreads( $sortSub, @threads ) }; - + for my $i ( 0..$#sorted ) { if ( $sorted[$i]->getId eq $thread->getId ) { return $sorted[$i+1]; @@ -232,7 +231,7 @@ sub getPreviousThread { my ( $sortSub, $thread, @threads ) = @_; # Use reverse so that $i-1 != -1 (which gets us the last thread) my @sorted = reverse @{ sortThreads( $sortSub, @threads ) }; - + for my $i ( 0..$#sorted ) { if ( $sorted[$i]->getId eq $thread->getId ) { return $sorted[$i+1]; diff --git a/t/Asset/Post/Thread/permission.t b/t/Asset/Post/Thread/permission.t index 240c58b65..103637024 100644 --- a/t/Asset/Post/Thread/permission.t +++ b/t/Asset/Post/Thread/permission.t @@ -62,8 +62,8 @@ my $thread $versionTag->commit( { timeout => 1_000_000 } ); # Re-load the collab to get the newly committed properties -$collab = WebGUI::Asset->newByDynamicClass( $session, $collab->getId ); -$thread = WebGUI::Asset->newByDynamicClass( $session, $thread->getId ); +$collab = WebGUI::Asset->newById( $session, $collab->getId ); +$thread = WebGUI::Asset->newById( $session, $thread->getId ); #---------------------------------------------------------------------------- # Tests @@ -104,7 +104,7 @@ $maker->prepare( { # Reply with allowReplies = 0 $collab->update({ allowReplies => 0 }); -$thread = WebGUI::Asset->newByDynamicClass( $session, $thread->getId ); +$thread = WebGUI::Asset->newById( $session, $thread->getId ); $maker->prepare( { object => $thread, method => 'canReply', diff --git a/t/Asset/Post/permission.t b/t/Asset/Post/permission.t index dcd0fd63b..21bc8e82e 100644 --- a/t/Asset/Post/permission.t +++ b/t/Asset/Post/permission.t @@ -67,9 +67,9 @@ my $post $versionTag->commit( { timeout => 1_000_000 } ); # Re-load the collab to get the newly committed properties -$collab = WebGUI::Asset->newByDynamicClass( $session, $collab->getId ); -$thread = WebGUI::Asset->newByDynamicClass( $session, $thread->getId ); -$post = WebGUI::Asset->newByDynamicClass( $session, $post->getId ); +$collab = WebGUI::Asset->newById( $session, $collab->getId ); +$thread = WebGUI::Asset->newById( $session, $thread->getId ); +$post = WebGUI::Asset->newById( $session, $post->getId ); #---------------------------------------------------------------------------- # Tests diff --git a/t/Asset/Sku/ProductCollateral.t b/t/Asset/Sku/ProductCollateral.t index 5ed86a964..db5a95270 100644 --- a/t/Asset/Sku/ProductCollateral.t +++ b/t/Asset/Sku/ProductCollateral.t @@ -302,7 +302,7 @@ my $product6 = $root->addChild({ $newVid = $product6->setCollateral('variantsJSON', 'vid', 'new', { wideChar => qq!on 16\x{201d} hand-crocheted Cord! , vid => 'new' }); -my $product6a = WebGUI::Asset->newByDynamicClass($session, $product6->getId); +my $product6a = WebGUI::Asset->newById($session, $product6->getId); lives_ok { $product6a->getAllCollateral('variantsJSON', 'vid', $newVid); }, 'Product collateral handles wide-character encodings okay'; $product6->purge; diff --git a/t/Asset/Wobject/Collaboration/permission.t b/t/Asset/Wobject/Collaboration/permission.t index 87f24ea98..07b3fba3e 100644 --- a/t/Asset/Wobject/Collaboration/permission.t +++ b/t/Asset/Wobject/Collaboration/permission.t @@ -51,7 +51,7 @@ my $collab $versionTag->commit( { timeout => 1_000_000 } ); # Re-load the collab to get the newly committed properties -$collab = WebGUI::Asset->newByDynamicClass( $session, $collab->getId ); +$collab = WebGUI::Asset->newById( $session, $collab->getId ); #---------------------------------------------------------------------------- # Tests diff --git a/t/Asset/Wobject/Collaboration/unarchiveAll.t b/t/Asset/Wobject/Collaboration/unarchiveAll.t index cb3866b07..b06242152 100644 --- a/t/Asset/Wobject/Collaboration/unarchiveAll.t +++ b/t/Asset/Wobject/Collaboration/unarchiveAll.t @@ -50,7 +50,7 @@ plan tests => 1; # Increment this number for each test you create #---------------------------------------------------------------------------- # www_unarchiveAll sets all threads to approved $collab->www_unarchiveAll; -$threads[0] = WebGUI::Asset->newByDynamicClass( $session, $threads[0]->getId ); +$threads[0] = WebGUI::Asset->newById( $session, $threads[0]->getId ); is( $threads[0]->get('status'), 'approved', "unarchiveAll sets thread to approved" ); #vim:ft=perl diff --git a/t/Asset/Wobject/Gallery/00base.t b/t/Asset/Wobject/Gallery/00base.t index 615bc9c1c..bdce13580 100644 --- a/t/Asset/Wobject/Gallery/00base.t +++ b/t/Asset/Wobject/Gallery/00base.t @@ -62,7 +62,7 @@ my $properties = $gallery->get; $gallery->purge; is( - WebGUI::Asset->newByDynamicClass($session, $properties->{assetId}), undef, + WebGUI::Asset->newById($session, $properties->{assetId}), undef, "Gallery no longer able to be instanciated", ); diff --git a/t/Asset/Wobject/GalleryAlbum/00base.t b/t/Asset/Wobject/GalleryAlbum/00base.t index 9de44c814..8414f54d5 100644 --- a/t/Asset/Wobject/GalleryAlbum/00base.t +++ b/t/Asset/Wobject/GalleryAlbum/00base.t @@ -67,7 +67,7 @@ my $properties = $album->get; $album->purge; is( - WebGUI::Asset->newByDynamicClass($session, $properties->{assetId}), undef, + WebGUI::Asset->newById($session, $properties->{assetId}), undef, "Album no longer able to be instanciated", ); diff --git a/t/Asset/Wobject/GalleryAlbum/delete.t b/t/Asset/Wobject/GalleryAlbum/delete.t index a590a81e4..bd58e20bf 100644 --- a/t/Asset/Wobject/GalleryAlbum/delete.t +++ b/t/Asset/Wobject/GalleryAlbum/delete.t @@ -96,7 +96,7 @@ $maker->prepare({ $maker->run; is( - WebGUI::Asset->newByDynamicClass( $session, $assetId ), + WebGUI::Asset->newById( $session, $assetId ), undef, "GalleryAlbum cannot be instanciated after www_deleteConfirm", ); diff --git a/t/Asset/Wobject/GalleryAlbum/edit.t b/t/Asset/Wobject/GalleryAlbum/edit.t index b250ac53a..478fb43de 100644 --- a/t/Asset/Wobject/GalleryAlbum/edit.t +++ b/t/Asset/Wobject/GalleryAlbum/edit.t @@ -109,7 +109,7 @@ $mech->content_contains( ); # Creates the album with the appropriate properties -my $album = WebGUI::Asset->newByDynamicClass( $session, $gallery->getAlbumIds->[0] ); +my $album = WebGUI::Asset->newById( $session, $gallery->getAlbumIds->[0] ); cmp_deeply( $properties, subhashof( $album->get ), "Properties from edit form are set correctly" ); #---------------------------------------------------------------------------- diff --git a/t/Asset/permissions.t b/t/Asset/permissions.t index f81c2967e..e2972ef42 100644 --- a/t/Asset/permissions.t +++ b/t/Asset/permissions.t @@ -622,14 +622,14 @@ TODO: { ################################################################ # -# newByDynamicClass +# newById # ################################################################ -my $newFixTitleAsset = WebGUI::Asset->newByDynamicClass($session, $fixTitleAsset->getId); -isnt($newFixTitleAsset, undef, 'newByDynamicClass did not fail'); -isa_ok($newFixTitleAsset, 'WebGUI::Asset', 'newByDynamicClass: able to look up an existing asset by id'); -cmp_deeply($newFixTitleAsset->{_properties}, $fixTitleAsset->{_properties}, 'newByDynamicClass created a duplicate asset'); +my $newFixTitleAsset = WebGUI::Asset->newById($session, $fixTitleAsset->getId); +isnt($newFixTitleAsset, undef, 'newById did not fail'); +isa_ok($newFixTitleAsset, 'WebGUI::Asset', 'newById: able to look up an existing asset by id'); +cmp_deeply($newFixTitleAsset->{_properties}, $fixTitleAsset->{_properties}, 'newById created a duplicate asset'); ################################################################ # diff --git a/t/Group/resetGroupFields.t b/t/Group/resetGroupFields.t index 58e7cb560..98adb58ac 100644 --- a/t/Group/resetGroupFields.t +++ b/t/Group/resetGroupFields.t @@ -107,7 +107,7 @@ is($userActivity->get('groupId'), $activityGroup->getId, 'group in Workflow Acti $assetGroup->delete; -my $newSnippet1 = WebGUI::Asset->newByDynamicClass($session, $snippet1->getId); +my $newSnippet1 = WebGUI::Asset->newById($session, $snippet1->getId); cmp_deeply( $newSnippet1->get, @@ -118,7 +118,7 @@ cmp_deeply( 'groupIdEdit updated on test snippet' ); -my $newSnippet2 = WebGUI::Asset->newByDynamicClass($session, $snippet2->getId); +my $newSnippet2 = WebGUI::Asset->newById($session, $snippet2->getId); cmp_deeply( $newSnippet2->get, @@ -129,7 +129,7 @@ cmp_deeply( 'other snippet not touched' ); -my $newSnippet3 = WebGUI::Asset->newByDynamicClass($session, $snippet3->getId); +my $newSnippet3 = WebGUI::Asset->newById($session, $snippet3->getId); cmp_deeply( $newSnippet3->get, @@ -140,7 +140,7 @@ cmp_deeply( 'multiple fields updated' ); -my $newGallery1 = WebGUI::Asset->newByDynamicClass($session, $gallery1->getId); +my $newGallery1 = WebGUI::Asset->newById($session, $gallery1->getId); cmp_deeply( $newGallery1->get, diff --git a/t/lib/WebGUI/Test.pm b/t/lib/WebGUI/Test.pm index 16fdc2c2a..86898059c 100644 --- a/t/lib/WebGUI/Test.pm +++ b/t/lib/WebGUI/Test.pm @@ -247,13 +247,13 @@ sub _mockAssetInits { # } # goto $original_new; # }; - my $original_newByDynamicClass = \&WebGUI::Asset::newById; + my $original_newById = \&WebGUI::Asset::newById; *WebGUI::Asset::newById = sub { my ($class, $session, $assetId, $revisionDate) = @_; if ($mockedAssetIds{$assetId}) { return $mockedAssetIds{$assetId}; } - goto $original_newByDynamicClass; + goto $original_newById; }; my $original_newPending = \&WebGUI::Asset::newPending; *WebGUI::Asset::newPending = sub {