From 80a6b90353a824560fa9c006747f44e1ad6ad03c Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 27 Nov 2009 09:37:56 -0800 Subject: [PATCH] Add Copy with children Asset Helper --- lib/WebGUI/AssetHelper/Copy/WithChildren.pm | 59 ++++++++++++++++ lib/WebGUI/i18n/English/Asset.pm | 6 ++ t/AssetHelper/Copy.t | 5 +- t/AssetHelper/Copy/WithChildren.t | 78 +++++++++++++++++++++ 4 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 lib/WebGUI/AssetHelper/Copy/WithChildren.pm create mode 100644 t/AssetHelper/Copy/WithChildren.t diff --git a/lib/WebGUI/AssetHelper/Copy/WithChildren.pm b/lib/WebGUI/AssetHelper/Copy/WithChildren.pm new file mode 100644 index 000000000..980c43000 --- /dev/null +++ b/lib/WebGUI/AssetHelper/Copy/WithChildren.pm @@ -0,0 +1,59 @@ +package WebGUI::AssetHelper::Copy::WithChildren; + +use strict; +use Class::C3; +use base qw/WebGUI::AssetHelper::Copy/; + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2009 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 + ------------------------------------------------------------------- + +=head1 NAME + +Package WebGUI::AssetHelper::Copy::WithChildren + +=head1 DESCRIPTION + +Copy an Asset to the Clipboard, with children only. + +=head1 METHODS + +These methods are available from this class: + +=cut + +#------------------------------------------------------------------- + +=head2 duplicate ( $class, $asset ) + +Duplicates the asset. Extracted out so that it can be subclassed by copy with children, +and copy with descendants. + +=cut + +sub duplicate { + my ($class, $asset) = @_; + return $asset->duplicateBranch(1); +} + +#------------------------------------------------------------------- + +=head2 getMessage ( ) + +Returns the name of the i18n message to use + +=cut + +sub getMessage { + return 'copied asset with children'; +} + +1; diff --git a/lib/WebGUI/i18n/English/Asset.pm b/lib/WebGUI/i18n/English/Asset.pm index 128acc023..2a71c0ab8 100644 --- a/lib/WebGUI/i18n/English/Asset.pm +++ b/lib/WebGUI/i18n/English/Asset.pm @@ -1382,6 +1382,12 @@ Couldn't open %-s because %-s
context => q{%s will be replaced by the title of the asset.}, }, + 'copied asset with children' => { + message => q{Asset %s was copied to the clipboard with its children.}, + lastUpdated => 0, + context => q{%s will be replaced by the title of the asset.}, + }, + }; 1; diff --git a/t/AssetHelper/Copy.t b/t/AssetHelper/Copy.t index 25171015f..df52d9b32 100644 --- a/t/AssetHelper/Copy.t +++ b/t/AssetHelper/Copy.t @@ -38,6 +38,7 @@ plan tests => 3; # Increment this number for each test you create my $output; my $home = WebGUI::Asset->getDefault($session); +my $root = WebGUI::Asset->getRoot($session); { @@ -50,7 +51,7 @@ my $home = WebGUI::Asset->getDefault($session); 'AssetHelper/Copy redirects the back to the copied asset' ); - my $clippies = $home->getAssetsInClipboard(); + my $clippies = $root->getLineage(["descendants"], {statesToInclude => [qw{clipboard clipboard-limbo}], returnObjects => 1,}); is @{ $clippies }, 1, '... only copied 1 asset to the clipboard, no children'; addToCleanup(@{ $clippies }); } @@ -68,7 +69,7 @@ my $home = WebGUI::Asset->getDefault($session); 'AssetHelper/Copy opens a tab for commit comments' ); - my $clippies = $home->getAssetsInClipboard(); + my $clippies = $root->getLineage(["descendants"], {statesToInclude => [qw{clipboard clipboard-limbo}], returnObjects => 1,}); addToCleanup(@{ $clippies }); } diff --git a/t/AssetHelper/Copy/WithChildren.t b/t/AssetHelper/Copy/WithChildren.t new file mode 100644 index 000000000..98050e9b5 --- /dev/null +++ b/t/AssetHelper/Copy/WithChildren.t @@ -0,0 +1,78 @@ +# vim:syntax=perl +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2009 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 +#------------------------------------------------------------------ + +# Write a little about what this script tests. +# +# + +use FindBin; +use strict; +use lib "$FindBin::Bin/../../lib"; +use Test::More; +use Test::Deep; +use WebGUI::Test; # Must use this before any other WebGUI modules +use WebGUI::Session; +use WebGUI::Asset; +use WebGUI::AssetHelper::Copy::WithChildren; + +#---------------------------------------------------------------------------- +# Init +my $session = WebGUI::Test->session; + + +#---------------------------------------------------------------------------- +# Tests + +plan tests => 3; # Increment this number for each test you create + +#---------------------------------------------------------------------------- +# put your tests here + +my $output; +my $home = WebGUI::Asset->getDefault($session); +my $root = WebGUI::Asset->getRoot($session); + +$session->user({userId => 3}); + +{ + + $output = WebGUI::AssetHelper::Copy::WithChildren->process($home); + cmp_deeply( + $output, + { + message => re('was copied to the clipboard with its children'), + }, + 'AssetHelper/Copy redirects the back to the copied asset' + ); + + my $clippies = $root->getLineage(["descendants"], {statesToInclude => [qw{clipboard clipboard-limbo}], returnObjects => 1,}); + is @{ $clippies }, 10, '... only copied the asset to the clipboard with children'; + addToCleanup(@{ $clippies }); +} + +{ + $session->setting->set('skipCommitComments', 0); + + $output = WebGUI::AssetHelper::Copy::WithChildren->process($home); + cmp_deeply( + $output, + { + message => re('was copied to the clipboard with its children'), + open_tab => re('^'.$home->getUrl), + }, + 'AssetHelper/Copy/WithChildren opens a tab for commit comments' + ); + + my $clippies = $home->getAssetsInClipboard(); + addToCleanup(@{ $clippies }); +} + +#vim:ft=perl