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
This commit is contained in:
parent
d5be2abcf3
commit
6ad527c4a9
2 changed files with 213 additions and 2 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
202
t/Session/Icon.t
Normal file
202
t/Session/Icon.t
Normal file
|
|
@ -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',
|
||||
},
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue