Change this test to use a Snippet instead of a Template.

This commit is contained in:
Colin Kuskie 2010-01-25 22:52:25 -08:00
parent d66b3b891b
commit e940dc0427

View file

@ -18,19 +18,19 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test; use WebGUI::Test;
use WebGUI::Session; use WebGUI::Session;
use WebGUI::Utility; use WebGUI::Utility;
use WebGUI::Asset::Template; use WebGUI::Asset::Snippet;
use Test::More; # increment this value for each test you create use Test::More; # increment this value for each test you create
plan tests => 26; plan tests => 26;
my $session = WebGUI::Test->session; my $session = WebGUI::Test->session;
my $propertyHash = { my $propertyHash = {
template => "Hi, I'm a template", template => "Hi, I'm a snippet",
url => '/template/versionTest', url => '/template/versionTest',
title => 'Version Test Template', title => 'Version Test Snippet',
menuTitle => 'Version Test Template', menuTitle => 'Version Test Snippet',
namespace => 'Article', namespace => 'Snippet',
className => 'WebGUI::Asset::Template', className => 'WebGUI::Asset::Snippet',
}; };
my $root = WebGUI::Asset->getRoot($session); my $root = WebGUI::Asset->getRoot($session);
@ -44,35 +44,35 @@ my $originalVersionTags = $session->db->quickScalar(q{select count(*) from asset
################################################################ ################################################################
note "purgeRevision tests"; note "purgeRevision tests";
my $template = $root->addChild($propertyHash); my $snippet = $root->addChild($propertyHash);
$template->commit; $snippet->commit;
is (ref $template, "WebGUI::Asset::Template", "Template Asset created"); isa_ok $snippet, "WebGUI::Asset::Snippet";
checkTableEntries($template->getId, 1,1,1,1); checkTableEntries($snippet->getId, 1,1,1,1);
sleep 1; sleep 1;
my $templatev2 = $template->addRevision({template => 'Hello, I am a template with formal grammar'}); my $snippetv2 = $snippet->addRevision({snippet => 'Hello, I am a snippet with formal grammar'});
$templatev2->commit; $snippetv2->commit;
is ($templatev2->getId, $template->getId, 'Both versions of the asset have the same assetId'); is ($snippetv2->getId, $snippet->getId, 'Both versions of the asset have the same assetId');
checkTableEntries($templatev2->getId, 1,2,2,1); checkTableEntries($snippetv2->getId, 1,2,2,1);
$templatev2->purgeRevision; $snippetv2->purgeRevision;
checkTableEntries($templatev2->getId, 1,1,1,1); checkTableEntries($snippetv2->getId, 1,1,1,1);
undef $templatev2; undef $snippetv2;
my $templatev2a = $template->addRevision({template => 'Hey, yall! Ima template.'}); my $snippetv2a = $snippet->addRevision({snippet => 'Hey, yall! Ima snippet.'});
$templatev2a->commit; $snippetv2a->commit;
$template->purgeRevision; $snippet->purgeRevision;
checkTableEntries($template->getId, 1,1,1,1); checkTableEntries($snippet->getId, 1,1,1,1);
$template->purgeRevision; $snippet->purgeRevision;
checkTableEntries($template->getId, 0,0,0,0); checkTableEntries($snippet->getId, 0,0,0,0);
my $versionTagCheck; my $versionTagCheck;
$versionTagCheck = $session->db->quickScalar(q{select count(*) from assetVersionTag}); $versionTagCheck = $session->db->quickScalar(q{select count(*) from assetVersionTag});
@ -84,22 +84,22 @@ is($versionTagCheck, $originalVersionTags, 'version tag cleaned up by deleting l
# #
################################################################ ################################################################
$template = $root->addChild($propertyHash); $snippet = $root->addChild($propertyHash);
my $tag1 = WebGUI::VersionTag->getWorking($session); my $tag1 = WebGUI::VersionTag->getWorking($session);
$tag1->commit; $tag1->commit;
WebGUI::Test->tagsToRollback($tag1); WebGUI::Test->tagsToRollback($tag1);
sleep 1; sleep 1;
$templatev2 = $template->addRevision({template => 'Vie gates. Ich bin ein templater.'}); $snippetv2 = $snippet->addRevision({snippet => 'Vie gates. Ich bin ein snippetr.'});
my $tag2 = WebGUI::VersionTag->getWorking($session); my $tag2 = WebGUI::VersionTag->getWorking($session);
$tag2->commit; $tag2->commit;
WebGUI::Test->tagsToRollback($tag2); WebGUI::Test->tagsToRollback($tag2);
note "purge"; note "purge";
checkTableEntries($templatev2->getId, 1,2,2); checkTableEntries($snippetv2->getId, 1,2,2);
$versionTagCheck = $session->db->quickScalar(q{select count(*) from assetVersionTag}); $versionTagCheck = $session->db->quickScalar(q{select count(*) from assetVersionTag});
is($versionTagCheck, $originalVersionTags+2, 'created two version tags'); is($versionTagCheck, $originalVersionTags+2, 'created two version tags');
$template->purge; $snippet->purge;
checkTableEntries($templatev2->getId, 0,0,0); checkTableEntries($snippetv2->getId, 0,0,0);
$versionTagCheck = $session->db->quickScalar(q{select count(*) from assetVersionTag}); $versionTagCheck = $session->db->quickScalar(q{select count(*) from assetVersionTag});
is($versionTagCheck, $originalVersionTags, 'purge deleted both tags'); is($versionTagCheck, $originalVersionTags, 'purge deleted both tags');
@ -110,7 +110,7 @@ is($versionTagCheck, $originalVersionTags, 'purge deleted both tags');
################################################################ ################################################################
sub checkTableEntries { sub checkTableEntries {
my ($assetId, $assetNum, $assetDataNum, $templateNum) = @_; my ($assetId, $assetNum, $assetDataNum, $snippetNum) = @_;
my ($count) = $session->db->quickArray('select COUNT(*) from asset where assetId=?', [$assetId]); my ($count) = $session->db->quickArray('select COUNT(*) from asset where assetId=?', [$assetId]);
is ($count, $assetNum, is ($count, $assetNum,
sprintf 'Expecting %d Assets with that id in asset', $assetNum); sprintf 'Expecting %d Assets with that id in asset', $assetNum);
@ -119,7 +119,7 @@ sub checkTableEntries {
is ($count, $assetDataNum, is ($count, $assetDataNum,
sprintf 'Expecting %d Assets with that id in assetData', $assetDataNum); sprintf 'Expecting %d Assets with that id in assetData', $assetDataNum);
($count) = $session->db->quickArray('select COUNT(*) from template where assetId=?', [$assetId]); ($count) = $session->db->quickArray('select COUNT(*) from snippet where assetId=?', [$assetId]);
is ($count, $templateNum, is ($count, $snippetNum,
sprintf 'Expecting %d Assets with that id in template', $templateNum); sprintf 'Expecting %d Assets with that id in snippet', $snippetNum);
} }