From 5375fbbf8f34bb6be755684fe99ef596c3dc3bdf Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 30 Nov 2009 17:31:42 -0800 Subject: [PATCH] AssetManager Helper, which just opens a tab to the ContentHandler. --- lib/WebGUI/AssetHelper/Manage.pm | 58 ++++++++++++++++++++++ t/AssetHelper/Manage.t | 84 ++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 lib/WebGUI/AssetHelper/Manage.pm create mode 100644 t/AssetHelper/Manage.t diff --git a/lib/WebGUI/AssetHelper/Manage.pm b/lib/WebGUI/AssetHelper/Manage.pm new file mode 100644 index 000000000..cdd1aac32 --- /dev/null +++ b/lib/WebGUI/AssetHelper/Manage.pm @@ -0,0 +1,58 @@ +package WebGUI::AssetHelper::Manage; + +use strict; +use Class::C3; +use base qw/WebGUI::AssetHelper/; +use WebGUI::User; +use WebGUI::HTML; + +=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::Manage + +=head1 DESCRIPTION + +Displays the asset manager, starting at this Asset. + +=head1 METHODS + +These methods are available from this class: + +=cut + +#------------------------------------------------------------------- + +=head2 process ( $class, $asset ) + +Opens a new tab for displaying the Asset Manager, starting at this Asset. + +=cut + +sub process { + my ($class, $asset) = @_; + my $session = $asset->session; + my $i18n = WebGUI::International->new($session, "Asset"); + if (! $asset->canEdit) { + return { + error => $i18n->get('38', 'WebGUI'), + } + } + + return { + open_tab => $asset->getManagerUrl, + }; +} + +1; diff --git a/t/AssetHelper/Manage.t b/t/AssetHelper/Manage.t new file mode 100644 index 000000000..86d5e96fc --- /dev/null +++ b/t/AssetHelper/Manage.t @@ -0,0 +1,84 @@ +# 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::Manage; + +#---------------------------------------------------------------------------- +# Init +my $session = WebGUI::Test->session; + + +#---------------------------------------------------------------------------- +# Tests + +plan tests => 2; # Increment this number for each test you create + +#---------------------------------------------------------------------------- +# put your tests here + +my $output; +my $home = WebGUI::Asset->getDefault($session); + +$session->user({userId => 3}); + +my $versionTag = WebGUI::VersionTag->getWorking($session); + +my $newPage = $home->addChild({ + className => 'WebGUI::Asset::Wobject::Layout', + title => 'Test page', +}, undef, undef, { skipAutoCommitWorkflows => 1, }); + +my $article1 = $newPage->addChild({ + className => 'WebGUI::Asset::Wobject::Article', + title => 'Article_1', +}, undef, undef, { skipAutoCommitWorkflows => 1, }); + +my $article2 = $newPage->addChild({ + className => 'WebGUI::Asset::Wobject::Article', + title => 'Article_2', +}, undef, undef, { skipAutoCommitWorkflows => 1, }); + +$versionTag->commit; +addToCleanup($versionTag); + +$session->user({userId => 1}); +$output = WebGUI::AssetHelper::Manage->process($article2); +cmp_deeply( + $output, + { + error => re('You do not have sufficient privileges'), + }, + 'AssetHelper/Promote checks for editing privileges' +); + +$session->user({userId => 3}); +$output = WebGUI::AssetHelper::Manage->process($article2); +cmp_deeply( + $output, + { + open_tab => $article2->getManagerUrl, + }, + 'AssetHelper/Promote returns a message' +); + +#vim:ft=perl