1b654add58426600191d450349a883991e45d9b8
[freeside.git] / FS / t / suite / 13-tokenization.t
1 #!/usr/bin/perl
2
3 use FS::Test;
4 use Test::More tests => 8;
5 use FS::Conf;
6
7 ### can only run on test database (company name "Freeside Test")
8 ### will run upgrade, which uses lots of prints & warns beyond regular test output
9
10 my $fs = FS::Test->new( user => 'admin' );
11 my $conf = new_ok('FS::Conf');
12 my $err;
13 my $bopconf;
14
15 like( $conf->config('company_name'), qr/^Freeside Test/, 'using test database' ) or BAIL_OUT('');
16
17 # some pre-upgrade cleanup, upgrade will fail if these are still configured
18 foreach my $cust_main ( $fs->qsearch('cust_main') ) {
19   my @count = $fs->qsearch('agent_payment_gateway', { agentnum => $cust_main->agentnum } );
20   if (@count > 1) {
21     note("DELETING CARDTYPE GATEWAYS");
22     foreach my $apg (@count) {
23       $err = $apg->delete if $apg->cardtype;
24       last if $err;
25     }
26     @count = $fs->qsearch('agent_payment_gateway', { agentnum => $cust_main->agentnum } );
27     if (@count > 1) {
28       $err = "Still found ".@count." gateways for custnum ".$cust_main->custnum;
29       last;
30     }
31   }
32 }
33 ok( !$err, "remove obsolete payment gateways" ) or BAIL_OUT($err);
34
35 $bopconf = 
36 'IPPay
37 TESTTERMINAL';
38 $conf->set('business-onlinepayment' => $bopconf);
39 is( join("\n",$conf->config('business-onlinepayment')), $bopconf, "setting first default gateway" ) or BAIL_OUT('');
40
41 $err = system('freeside-upgrade','admin');
42 ok( !$err, 'initial upgrade' ) or BAIL_OUT('Error string: '.$!);
43
44 $bopconf =
45 'CardFortress
46 cardfortresstest
47 (TEST54)
48 Normal Authorization
49 gateway
50 IPPay
51 gateway_login
52 TESTTERMINAL
53 gateway_password
54
55 private_key
56 /usr/local/etc/freeside/cardfortresstest.txt';
57 $conf->set('business-onlinepayment' => $bopconf);
58 is( join("\n",$conf->config('business-onlinepayment')), $bopconf, "setting tokenizable default gateway" ) or BAIL_OUT('');
59
60 foreach my $pg ($fs->qsearch('payment_gateway')) {
61   unless ($pg->gateway_module eq 'CardFortress') {
62     note('UPGRADING NON-CF PAYMENT GATEWAY');
63     my %pgopts = (
64       gateway          => $pg->gateway_module,
65       gateway_login    => $pg->gateway_username,
66       gateway_password => $pg->gateway_password,
67       private_key      => '/usr/local/etc/freeside/cardfortresstest.txt',
68     );
69     $pg->gateway_module('CardFortress');
70     $pg->gateway_username('cardfortresstest');
71     $pg->gateway_password('(TEST54)');
72     $err = $pg->replace(\%pgopts);
73     last if $err;
74   }
75 }
76 ok( !$err, "remove non-CF payment gateways" ) or BAIL_OUT($err);
77
78 $err = system('freeside-upgrade','admin');
79 ok( !$err, 'tokenizable upgrade' ) or BAIL_OUT('Error string: '.$!);
80
81 1;
82