Add Copy with children Asset Helper

This commit is contained in:
Colin Kuskie 2009-11-27 09:37:56 -08:00
parent 9eadb2642a
commit 80a6b90353
4 changed files with 146 additions and 2 deletions

View file

@ -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;

View file

@ -1382,6 +1382,12 @@ Couldn't open %-s because %-s <br />
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;

View file

@ -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 });
}

View file

@ -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