From b8e088ff7a8445bb97ab4eabad07fe436781fac1 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 28 Dec 2011 11:11:21 -0800 Subject: [PATCH] Refactor Session/Icon to remove a bunch of copy/paste code. Update test to remove deprecated profileField calls. --- lib/WebGUI/Session/Icon.pm | 132 ++++++++++++++----------------------- t/Session/Icon.t | 17 ++--- 2 files changed, 54 insertions(+), 95 deletions(-) diff --git a/lib/WebGUI/Session/Icon.pm b/lib/WebGUI/Session/Icon.pm index 99ab00c71..58a5a8834 100644 --- a/lib/WebGUI/Session/Icon.pm +++ b/lib/WebGUI/Session/Icon.pm @@ -75,6 +75,30 @@ sub getBaseURL { } +#------------------------------------------------------------------- + +=head2 _basic ( ) + +Returns a basic icon with i18n title and alt text. + +=cut + +sub _basic { + my $self = shift; + my $i18n_tag = shift; + my $icon_name = shift; + my $url_params = shift; + my $pageURL = shift || $self->session->url->getRequestedUrl; + my $i18n = WebGUI::International->new($self->session,'Icon'); + my $tag = $i18n->get($i18n_tag); + my $output = ''; + $output .= ''.$tag.''; + return $output; +} + + #------------------------------------------------------------------- =head2 copy ( urlParameters [, pageURL ] ) @@ -93,13 +117,8 @@ file will be prepended to it. =cut sub copy { - my $self = shift; - my $urlParams = shift; - my $pageURL = shift || $self->session->url->getRequestedUrl; - my $i18n = WebGUI::International->new($self->session,'Icon'); - my $output = ''; - $output .= ''.$i18n->get('Copy').''; - return $output; + my $self = shift; + return $self->_basic('Copy', 'copy.gif', @_); } #------------------------------------------------------------------- @@ -120,13 +139,8 @@ file will be prepended to it. =cut sub cut { - my $self = shift; - my $urlParams = shift; - my $pageURL = shift || $self->session->url->getRequestedUrl; - my $i18n = WebGUI::International->new($self->session,'Icon'); - my $output = ''; - $output .= ''.$i18n->get('Cut').''; - return $output; + my $self = shift; + return $self->_basic('Cut', 'cut.gif', @_); } #------------------------------------------------------------------- @@ -202,13 +216,8 @@ file will be prepended to it. =cut sub edit { - my $self = shift; - my $urlParams = shift; - my $pageURL = shift || $self->session->url->getRequestedUrl; - my $i18n = WebGUI::International->new($self->session,'Icon'); - my $output = ''; - $output .= ''.$i18n->get('Edit').''; - return $output; + my $self = shift; + return $self->_basic('Edit', 'edit.gif', @_); } #------------------------------------------------------------------- @@ -230,13 +239,8 @@ file will be prepended to it. =cut sub export { - my $self = shift; - my $urlParams = shift; - my $pageURL = shift || $self->session->url->getRequestedUrl; - my $i18n = WebGUI::International->new($self->session,'Icon'); - my $output = ''; - $output .= ''.$i18n->get('Export').''; - return $output; + my $self = shift; + return $self->_basic('Export', 'export.gif', @_); } #------------------------------------------------------------------- @@ -283,13 +287,8 @@ file will be prepended to it. =cut sub locked { - my $self = shift; - my $urlParams = shift; - my $pageURL = shift || $self->session->url->getRequestedUrl; - my $i18n = WebGUI::International->new($self->session,'Icon'); - my $output = ''; - $output .= ''.$i18n->get('locked').''; - return $output; + my $self = shift; + return $self->_basic('locked', 'locked.gif', @_); } #------------------------------------------------------------------- @@ -311,13 +310,8 @@ file will be prepended to it. =cut sub manage { - my $self = shift; - my $urlParams = shift; - my $pageURL = shift || $self->session->url->getRequestedUrl; - my $i18n = WebGUI::International->new($self->session,'Icon'); - my $output = ''; - $output .= ''.$i18n->get('Manage').''; - return $output; + my $self = shift; + return $self->_basic('Manage', 'manage.gif', @_); } #------------------------------------------------------------------- @@ -339,13 +333,8 @@ file will be prepended to it. =cut sub moveBottom { - my $self = shift; - my $urlParams = shift; - my $pageURL = shift || $self->session->url->getRequestedUrl; - my $i18n = WebGUI::International->new($self->session,'Icon'); - my $output = ''; - $output .= ''.$i18n->get('Move To Bottom').''; - return $output; + my $self = shift; + return $self->_basic('Move To Bottom', 'moveBotom.gif', @_); } #------------------------------------------------------------------- @@ -403,13 +392,8 @@ file will be prepended to it. =cut sub moveLeft { - my $self = shift; - my $urlParams = shift; - my $pageURL = shift || $self->session->url->getRequestedUrl; - my $i18n = WebGUI::International->new($self->session,'Icon'); - my $output = ''; - $output .= ''.$i18n->get('Move Left').''; - return $output; + my $self = shift; + return $self->_basic('Move Left', 'moveLeft.gif', @_); } #------------------------------------------------------------------- @@ -431,13 +415,8 @@ file will be prepended to it. =cut sub moveRight { - my $self = shift; - my $urlParams = shift; - my $pageURL = shift || $self->session->url->getRequestedUrl; - my $i18n = WebGUI::International->new($self->session,'Icon'); - my $output = ''; - $output .= ''.$i18n->get('Move Right').''; - return $output; + my $self = shift; + return $self->_basic('Move Right', 'moveRight.gif', @_); } #------------------------------------------------------------------- @@ -459,13 +438,8 @@ file will be prepended to it. =cut sub moveTop { - my $self = shift; - my $urlParams = shift; - my $pageURL = shift || $self->session->url->getRequestedUrl; - my $i18n = WebGUI::International->new($self->session,'Icon'); - my $output = ''; - $output .= ''.$i18n->get('Move To Top').''; - return $output; + my $self = shift; + return $self->_basic('Move To Top', 'moveTop.gif', @_); } #------------------------------------------------------------------- @@ -559,13 +533,8 @@ file will be prepended to it. =cut sub shortcut { - my $self = shift; - my $urlParams = shift; - my $pageURL = shift || $self->session->url->getRequestedUrl; - my $i18n = WebGUI::International->new($self->session,'Icon'); - my $output = ''; - $output .= ''.$i18n->get('Create Shortcut').''; - return $output; + my $self = shift; + return $self->_basic('Create Shortcut', 'shortcut.gif', @_); } #------------------------------------------------------------------- @@ -587,13 +556,8 @@ file will be prepended to it. =cut sub view { - my $self = shift; - my $urlParams = shift; - my $pageURL = shift || $self->session->url->getRequestedUrl; - my $i18n = WebGUI::International->new($self->session,'Icon'); - my $output = ''; - $output .= ''.$i18n->get('View').''; - return $output; + my $self = shift; + return $self->_basic('View', 'view.gif', @_); } diff --git a/t/Session/Icon.t b/t/Session/Icon.t index 3819d874d..e5ffc20d7 100644 --- a/t/Session/Icon.t +++ b/t/Session/Icon.t @@ -18,14 +18,8 @@ use Test::Deep; use Test::MockObject; use HTML::TokeParser; -my $numTests = 10; - my @iconTests = fetchTestSet(); -$numTests += scalar(@iconTests) * 4; - -plan tests => $numTests; - my $session = WebGUI::Test->session; #################################################### @@ -36,8 +30,8 @@ my $session = WebGUI::Test->session; # #################################################### -my $origToolbar = $session->user->profileField('toolbar'); -WebGUI::Test->addToCleanup(sub { $session->user->profileField('toolbar', $origToolbar); },); +my $origToolbar = $session->user->get('toolbar'); +WebGUI::Test->addToCleanup(sub { $session->user->update('toolbar', $origToolbar); },); my $toolbars = $session->url->extras('toolbar/'); my $request = $session->request; @@ -52,13 +46,13 @@ my $i18n = WebGUI::International->new($session, 'Icon'); # #################################################### -$session->user->profileField('toolbar', 'useLanguageDefault'); +$session->user->update('toolbar', 'useLanguageDefault'); is($session->icon->getBaseURL, $toolbars.'bullet/', 'getBaseUrl: default English toolbar is bullet'); -$session->user->profileField('toolbar', 'mullet'); +$session->user->update('toolbar', 'mullet'); is($session->icon->getBaseURL, $toolbars.'mullet/', 'getBaseUrl: fetch user preference of mullet toolbar'); -$session->user->profileField('toolbar', $origToolbar); +$session->user->update('toolbar', $origToolbar); #################################################### # @@ -154,6 +148,7 @@ SKIP: { cmp_bag(\@toolbarDirs, \@toolbarOptionDirs, 'getToolbarOptions'); } +done_testing; sub linkAndText { my ($text, $tag, @params) = @_;