From 7018d38f15784ad52e8eee4cdb460e1ee9cf188b Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 20 Jul 2007 23:04:43 +0000 Subject: [PATCH] Refactor out the Wobject level www_edit code that switches between Add Wobject and Edit Wobject into an Asset level method. Convert Wobject.pm and Snippet.pm to use it. Build a very bare bones test method for it. --- lib/WebGUI/Asset.pm | 18 +++++++++++++++++- lib/WebGUI/Asset/Snippet.pm | 4 +--- lib/WebGUI/Asset/Wobject.pm | 4 +--- t/Asset/Asset.t | 25 ++++++++++++++++++------- 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 8c8b52273..8219c4809 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -57,6 +57,22 @@ These methods are available from this class: =cut +#------------------------------------------------------------------- + +=head2 addEditLabel ( ) + +Generate an internationalized label for the add/edit screens that says +whether you're adding or editing an Asset, for clarity. + +=cut + +sub addEditLabel { + my $self = shift; + my $i18n = WebGUI::International->new($self->session,'Asset_Wobject'); + my $addEdit = ($self->session->form->process("func") eq 'add') ? $i18n->get('add') : $i18n->get('edit'); + return $addEdit.' '.$self->getName; +} + #------------------------------------------------------------------- =head2 addMissing ( url ) @@ -2065,7 +2081,7 @@ The asset url you'd like to check for. head3 options -A hash reference of optional parameters. +A hash reference of optional parameters that can be passed to refine the search. head4 assetId diff --git a/lib/WebGUI/Asset/Snippet.pm b/lib/WebGUI/Asset/Snippet.pm index 65ed991bb..5bcf7fa66 100644 --- a/lib/WebGUI/Asset/Snippet.pm +++ b/lib/WebGUI/Asset/Snippet.pm @@ -178,9 +178,7 @@ sub www_edit { return $self->session->privilege->insufficient() unless $self->canEdit; return $self->session->privilege->locked() unless $self->canEditIfLocked; $self->getAdminConsole->setHelp("snippet add/edit","Asset_Snippet"); - my $i18n = WebGUI::International->new($self->session,'Asset_Wobject'); - my $addEdit = ($self->session->form->process("func") eq 'add') ? $i18n->get('add') : $i18n->get('edit'); - return $self->getAdminConsole->render($self->getEditForm->print,$addEdit.' '.$self->getName); + return $self->getAdminConsole->render($self->getEditForm->print,$self->addEditLabel); } diff --git a/lib/WebGUI/Asset/Wobject.pm b/lib/WebGUI/Asset/Wobject.pm index 2978c3286..7293b44a7 100644 --- a/lib/WebGUI/Asset/Wobject.pm +++ b/lib/WebGUI/Asset/Wobject.pm @@ -493,9 +493,7 @@ sub www_edit { $tag =~ s/([a-z])([A-Z])/$1 $2/g; #Separate studly caps $tag =~ s/([A-Z]+(?![a-z]))/$1 /g; #Separate acronyms $self->getAdminConsole->setHelp(lc($tag)." add/edit", "Asset_".$tag2); - my $i18n = WebGUI::International->new($self->session,'Asset_Wobject'); - my $addEdit = ($self->session->form->process("func") eq 'add') ? $i18n->get('add') : $i18n->get('edit'); - return $self->getAdminConsole->render($self->getEditForm->print,$addEdit.' '.$self->getName); + return $self->getAdminConsole->render($self->getEditForm->print,$self->addEditLabel); } diff --git a/t/Asset/Asset.t b/t/Asset/Asset.t index d3ffe4c7f..65397198d 100644 --- a/t/Asset/Asset.t +++ b/t/Asset/Asset.t @@ -17,7 +17,7 @@ use WebGUI::Session; use WebGUI::Asset; use WebGUI::Asset::Wobject::Navigation; -use Test::More tests => 25; # increment this value for each test you create +use Test::More tests => 27; # increment this value for each test you create my $session = WebGUI::Test->session; @@ -102,13 +102,24 @@ is($importNode->getParent->getId, $rootAsset->getId, 'Import Nodes parent is Roo # ################################################################ -##We need as asset with a URL for this one. +##We need an asset with a URL for this one. my $importUrl = $importNode->get('url'); my $importId = $importNode->getId; -ok( WebGUI::Asset->urlExists($session, $importUrl), 'url for import node exists'); -ok( !WebGUI::Asset->urlExists($session, '/foo/bar/baz'), 'made up url does not exist'); -ok( !WebGUI::Asset->urlExists($session, $importUrl, {assetId => $importId}), 'url for import node only exists at specific id'); -ok( !WebGUI::Asset->urlExists($session, '/foo/bar/baz', {assetId => $importId}), 'imaginary url does not exist at specific id'); -ok( WebGUI::Asset->urlExists($session, $importUrl, {assetId => 'notAnWebGUIId'}), 'imaginary url does not exist at wrong id'); +ok( WebGUI::Asset->urlExists($session, $importUrl), 'url for import node exists'); +ok( WebGUI::Asset->urlExists($session, uc($importUrl)), 'url for import node exists, case insensitive'); +ok( !WebGUI::Asset->urlExists($session, '/foo/bar/baz'), 'made up url does not exist'); + +ok( !WebGUI::Asset->urlExists($session, $importUrl, {assetId => $importId}), 'url for import node only exists at specific id'); +ok( !WebGUI::Asset->urlExists($session, '/foo/bar/baz', {assetId => $importId}), 'imaginary url does not exist at specific id'); +ok( WebGUI::Asset->urlExists($session, $importUrl, {assetId => 'notAnWebGUIId'}), 'imaginary url does not exist at wrong id'); + +################################################################ +# +# addEditLabel +# +################################################################ + +my $i18n = WebGUI::International->new($session, 'Asset_Wobject'); +is($importNode->addEditLabel, $i18n->get('edit').' '.$importNode->getName, 'addEditLabel, default mode is edit mode');