From 39ffaba487774ba8f2980568c982a1fa46c44d3a Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 27 Nov 2009 09:46:14 -0800 Subject: [PATCH] Add copy with descendants. --- lib/WebGUI/AssetHelper/Copy/WithChildren.pm | 3 +- .../AssetHelper/Copy/WithDescendants.pm | 58 ++++++++++++++ lib/WebGUI/i18n/English/Asset.pm | 6 ++ t/AssetHelper/Copy/WithDescendants.t | 78 +++++++++++++++++++ 4 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 lib/WebGUI/AssetHelper/Copy/WithDescendants.pm create mode 100644 t/AssetHelper/Copy/WithDescendants.t diff --git a/lib/WebGUI/AssetHelper/Copy/WithChildren.pm b/lib/WebGUI/AssetHelper/Copy/WithChildren.pm index 980c43000..880a1e71b 100644 --- a/lib/WebGUI/AssetHelper/Copy/WithChildren.pm +++ b/lib/WebGUI/AssetHelper/Copy/WithChildren.pm @@ -34,8 +34,7 @@ These methods are available from this class: =head2 duplicate ( $class, $asset ) -Duplicates the asset. Extracted out so that it can be subclassed by copy with children, -and copy with descendants. +Duplicates the asset with children, =cut diff --git a/lib/WebGUI/AssetHelper/Copy/WithDescendants.pm b/lib/WebGUI/AssetHelper/Copy/WithDescendants.pm new file mode 100644 index 000000000..b0e3600b5 --- /dev/null +++ b/lib/WebGUI/AssetHelper/Copy/WithDescendants.pm @@ -0,0 +1,58 @@ +package WebGUI::AssetHelper::Copy::WithDescendants; + +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::WithDescendants + +=head1 DESCRIPTION + +Copy an Asset to the Clipboard, with all descendants. + +=head1 METHODS + +These methods are available from this class: + +=cut + +#------------------------------------------------------------------- + +=head2 duplicate ( $class, $asset ) + +Duplicates the asset with descendants. + +=cut + +sub duplicate { + my ($class, $asset) = @_; + return $asset->duplicateBranch(); +} + +#------------------------------------------------------------------- + +=head2 getMessage ( ) + +Returns the name of the i18n message to use + +=cut + +sub getMessage { + return 'copied asset with descendants'; +} + +1; diff --git a/lib/WebGUI/i18n/English/Asset.pm b/lib/WebGUI/i18n/English/Asset.pm index 2a71c0ab8..300189fc7 100644 --- a/lib/WebGUI/i18n/English/Asset.pm +++ b/lib/WebGUI/i18n/English/Asset.pm @@ -1388,6 +1388,12 @@ Couldn't open %-s because %-s
context => q{%s will be replaced by the title of the asset.}, }, + 'copied asset with descendants' => { + message => q{Asset %s was copied to the clipboard with all descendants.}, + lastUpdated => 0, + context => q{%s will be replaced by the title of the asset.}, + }, + }; 1; diff --git a/t/AssetHelper/Copy/WithDescendants.t b/t/AssetHelper/Copy/WithDescendants.t new file mode 100644 index 000000000..d44f394bc --- /dev/null +++ b/t/AssetHelper/Copy/WithDescendants.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::WithDescendants; + +#---------------------------------------------------------------------------- +# 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::WithDescendants->process($home); + cmp_deeply( + $output, + { + message => re('was copied to the clipboard with all descendants'), + }, + 'AssetHelper/Copy/WithDescendants redirects the back to the copied asset' + ); + + my $clippies = $root->getLineage(["descendants"], {statesToInclude => [qw{clipboard clipboard-limbo}], returnObjects => 1,}); + is @{ $clippies }, 27, '... only copied the asset to the clipboard with children'; + addToCleanup(@{ $clippies }); +} + +{ + $session->setting->set('skipCommitComments', 0); + + $output = WebGUI::AssetHelper::Copy::WithDescendants->process($home); + cmp_deeply( + $output, + { + message => re('was copied to the clipboard with all descendants'), + open_tab => re('^'.$home->getUrl), + }, + 'AssetHelper/Copy/WithDescendants opens a tab for commit comments' + ); + + my $clippies = $home->getAssetsInClipboard(); + addToCleanup(@{ $clippies }); +} + +#vim:ft=perl