From f36a30f2b992d1bb56c4c53d35a9cf0c70cd4cbb Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 9 Apr 2010 11:46:36 -0700 Subject: [PATCH] Refactor out code to build an asset with a real parent. Add purge tests. --- t/tests/Test/WebGUI/Asset.pm | 40 ++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/t/tests/Test/WebGUI/Asset.pm b/t/tests/Test/WebGUI/Asset.pm index c79c13d7d..11027e5bb 100644 --- a/t/tests/Test/WebGUI/Asset.pm +++ b/t/tests/Test/WebGUI/Asset.pm @@ -15,6 +15,7 @@ use Test::Deep; use Test::Exception; use WebGUI::Test; use WebGUI::Utility; +use Data::Dumper; sub assetUiLevel { return 1; @@ -28,6 +29,20 @@ sub parent_list { return []; } +sub getAnchoredAsset { + my $test = shift; + my $session = $test->session; + my $tag = WebGUI::VersionTag->getWorking($session); + my @parents = $test->getMyParents; + my $asset = $parents[-1]->addChild({ + className => $test->class, + }, undef, undef, {skipNotification => 1, skipAutoCommitWorkflows => 1,}); + WebGUI::Test->addToCleanup($asset); + $tag->commit; + WebGUI::Test->addToCleanup($tag); + return ($tag, $asset, @parents); +} + sub getMyParents { my $test = shift; my $session = $test->session; @@ -58,6 +73,7 @@ sub _constructor : Test(4) { $asset = eval { WebGUI::Asset->new($session, ''); }; my $e = Exception::Class->caught; isa_ok $e, 'WebGUI::Error'; + } sub title : Test(6) { @@ -195,14 +211,7 @@ sub write_update : Test(8) { sub keywords : Test(3) { my $test = shift; my $session = $test->session; - my $tag = WebGUI::VersionTag->getWorking($session); - my @parents = $test->getMyParents; - my $asset = $parents[-1]->addChild({ - className => $test->class, - }, undef, undef, {skipNotification => 1, skipAutoCommitWorkflows => 1,}); - WebGUI::Test->addToCleanup($asset); - $tag->commit; - WebGUI::Test->addToCleanup($tag); + my ($tag, $asset, @parents) = $test->getAnchoredAsset(); can_ok $asset, 'keywords'; $asset->keywords('chess set'); is $asset->keywords, 'chess set', 'set and get of keywords via direct accessor'; @@ -300,6 +309,21 @@ sub scan_properties : Test(1) { or diag "except these: ".join ", ", @undefined_tables; } +sub purge : Test(3) { + note "purge"; + my $test = shift; + my $session = $test->session; + my ($tag, $asset, @parents) = $test->getAnchoredAsset(); + my @tables = $asset->meta->get_tables; + ok $asset->purge, 'purge returns true if it was purged'; + throws_ok { WebGUI::Asset->newById($session, $asset->assetId); } 'WebGUI::Error::InvalidParam', 'Unable to fetch asset by assetId now'; + my $exists_in_table = 0; + foreach my $table (@tables) { + $exists_in_table ||= $session->db->quickScalar("select count(*) from `$table` where assetId=?",[$asset->assetId]); + } + ok ! $exists_in_table, 'assetId removed from all asset tables'; +} + 1;