Add group privilege checking to the Shipping Drivers
This commit is contained in:
parent
0a004d72a0
commit
a85924d07b
9 changed files with 166 additions and 20 deletions
|
|
@ -20,6 +20,7 @@ use Test::More;
|
|||
use Test::Deep;
|
||||
use JSON;
|
||||
use HTML::Form;
|
||||
use Data::Dumper;
|
||||
|
||||
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||
use WebGUI::Session;
|
||||
|
|
@ -149,7 +150,7 @@ cmp_deeply(
|
|||
'addShipper croaks without options to build a object with',
|
||||
);
|
||||
|
||||
$driver = $ship->addShipper('WebGUI::Shop::ShipDriver::FlatRate', { enabled=>1, label=>q{Jake's Jailbird Airmail}});
|
||||
$driver = $ship->addShipper('WebGUI::Shop::ShipDriver::FlatRate', { enabled=>1, label=>q{Jake's Jailbird Airmail}, groupToUse=>7});
|
||||
isa_ok($driver, 'WebGUI::Shop::ShipDriver::FlatRate', 'added a new, configured FlatRate driver');
|
||||
|
||||
#######################################################################
|
||||
|
|
@ -159,9 +160,10 @@ isa_ok($driver, 'WebGUI::Shop::ShipDriver::FlatRate', 'added a new, configured F
|
|||
#######################################################################
|
||||
|
||||
my $shippers;
|
||||
$driver2 = $ship->addShipper('WebGUI::Shop::ShipDriver::FlatRate', { enabled=>0, label=>q{Tommy's cut-rate shipping}});
|
||||
$driver2 = $ship->addShipper('WebGUI::Shop::ShipDriver::FlatRate', { enabled=>0, label=>q{Tommy's cut-rate shipping}, groupToUse=>7});
|
||||
|
||||
$shippers = $ship->getShippers();
|
||||
|
||||
is(scalar @{$shippers}, 3, 'getShippers: got both shippers, even though one is not enabled');
|
||||
|
||||
my @shipperNames = map { $_->get("label") } @{ $shippers };
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ my $session = WebGUI::Test->session;
|
|||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
my $tests = 37;
|
||||
my $tests = 44;
|
||||
plan tests => 1 + $tests;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
@ -84,7 +84,13 @@ cmp_deeply(
|
|||
label => ignore(),
|
||||
hoverHelp => ignore(),
|
||||
defaultValue => 1,
|
||||
}
|
||||
},
|
||||
groupToUse => {
|
||||
fieldType => 'group',
|
||||
label => ignore(),
|
||||
hoverHelp => ignore(),
|
||||
defaultValue => 7,
|
||||
},
|
||||
}
|
||||
} ],
|
||||
,
|
||||
|
|
@ -151,8 +157,9 @@ cmp_deeply(
|
|||
);
|
||||
|
||||
my $options = {
|
||||
label => 'Slow and dangerous',
|
||||
enabled => 1,
|
||||
label => 'Slow and dangerous',
|
||||
enabled => 1,
|
||||
groupToUse => 7,
|
||||
};
|
||||
|
||||
$driver = WebGUI::Shop::ShipDriver->create( $session, $options );
|
||||
|
|
@ -174,7 +181,7 @@ cmp_deeply(
|
|||
{
|
||||
shipperId => $driver->getId,
|
||||
className => ref($driver),
|
||||
options => q|{"label":"Slow and dangerous","enabled":1}|,
|
||||
options => q|{"groupToUse":7,"label":"Slow and dangerous","enabled":1}|,
|
||||
},
|
||||
'Correct data written to the db',
|
||||
);
|
||||
|
|
@ -216,7 +223,7 @@ my @forms = HTML::Form->parse($html, 'http://www.webgui.org');
|
|||
is (scalar @forms, 1, 'getEditForm generates just 1 form');
|
||||
|
||||
my @inputs = $forms[0]->inputs;
|
||||
is (scalar @inputs, 7, 'getEditForm: the form has 7 controls');
|
||||
is (scalar @inputs, 9, 'getEditForm: the form has 9 controls');
|
||||
|
||||
my @interestingFeatures;
|
||||
foreach my $input (@inputs) {
|
||||
|
|
@ -256,6 +263,14 @@ cmp_deeply(
|
|||
name => 'enabled',
|
||||
type => 'radio',
|
||||
},
|
||||
{
|
||||
name => 'groupToUse',
|
||||
type => 'option',
|
||||
},
|
||||
{
|
||||
name => '__groupToUse_isIn',
|
||||
type => 'hidden',
|
||||
},
|
||||
],
|
||||
'getEditForm made the correct form with all the elements'
|
||||
|
||||
|
|
@ -306,12 +321,10 @@ cmp_deeply(
|
|||
|
||||
my $driverCopy = WebGUI::Shop::ShipDriver->new($session, $driver->getId);
|
||||
|
||||
is($driver->getId, $driverCopy->getId, 'same id');
|
||||
is(ref $driver, ref $driverCopy, 'same className');
|
||||
is($driver->getId, $driverCopy->getId, 'same id');
|
||||
is(ref $driver, ref $driverCopy, 'same className');
|
||||
cmp_deeply($driver->get, $driverCopy->get, 'same options');
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
# calculate
|
||||
|
|
@ -323,7 +336,7 @@ like ($@, qr/^You must override the calculate method/, 'calculate croaks to forc
|
|||
|
||||
#######################################################################
|
||||
#
|
||||
# update
|
||||
# update, get
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
|
|
@ -338,6 +351,37 @@ cmp_deeply(
|
|||
'update takes exception to not giving it a hashref of options',
|
||||
);
|
||||
|
||||
isa_ok( $driver->get(), 'HASH', 'get returns a hashref if called with no param');
|
||||
|
||||
use Data::Dumper;
|
||||
diag Dumper $driver->get();
|
||||
|
||||
is($driver->get('groupToUse'), 7, '... default group is 7');
|
||||
|
||||
$options = $driver->get();
|
||||
$options->{groupToUse} = 3;
|
||||
|
||||
is($driver->get('groupToUse'), 7, '... get returns a safe hashref');
|
||||
|
||||
$driver->update($options);
|
||||
is($driver->get('groupToUse'), 3, '... update groupToUse to 3');
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
# canUse
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
$session->user({userId => 1});
|
||||
ok(! $driver->canUse, 'canUse, Visitor cannot use this driver since it is set to Admin');
|
||||
$session->user({userId => 3});
|
||||
ok( $driver->canUse, '... Admin can use this driver');
|
||||
|
||||
$options = $driver->get();
|
||||
$options->{groupToUse} = 7;
|
||||
$session->user({userId => 1});
|
||||
ok(! $driver->canUse, '... reset to group Everyone, and Visitor can use it');
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
# delete
|
||||
|
|
|
|||
|
|
@ -116,6 +116,12 @@ cmp_deeply(
|
|||
hoverHelp => ignore(),
|
||||
defaultValue => 1,
|
||||
},
|
||||
groupToUse => {
|
||||
fieldType => 'group',
|
||||
label => ignore(),
|
||||
hoverHelp => ignore(),
|
||||
defaultValue => 7,
|
||||
},
|
||||
}
|
||||
} ],
|
||||
'Definition returns an array of hashrefs',
|
||||
|
|
@ -167,7 +173,7 @@ my @forms = HTML::Form->parse($html, 'http://www.webgui.org');
|
|||
is (scalar @forms, 1, 'getEditForm generates just 1 form');
|
||||
|
||||
my @inputs = $forms[0]->inputs;
|
||||
is (scalar @inputs, 11, 'getEditForm: the form has 11 controls');
|
||||
is (scalar @inputs, 13, 'getEditForm: the form has 13 controls');
|
||||
|
||||
my @interestingFeatures;
|
||||
foreach my $input (@inputs) {
|
||||
|
|
@ -207,6 +213,14 @@ cmp_deeply(
|
|||
name => 'enabled',
|
||||
type => 'radio',
|
||||
},
|
||||
{
|
||||
name => 'groupToUse',
|
||||
type => 'option',
|
||||
},
|
||||
{
|
||||
name => '__groupToUse_isIn',
|
||||
type => 'hidden',
|
||||
},
|
||||
{
|
||||
name => 'flatFee',
|
||||
type => 'text',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue