Forward port the PayDriver bug fixes from 7.5 branch. Labels are always
taken consistently from the JSON blob, and not a mixture of the two.
This commit is contained in:
parent
3348df94da
commit
1b6dd7be63
6 changed files with 47 additions and 71 deletions
23
t/Shop/Pay.t
23
t/Shop/Pay.t
|
|
@ -33,7 +33,7 @@ my $session = WebGUI::Test->session;
|
|||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
my $tests = 19;
|
||||
my $tests = 18;
|
||||
plan tests => 1 + $tests;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
@ -106,15 +106,6 @@ throws_deeply ( sub { $gateway = $pay->addPaymentGateway('WebGUI::Shop::PayDrive
|
|||
'addPaymentGateway croaks without a configured class',
|
||||
);
|
||||
|
||||
throws_deeply ( sub { $gateway = $pay->addPaymentGateway('WebGUI::Shop::PayDriver::Cash'); },
|
||||
'WebGUI::Error::InvalidParam',
|
||||
{
|
||||
error => 'Must provide a label to create an object',
|
||||
},
|
||||
'addPaymentGateway requires a label',
|
||||
);
|
||||
|
||||
|
||||
throws_deeply ( sub { $gateway = $pay->addPaymentGateway('WebGUI::Shop::PayDriver::Cash', 'JAL'); },
|
||||
'WebGUI::Error::InvalidParam',
|
||||
{
|
||||
|
|
@ -123,7 +114,7 @@ throws_deeply ( sub { $gateway = $pay->addPaymentGateway('WebGUI::Shop::PayDrive
|
|||
'addPaymentGateway croaks without options to build a object with',
|
||||
);
|
||||
|
||||
throws_deeply ( sub { $gateway = $pay->addPaymentGateway('WebGUI::Shop::PayDriver::Cash', 'JAL', {}); },
|
||||
throws_deeply ( sub { $gateway = $pay->addPaymentGateway('WebGUI::Shop::PayDriver::Cash', {}); },
|
||||
'WebGUI::Error::InvalidParam',
|
||||
{
|
||||
error => 'You must pass a hashref of options to create a new PayDriver object',
|
||||
|
|
@ -135,9 +126,9 @@ my $options = {
|
|||
enabled => 1,
|
||||
label => 'Cold, stone hard cash',
|
||||
};
|
||||
$newDriver = $pay->addPaymentGateway('WebGUI::Shop::PayDriver::Cash', 'JAL', $options);
|
||||
$newDriver = $pay->addPaymentGateway('WebGUI::Shop::PayDriver::Cash', $options);
|
||||
isa_ok($newDriver, 'WebGUI::Shop::PayDriver::Cash', 'added a new, configured Cash driver');
|
||||
is($newDriver->label, 'JAL', 'label passed correctly to paydriver');
|
||||
is($newDriver->get('label'), 'Cold, stone hard cash', 'label passed correctly to paydriver');
|
||||
|
||||
|
||||
#TODO: check if options are stored.
|
||||
|
|
@ -212,14 +203,14 @@ my $otherOptions = {
|
|||
enabled => 1,
|
||||
label => 'Even harder cash',
|
||||
};
|
||||
$anotherDriver = $pay->addPaymentGateway('WebGUI::Shop::PayDriver::Cash', 'Pomade', $otherOptions);
|
||||
$anotherDriver = $pay->addPaymentGateway('WebGUI::Shop::PayDriver::Cash', $otherOptions);
|
||||
|
||||
my $gateways = $pay->getPaymentGateways;
|
||||
my @returnedIds = map {$_->label} @{ $gateways };
|
||||
my @returnedIds = map {$_->get('label')} @{ $gateways };
|
||||
cmp_bag(
|
||||
\@returnedIds,
|
||||
[
|
||||
qw/Cash ITransact Pomade JAL/
|
||||
qw/Cash ITransact/, 'Even harder cash', 'Cold, stone hard cash',
|
||||
],
|
||||
'getPaymentGateways returns all create payment drivers',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ my $session = WebGUI::Test->session;
|
|||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
my $tests = 49;
|
||||
my $tests = 46;
|
||||
plan tests => 1 + $tests;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
@ -150,31 +150,9 @@ cmp_deeply (
|
|||
'create takes exception to not giving it a session object',
|
||||
);
|
||||
|
||||
eval { $driver = WebGUI::Shop::PayDriver->create($session); };
|
||||
eval { $driver = WebGUI::Shop::PayDriver->create($session, {}); };
|
||||
$e = Exception::Class->caught();
|
||||
isa_ok ($e, 'WebGUI::Error::InvalidParam', 'create takes exception to not giving it a label');
|
||||
cmp_deeply (
|
||||
$e,
|
||||
methods(
|
||||
error => 'Must provide a human readable label in the hashref of options',
|
||||
),
|
||||
'create takes exception to not giving it a hashref of options',
|
||||
);
|
||||
|
||||
eval { $driver = WebGUI::Shop::PayDriver->create($session, 'Very human readable label'); };
|
||||
$e = Exception::Class->caught();
|
||||
isa_ok ($e, 'WebGUI::Error::InvalidParam', 'create takes exception to not giving it a hashref of options');
|
||||
cmp_deeply (
|
||||
$e,
|
||||
methods(
|
||||
error => 'Must provide a hashref of options',
|
||||
),
|
||||
'create takes exception to not giving it a hashref of options',
|
||||
);
|
||||
|
||||
eval { $driver = WebGUI::Shop::PayDriver->create($session, 'Very human readable label', {}); };
|
||||
$e = Exception::Class->caught();
|
||||
isa_ok ($e, 'WebGUI::Error::InvalidParam', 'create takes exception to not giving it an empty hashref of options');
|
||||
isa_ok ($e, 'WebGUI::Error::InvalidParam', 'create takes exception to giving it an empty hashref of options');
|
||||
cmp_deeply (
|
||||
$e,
|
||||
methods(
|
||||
|
|
@ -185,7 +163,6 @@ cmp_deeply (
|
|||
|
||||
# Test functionality
|
||||
|
||||
my $label = 'Human Readable Label';
|
||||
my $options = {
|
||||
label => 'Fast and harmless',
|
||||
enabled => 1,
|
||||
|
|
@ -193,19 +170,18 @@ my $options = {
|
|||
receiptMessage => 'Pannenkoeken zijn nog lekkerder met spek',
|
||||
};
|
||||
|
||||
$driver = WebGUI::Shop::PayDriver->create( $session, $label, $options );
|
||||
$driver = WebGUI::Shop::PayDriver->create( $session, $options );
|
||||
|
||||
isa_ok ($driver, 'WebGUI::Shop::PayDriver', 'create creates WebGUI::Shop::PayDriver object');
|
||||
like($driver->getId, $session->id->getValidator, 'driver id is a valid GUID');
|
||||
|
||||
my $dbData = $session->db->quickHashRef('select * from paymentGateway where paymentGatewayId=?', [ $driver->getId ]);
|
||||
|
||||
#diag ($driver->getId);
|
||||
cmp_deeply (
|
||||
$dbData,
|
||||
{
|
||||
paymentGatewayId => $driver->getId,
|
||||
className => ref $driver,
|
||||
label => $driver->label,
|
||||
options => q|{"group":3,"receiptMessage":"Pannenkoeken zijn nog lekkerder met spek","label":"Fast and harmless","enabled":1}|,
|
||||
},
|
||||
'Correct data written to the db',
|
||||
|
|
@ -213,7 +189,6 @@ cmp_deeply (
|
|||
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
# session
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue