Large batch of test fixes, most for newByDynamicClass -> newById

This commit is contained in:
Colin Kuskie 2010-05-13 20:02:26 -07:00
parent c74894321d
commit 5140ece731
17 changed files with 41 additions and 39 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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",
);

View file

@ -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",
);

View file

@ -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",
);

View file

@ -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" );
#----------------------------------------------------------------------------

View file

@ -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');
################################################################
#

View file

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

View file

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