Fix introspection with a complicated supported_actions
[Business-OnlinePayment.git] / t / introspection.t
index de68a10..8605996 100644 (file)
@@ -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");
+