de68a10361a2621ee3df6f666450aafaaade3726
[Business-OnlinePayment.git] / t / introspection.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use Test::More tests => 9;
6
7 {    # fake test driver 1 (no _info hash)
8
9     package Business::OnlinePayment::MOCK1;
10     use strict;
11     use warnings;
12     use base qw(Business::OnlinePayment);
13 }
14
15 {    # fake test driver 2 (with _info hash)
16
17     package Business::OnlinePayment::MOCK2;
18     use base qw(Business::OnlinePayment::MOCK1);
19     sub _info {
20       {
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',
31                                      'Authorization Only',
32                                      'Post Authorization',
33                                      'Void',
34                                      'Credit',
35                                    ],
36         'CC_void_requires_card' => 1,
37       };
38     }
39 }
40
41 my $package = "Business::OnlinePayment";
42 my @drivers = qw(MOCK1 MOCK2);
43 my $driver  = $drivers[0];
44
45 # trick to make use() happy (called in Business::OnlinePayment->new)
46 foreach my $drv (@drivers) {
47     $INC{"Business/OnlinePayment/${drv}.pm"} = "testing";
48 }
49
50
51 my $obj = $package->new($driver);
52 isa_ok( $obj, $package );
53 isa_ok( $obj, $package . "::" . $driver );
54
55 my %throwaway_actions = eval { $obj->info('supported_actions') };
56 ok( !$@, "->info('supported_actions') works w/o gateway module introspection");
57
58
59 $driver = 'MOCK2';
60 $obj = $package->new($driver);
61 isa_ok( $obj, $package );
62 isa_ok( $obj, $package . "::" . $driver );
63
64 my %actions = eval { $obj->info('supported_actions') };
65 ok( grep { $_ eq 'Void' } @{ $actions{$_} },
66     "->info('supported_actions') works w/gateway module introspection ($_)"
67   ) foreach qw( CC ECHECK );
68
69 ok($obj->info('CC_void_requires_card'),
70    'CC_void_requires_card introspection');
71 ok(!$obj->info('ECHECK_void_requires_account'),
72    'ECHECK_void_requires_account introspection');