5 use Test::More tests => 13;
7 { # fake test driver 1 (no _info hash)
9 package Business::OnlinePayment::MOCK1;
12 use base qw(Business::OnlinePayment);
15 { # fake test driver 2 (with _info hash)
17 package Business::OnlinePayment::MOCK2;
18 use base qw(Business::OnlinePayment::MOCK1);
21 'info_compat' => '0.01', # always 0.01 for now,
22 # 0.02 will have requirements
23 'gateway_name' => 'Example Gateway',
24 'gateway_url' => 'http://www.example.com/',
25 'module_version' => '0.01', #$VERSION,
26 'supported_types' => [ qw( CC ECHECK ) ],
27 'token_support' => 0, #card storage/tokenization support
28 'test_transaction' => 0, #set true if ->test_transaction(1) works
29 'supported_actions' => [
30 'Normal Authorization',
36 'CC_void_requires_card' => 1,
41 { # fake test driver 3 (with _info hash)
43 package Business::OnlinePayment::MOCK3;
44 use base qw(Business::OnlinePayment::MOCK1);
47 'info_compat' => '0.01', # always 0.01 for now,
48 # 0.02 will have requirements
49 'gateway_name' => 'Example Gateway',
50 'gateway_url' => 'http://www.example.com/',
51 'module_version' => '0.01', #$VERSION,
52 'supported_types' => [ qw( CC ECHECK ) ],
54 'test_transaction' => 1,
55 'supported_actions' => { 'CC' => [
56 'Normal Authorization',
61 'Recurring Authorization',
62 'Modify Recurring Authorization',
63 'Cancel Recurring Authorization',
66 'Normal Authorization',
75 my $package = "Business::OnlinePayment";
76 my @drivers = qw(MOCK1 MOCK2 MOCK3);
77 my $driver = $drivers[0];
79 # trick to make use() happy (called in Business::OnlinePayment->new)
80 foreach my $drv (@drivers) {
81 $INC{"Business/OnlinePayment/${drv}.pm"} = "testing";
85 my $obj = $package->new($driver);
86 isa_ok( $obj, $package );
87 isa_ok( $obj, $package . "::" . $driver );
89 my %throwaway_actions = eval { $obj->info('supported_actions') };
90 ok( !$@, "->info('supported_actions') works w/o gateway module introspection");
94 $obj = $package->new($driver);
95 isa_ok( $obj, $package );
96 isa_ok( $obj, $package . "::" . $driver );
98 my %actions = eval { $obj->info('supported_actions') };
99 ok( grep { $_ eq 'Void' } @{ $actions{$_} },
100 "->info('supported_actions') works w/gateway module introspection ($_)"
101 ) foreach qw( CC ECHECK );
103 ok($obj->info('CC_void_requires_card'),
104 'CC_void_requires_card introspection');
105 ok(!$obj->info('ECHECK_void_requires_account'),
106 'ECHECK_void_requires_account introspection');
110 $obj = $package->new($driver);
111 isa_ok( $obj, $package );
112 isa_ok( $obj, $package . "::" . $driver );
114 %actions = eval { $obj->info('supported_actions') };
115 ok( grep { $_ eq 'Authorization Only' } @{ $actions{CC} },
116 "->info('supported_actions') w/hashref supported_actions");
117 ok( ! grep { $_ eq 'Authorization Only' } @{ $actions{ECHECK} },
118 "->info('supported_actions') w/hashref supported_actions");