From 237ba58597d5e9c8472b942a550d849905ca0268 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 29 Jul 2011 19:55:45 +0000 Subject: [PATCH] Fix introspection with a complicated supported_actions --- Changes | 1 + MANIFEST | 1 + OnlinePayment.pm | 4 ++-- t/introspection.t | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 53 insertions(+), 4 deletions(-) diff --git a/Changes b/Changes index 1fe256f..de58e25 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,7 @@ Revision history for Perl extension Business::OnlinePayment. 3.02 unreleased - Fix fatal error calling ->info('supported_actions') on a gateway that does not yet support introspection (e.g. AuthorizeNet) + - Fix introspection with a complicated supported_actions - Documentation fix for recurring_billing flag - Add optional transaction field to documentation: currency - Fix spelling mistake in preCharge.pm POD, thanks to gregor herrmann, diff --git a/MANIFEST b/MANIFEST index 2e80dec..9063c11 100644 --- a/MANIFEST +++ b/MANIFEST @@ -11,6 +11,7 @@ t/bop_https.t t/bop.t t/fd_precharge.t t/pod.t +t/introspection.t notes_for_module_writers notes_for_module_writers_v3 META.yml Module meta-data (added by MakeMaker) diff --git a/OnlinePayment.pm b/OnlinePayment.pm index 8c421e1..0c9d2ff 100644 --- a/OnlinePayment.pm +++ b/OnlinePayment.pm @@ -56,10 +56,10 @@ sub _info { }, 'supported_actions' => sub { my( $class, $v ) = @_; - return $v if ref($v) eq 'HASH'; + return %$v if ref($v) eq 'HASH'; $v = [ $v ] unless ref($v); my $types = $class->info('supported_types') || {}; - { map { $_ => $v } keys %$types }; + ( map { $_ => $v } keys %$types ); }, ); diff --git a/t/introspection.t b/t/introspection.t index de68a10..8605996 100644 --- a/t/introspection.t +++ b/t/introspection.t @@ -2,7 +2,7 @@ use strict; use warnings; -use Test::More tests => 9; +use Test::More tests => 13; { # fake test driver 1 (no _info hash) @@ -38,8 +38,42 @@ use Test::More tests => 9; } } +{ # fake test driver 3 (with _info hash) + + package Business::OnlinePayment::MOCK3; + use base qw(Business::OnlinePayment::MOCK1); + sub _info { + { + 'info_compat' => '0.01', # always 0.01 for now, + # 0.02 will have requirements + 'gateway_name' => 'Example Gateway', + 'gateway_url' => 'http://www.example.com/', + 'module_version' => '0.01', #$VERSION, + 'supported_types' => [ qw( CC ECHECK ) ], + 'token_support' => 1, + 'test_transaction' => 1, + 'supported_actions' => { 'CC' => [ + 'Normal Authorization', + 'Authorization Only', + 'Post Authorization', + 'Void', + 'Credit', + 'Recurring Authorization', + 'Modify Recurring Authorization', + 'Cancel Recurring Authorization', + ], + 'ECHECK' => [ + 'Normal Authorization', + 'Void', + 'Credit', + ], + }, + }; + } +} + my $package = "Business::OnlinePayment"; -my @drivers = qw(MOCK1 MOCK2); +my @drivers = qw(MOCK1 MOCK2 MOCK3); my $driver = $drivers[0]; # trick to make use() happy (called in Business::OnlinePayment->new) @@ -70,3 +104,16 @@ ok($obj->info('CC_void_requires_card'), 'CC_void_requires_card introspection'); ok(!$obj->info('ECHECK_void_requires_account'), 'ECHECK_void_requires_account introspection'); + + +$driver = 'MOCK3'; +$obj = $package->new($driver); +isa_ok( $obj, $package ); +isa_ok( $obj, $package . "::" . $driver ); + +%actions = eval { $obj->info('supported_actions') }; +ok( grep { $_ eq 'Authorization Only' } @{ $actions{CC} }, + "->info('supported_actions') w/hashref supported_actions"); +ok( ! grep { $_ eq 'Authorization Only' } @{ $actions{ECHECK} }, + "->info('supported_actions') w/hashref supported_actions"); + -- 2.11.0