From 6ad527c4a974c87b6b2c42f1304ef3f39764e7d6 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 20 Oct 2006 21:19:08 +0000 Subject: [PATCH] Bulk tests for Session::Icon Documented the disabled flag for moveDown and moveUp. Only the EMS uses this in the core as far as I can tell. Optimized out 1 profile call in getBaseURL --- lib/WebGUI/Session/Icon.pm | 13 ++- t/Session/Icon.t | 202 +++++++++++++++++++++++++++++++++++++ 2 files changed, 213 insertions(+), 2 deletions(-) create mode 100644 t/Session/Icon.t diff --git a/lib/WebGUI/Session/Icon.pm b/lib/WebGUI/Session/Icon.pm index 2abfc1edd..1039ffc6b 100644 --- a/lib/WebGUI/Session/Icon.pm +++ b/lib/WebGUI/Session/Icon.pm @@ -63,8 +63,9 @@ Returns the base URL for this user's toolbar icon set. sub getBaseURL { my $self = shift; my $url = $self->session->url->extras('toolbar/'); - if ($self->session->user->profileField("toolbar") ne "useLanguageDefault") { - $url .= $self->session->user->profileField("toolbar"); + my $toolbar = $self->session->user->profileField("toolbar"); + if ($toolbar ne "useLanguageDefault") { + $url .= $toolbar; } else { $url .= WebGUI::International->new($self->session,'Icon')->getLanguage($self->session->user->profileField("language"),"toolbar"); } @@ -361,6 +362,10 @@ Any URL parameters that need to be tacked on to the current URL to accomplish wh The URL to any page. Defaults to the current page. +=head3 disabled + +If this flag is true, the icon will be generated but no action link will be wrapped around it. + =cut sub moveDown { @@ -469,6 +474,10 @@ Any URL parameters that need to be tacked on to the current URL to accomplish wh The URL to any page. Defaults to the current page. +=head3 disabled + +If this flag is true, the icon will be generated but no action link will be wrapped around it. + =cut sub moveUp { diff --git a/t/Session/Icon.t b/t/Session/Icon.t new file mode 100644 index 000000000..b671cbb3a --- /dev/null +++ b/t/Session/Icon.t @@ -0,0 +1,202 @@ +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2006 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 +#------------------------------------------------------------------- + +use FindBin; +use strict; +use lib "$FindBin::Bin/../lib"; + +use WebGUI::Test; +use WebGUI::Session; + +use Test::More; +use Test::MockObject; +use HTML::TokeParser; + +my $numTests = 2; + +my @iconTests = fetchTestSet(); + +$numTests += scalar(@iconTests) * 4; + +plan tests => $numTests; + +my $session = WebGUI::Test->session; + +#################################################### +# +# Setup code +# Save the original user profile field toolbar +# Force $session->url->getRequestedUrl to return something useful +# +#################################################### + +my $origToolbar = $session->user->profileField('toolbar'); +my $toolbars = $session->url->extras('toolbar/'); + +my $newRequest = Test::MockObject->new; +my $requestedUrl = '/home/depot'; +$newRequest->set_bound('uri', \$requestedUrl); +$session->{_request} = $newRequest; + +my $i18n = WebGUI::International->new($session, 'Icon'); + +#################################################### +# +# getBaseURL +# +#################################################### + +$session->user->profileField('toolbar', 'useLanguageDefault'); +is($session->icon->getBaseURL, $toolbars.'bullet/', 'getBaseUrl: default English toolbar is bullet'); + +$session->user->profileField('toolbar', 'mullet'); +is($session->icon->getBaseURL, $toolbars.'mullet/', 'getBaseUrl: fetch user preference of mullet toolbar'); + +$session->user->profileField('toolbar', $origToolbar); + +#################################################### +# +# Most icon methods +# +#################################################### + +foreach my $test (@iconTests) { + my $method = $test->{method}; + my $label = $i18n->get($test->{label}); + + my $icon = $session->icon->$method($test->{urlParam}); + my ($url, $alt, $title) = linkAndText($icon); + + is($url, $session->url->gateway($requestedUrl, $test->{urlParam}), "$method: url okay"); + is($alt, $label, "$method: alt okay"); + is($title, $label, "$method: title okay"); + + $icon = $session->icon->copy($test->{urlParam2}, '/lowes'); + ($url, $alt, $title) = linkAndText($icon); + is($url, $session->url->gateway('/lowes', $test->{urlParam2}), "$method: manual url okay"); + +} + + +sub linkAndText { + my ($text) = @_; + my $p = HTML::TokeParser->new(\$text); + + my $token = $p->get_tag('a'); + my $url = $token->[1]{href} || "-"; + + $token = $p->get_tag('img'); + my $alt = $token->[1]{alt} || "-"; + my $title = $token->[1]{title} || "-"; + + return ($url, $alt, $title); +} + +#################################################### +# +# Pick up tests +# drag +# disabled for moveUp and moveDown +# confirmText for delete +# +#################################################### + +END: { + $session->user->profileField('toolbar', $origToolbar); +} + +sub fetchTestSet { + return ( + { + method => 'copy', + label => 'Copy', + urlParam => 'func=copy', + urlParam2 => 'op=copy', + }, + { + method => 'cut', + label => 'Cut', + urlParam => 'func=cut', + urlParam2 => 'op=cut', + }, + { + method => 'delete', + label => 'Delete', + urlParam => 'func=delete', + urlParam2 => 'op=delete', + }, + { + method => 'edit', + label => 'Edit', + urlParam => 'func=edit', + urlParam2 => 'op=edit', + }, + { + method => 'export', + label => 'Export', + urlParam => 'func=export', + urlParam2 => 'op=export', + }, + { + method => 'locked', + label => 'locked', + urlParam => 'func=locked', + urlParam2 => 'op=locked', + }, + { + method => 'manage', + label => 'Manage', + urlParam => 'func=manage', + urlParam2 => 'op=manage', + }, + { + method => 'moveBottom', + label => 'Move To Bottom', + urlParam => 'func=moveBottom', + urlParam2 => 'op=moveBottom', + }, + { + method => 'moveLeft', + label => 'Move Left', + urlParam => 'func=moveLeft', + urlParam2 => 'op=moveLeft', + }, + { + method => 'moveRight', + label => 'Move Right', + urlParam => 'func=moveRight', + urlParam2 => 'op=moveRight', + }, + { + method => 'moveTop', + label => 'Move To Top', + urlParam => 'func=moveTop', + urlParam2 => 'op=moveTop', + }, + { + method => 'moveUp', + label => 'Move Up', + urlParam => 'func=moveUp', + urlParam2 => 'op=moveUp', + }, + { + method => 'shortcut', + label => 'Create Shortcut', + urlParam => 'func=shortcut', + urlParam2 => 'op=shortcut', + }, + { + method => 'view', + label => 'View', + urlParam => 'func=view', + urlParam2 => 'op=view', + }, + ); +}