From dc226e3268613c557ed2dc7c26f4001bb001da56 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 20 Jul 2009 15:31:32 +0000 Subject: [PATCH] canUse should check whether the driver is enabled or not. PayDrivers update the local object cache on update. --- docs/changelog/7.x.x.txt | 2 ++ lib/WebGUI/Shop/PayDriver.pm | 10 ++++++++-- t/Shop/PayDriver.t | 30 +++++++++++++++++++++++++----- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 2db2bf1d7..808d4590b 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -4,6 +4,8 @@ - fixed #10662: Manage Clipboard / delete item - fixed #10637: shelf displays assets it shouldn't - fixed #10660: Crud doesn't like 0 + - fixed #10668: shop pay drivers + - fixed Pay Drivers update their objects 7.7.15 - fixed #10629: WebGUI::ProfileField create new field bug diff --git a/lib/WebGUI/Shop/PayDriver.pm b/lib/WebGUI/Shop/PayDriver.pm index 5c772c45f..e3f4958bf 100644 --- a/lib/WebGUI/Shop/PayDriver.pm +++ b/lib/WebGUI/Shop/PayDriver.pm @@ -13,6 +13,7 @@ use WebGUI::Macro; use WebGUI::User; use WebGUI::Shop::Cart; use JSON; +use Clone qw/clone/; use Scalar::Util qw/blessed/; =head1 NAME @@ -87,7 +88,9 @@ sub cancelRecurringPayment { =head2 canUse ( user ) -Checks to see if the user can use this Payment Driver. +Checks to see if the user can use this Payment Driver. Ability to use +is based on whether or not this user has the correct privileges, and if +the driver is enabled or not. =head3 user @@ -107,6 +110,7 @@ A user object that will be used directly. sub canUse { my $self = shift; + return 0 unless $self->get('enabled'); my $user = shift; my $userObject; if (!defined $user or ref($user) ne 'HASH') { @@ -304,7 +308,7 @@ sub get { return $options->{ $param }; } else { - return { %$options }; + return { %{ $options } }; } } @@ -729,6 +733,8 @@ sub update { $jsonOptions, $self->paymentGatewayId ]); + my $storedProperties = clone $properties; + $options{ id $self } = $storedProperties; return; } diff --git a/t/Shop/PayDriver.t b/t/Shop/PayDriver.t index 81152e0f0..8bb46ea3b 100644 --- a/t/Shop/PayDriver.t +++ b/t/Shop/PayDriver.t @@ -31,7 +31,7 @@ my $session = WebGUI::Test->session; #---------------------------------------------------------------------------- # Tests -my $tests = 46; +my $tests = 54; plan tests => 1 + $tests; #---------------------------------------------------------------------------- @@ -415,7 +415,7 @@ TODO: { ####################################################################### # -# update +# update, get # ####################################################################### @@ -438,27 +438,47 @@ my $newOptions = { }; $driver->update($newOptions); -my $storedOptions = $session->db->quickScalar('select options from paymentGateway where paymentGatewayId=?', [ +my $storedJson = $session->db->quickScalar('select options from paymentGateway where paymentGatewayId=?', [ $driver->getId, ]); cmp_deeply( $newOptions, - from_json($storedOptions), + from_json($storedJson), , 'update() actually stores data', ); +is( $driver->get('receiptMessage'), 'Dropjes!', '... updates object, receiptMessage'); +is( $driver->get('group'), 4, '... updates object, group'); +is( $driver->get('enabled'), 0, '... updates object, enabled'); +is( $driver->get('label'), 'Yet another label', '... updates object, label'); + +$newOptions->{label} = 'Safe reference'; +is( $driver->get('label'), 'Yet another label', '... safe reference check'); + +my $storedOptions = $driver->get(); +$storedOptions->{label} = 'Safe reference'; +is( $driver->get('label'), 'Yet another label', 'get: safe reference check'); ####################################################################### # # canUse # ####################################################################### +$options = $driver->get(); +$options->{enabled} = 1; +$driver->update($options); $session->user({userId => 3}); -ok($driver->canUse, 'canUse: session->user is used if no argument is passed'); +ok( $driver->canUse, 'canUse: session->user is used if no argument is passed'); ok(!$driver->canUse({userId => 1}), 'canUse: userId explicit works, visitor cannot use this driver'); +$options = $driver->get(); +$options->{enabled} = 0; +$driver->update($options); +ok( !$driver->get('enabled'), 'driver is disabled'); +ok( !$driver->canUse({userId => 3}), '... driver cannot be used'); + TODO: { local $TODO = 'tests for canUse'; ok(0, 'Test other users and groups');