From 913ed8ec265e25b58e3d7184d96f8df6d0d94c4f Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sat, 25 Oct 2008 20:33:24 +0000 Subject: [PATCH] reset isDefault to 0 on copy, 8921 --- docs/changelog/7.x.x.txt | 2 +- lib/WebGUI/Asset/Template.pm | 16 ++++++++++++++++ t/Asset/Template.t | 10 ++++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 84f162e36..8cbd5bff7 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -33,7 +33,7 @@ - fixed: Site Nav navigation template can now be used more than once per page - added: TextArea now supports "maxlength" attribute - added: DataForm can now run a workflow when an entry is added - + - Fixed #8921: Duplicating templates through conventional methods maintains default template flag 7.6.1 - changed: the list of extensions for the export system to pass through diff --git a/lib/WebGUI/Asset/Template.pm b/lib/WebGUI/Asset/Template.pm index c2a3cb0c4..f54c04797 100644 --- a/lib/WebGUI/Asset/Template.pm +++ b/lib/WebGUI/Asset/Template.pm @@ -105,6 +105,22 @@ sub definition { #------------------------------------------------------------------- +=head2 duplicate + +Subclass the duplicate method so that the isDefault flag is set to 0 on any +copy. + +=cut + +sub duplicate { + my $self = shift; + my $newTemplate = $self->SUPER::duplicate; + $newTemplate->update({isDefault => 0}); + return $newTemplate; +} + +#------------------------------------------------------------------- + sub processPropertiesFromFormPost { my $self = shift; $self->SUPER::processPropertiesFromFormPost; diff --git a/t/Asset/Template.t b/t/Asset/Template.t index 756dd4b62..e81ef02fd 100644 --- a/t/Asset/Template.t +++ b/t/Asset/Template.t @@ -15,7 +15,7 @@ use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; use WebGUI::Asset::Template; -use Test::More tests => 11; # increment this value for each test you create +use Test::More tests => 13; # increment this value for each test you create use Test::Deep; my $session = WebGUI::Test->session; @@ -52,5 +52,11 @@ ok(exists $newList->{$template->getId}, 'Uncommitted template exists returned fr my $newList2 = WebGUI::Asset::Template->getList($session, 'WebGUI Test Template', "assetData.status='approved'"); ok(!exists $newList2->{$template->getId}, 'extra clause to getList prevents uncommitted template from being displayed'); -$template->purge; +$template->update({isDefault=>1}); +is($template->get('isDefault'), 1, 'isDefault set to 1'); +my $templateCopy = $template->duplicate(); +is($templateCopy->get('isDefault'), 0, 'isDefault set to 0 on copy'); + +$template->purge; +$templateCopy->purge;