Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# Copyright 2015 Koha Development team |
4 |
# |
5 |
# This file is part of Koha |
6 |
# |
7 |
# Koha is free software; you can redistribute it and/or modify it |
8 |
# under the terms of the GNU General Public License as published by |
9 |
# the Free Software Foundation; either version 3 of the License, or |
10 |
# (at your option) any later version. |
11 |
# |
12 |
# Koha is distributed in the hope that it will be useful, but |
13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
# GNU General Public License for more details. |
16 |
# |
17 |
# You should have received a copy of the GNU General Public License |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
19 |
|
20 |
use Modern::Perl; |
21 |
use Test::More tests => 5; |
22 |
|
23 |
# use t::lib::Mocks; |
24 |
use Koha::Database; |
25 |
|
26 |
use t::lib::TestBuilder; |
27 |
my $builder = t::lib::TestBuilder->new(); |
28 |
|
29 |
my $schema = Koha::Database->new->schema; |
30 |
$schema->storage->txn_begin; |
31 |
|
32 |
my $dbh = C4::Context->dbh; |
33 |
$dbh->{AutoCommit} = 0; |
34 |
$dbh->{RaiseError} = 1; |
35 |
|
36 |
# ########## Tests start here ############################# |
37 |
# Given ... we can use the module |
38 |
BEGIN { use_ok('Koha::Account'); } |
39 |
|
40 |
subtest 'test_methods' => sub { |
41 |
plan tests => 1; |
42 |
|
43 |
# Given ... we can reach the method(s) |
44 |
my @methods = ( |
45 |
'pay', |
46 |
); |
47 |
can_ok('Koha::Account', @methods); |
48 |
}; |
49 |
|
50 |
# Given ... a random patron_id, a Koha::Account object can be created |
51 |
my $patron_id_0 = 654321; |
52 |
|
53 |
# When ... |
54 |
my $koha_account_0 = Koha::Account->new( { patron_id => $patron_id_0 } ); |
55 |
|
56 |
# Then ... |
57 |
isa_ok($koha_account_0, 'Koha::Account'); |
58 |
is($koha_account_0->{patron_id}, $patron_id_0, 'Got the expected patron_id value from calling Koha:;Account->new()'); |
59 |
|
60 |
# FIXME pay() method does not deal with absence of parameters and die on |
61 |
# Use of uninitialized value $amount in subtraction (-) at /var/koha/Koha/Koha/Account.pm line 175 |
62 |
# ... |
63 |
# Given ... calling on pay() with no params - just for fun. |
64 |
# my $params_1 = {}; |
65 |
|
66 |
# When ... Then ... |
67 |
# my $payment_id_1 = $koha_account_0->pay($params_1); |
68 |
# is($payment_id_1, undef, 'Got the expected undef payment id from Koha account pay with no params'); |
69 |
|
70 |
# Given ... an amount parameter and a borrower number |
71 |
my $amount_2 = 90; |
72 |
my $params_2 = { amount => $amount_2, }; |
73 |
|
74 |
$dbh->do("INSERT INTO borrowers(borrowernumber, surname, address, city, branchcode, categorycode, userid) VALUES ('.$patron_id_0.','Washington','address','city', 'IPT', 'HB', 'userid')"); |
75 |
|
76 |
# When ... |
77 |
my $payment_id_2 = $koha_account_0->pay($params_2); |
78 |
|
79 |
# Then ... |
80 |
ok($payment_id_2, 'Got some data back from Koha account pay with an amount'); |
81 |
|
82 |
# my $sth_2 = $dbh->prepare('SELECT * FROM accountlines WHERE borrowernumber = ?'); |
83 |
# my $acc_line = $sth_2->execute($patron_id_0); |
84 |
# my $result_2 = $sth_2->fetchrow(); |
85 |
|
86 |
|
87 |
$schema->storage->txn_rollback; |
88 |
|
89 |
1; |