From c6342a622529c8bb489046c28fe0fd2c6769bd68 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 17 May 2006 03:52:52 +0000 Subject: [PATCH] baseline testing for Asset versioning code --- t/Asset/Asset_version.t | 80 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 t/Asset/Asset_version.t diff --git a/t/Asset/Asset_version.t b/t/Asset/Asset_version.t new file mode 100644 index 000000000..82faf1817 --- /dev/null +++ b/t/Asset/Asset_version.t @@ -0,0 +1,80 @@ +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2006 Plain Black Corporation. +#------------------------------------------------------------------- +# Please read the legal notices (docs/legal.txt) and the license +# (docs/license.txt) that came with this distribution before using +# this software. +#------------------------------------------------------------------- +# http://www.plainblack.com info@plainblack.com +#------------------------------------------------------------------- + +use FindBin; +use strict; +use lib "$FindBin::Bin/../lib"; + +##The goal of this test is to check the creation and purging of +##versions. + +use WebGUI::Test; +use WebGUI::Session; +use WebGUI::Utility; +use WebGUI::Asset::Template; +use Test::More; # increment this value for each test you create +plan tests => 17; + +my $session = WebGUI::Test->session; + +my $propertyHash = { + template => q!Hi, I'm a template!, + url => '/template/versionTest', + title => 'Version Test Template', + menuTitle => 'Version Test Template', + namespace => 'Article', + className => 'WebGUI::Asset::Template', +}; + +my $root = WebGUI::Asset->getRoot($session); +my $template = $root->addChild($propertyHash); +$template->commit; + +is (ref $template, "WebGUI::Asset::Template", "Template Asset created"); +checkTableEntries($template->getId, 1,1,1); + +sleep 1; + +my $templatev2 = $template->addRevision({template => 'Hello, I am a template with formal grammar'}); +$templatev2->commit; + +is ($templatev2->getId, $template->getId, 'Both versions of the asset have the same assetId'); +checkTableEntries($templatev2->getId, 1,2,2); + +$templatev2->purgeRevision; + +checkTableEntries($templatev2->getId, 1,1,1); + +undef $templatev2; + +my $templatev2a = $template->addRevision({template => 'Hey, yall! Ima template.'}); +$templatev2a->commit; + +$template->purgeRevision; + +checkTableEntries($template->getId, 1,1,1); + +$template->purgeRevision; +checkTableEntries($template->getId, 0,0,0); + +sub checkTableEntries { + my ($assetId, $assetNum, $assetDataNum, $templateNum) = @_; + my ($count) = $session->db->quickArray('select COUNT(assetId) from asset where assetId=?', [$assetId]); + is ($count, $assetNum, + sprintf 'Expecting %d Assets with that id in asset', $assetNum); + + ($count) = $session->db->quickArray('select COUNT(assetId) from assetData where assetId=?', [$assetId]); + is ($count, $assetDataNum, + sprintf 'Expecting %d Assets with that id in assetData', $assetDataNum); + + ($count) = $session->db->quickArray('select COUNT(assetId) from template where assetId=?', [$assetId]); + is ($count, $templateNum, + sprintf 'Expecting %d Assets with that id in template', $templateNum); +}