Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# Copyright 2015 Vaara-kirjastot |
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; |
22 |
use Try::Tiny; |
23 |
use Scalar::Util qw(blessed); |
24 |
|
25 |
use C4::Accounts; |
26 |
|
27 |
use t::lib::TestObjects::ObjectFactory; |
28 |
use t::lib::TestObjects::BorrowerFactory; |
29 |
|
30 |
##Setting up the test context |
31 |
my $testContext = {}; |
32 |
|
33 |
my $password = '1234'; |
34 |
my $borrowerFactory = t::lib::TestObjects::BorrowerFactory->new(); |
35 |
my $borrowers = $borrowerFactory->createTestGroup([ |
36 |
{firstname => 'Olli-Antti', |
37 |
surname => 'Kivi', |
38 |
cardnumber => '1A01', |
39 |
branchcode => 'CPL', |
40 |
password => $password, |
41 |
}, |
42 |
{firstname => 'Alli-Ontti', |
43 |
surname => 'Ivik', |
44 |
cardnumber => '1A02', |
45 |
branchcode => 'CPL', |
46 |
password => $password, |
47 |
}, |
48 |
{firstname => 'NoFines', |
49 |
surname => 'Angel', |
50 |
cardnumber => '1A03', |
51 |
branchcode => 'CPL', |
52 |
password => $password, |
53 |
}, |
54 |
], undef, $testContext); |
55 |
|
56 |
##Test context set, starting testing: |
57 |
subtest "Get all Borrowers with Fines" => \&getAllBorrowersWithFines; |
58 |
sub getAllBorrowersWithFines { |
59 |
eval { #run in a eval-block so we don't die without tearing down the test context |
60 |
my $borrowerKivi = $borrowers->{'1A01'}; |
61 |
my $borrowerIvik = $borrowers->{'1A02'}; |
62 |
|
63 |
#What happens if there are only good Borrowers? |
64 |
my $badBorrowers = C4::Accounts::GetAllBorrowersWithUnpaidFines(); |
65 |
ok(ref($badBorrowers) eq 'ARRAY', |
66 |
"GetAllBorrowersWithUnpaidFines, no results is still an ARRAYRef"); |
67 |
|
68 |
C4::Accounts::manualinvoice($borrowerKivi->borrowernumber, undef, 'TESTIS1', 'F', 1.123456, 'NOTED'); |
69 |
C4::Accounts::manualinvoice($borrowerKivi->borrowernumber, undef, 'TESTIS2', 'F', 2, 'NOTED'); |
70 |
C4::Accounts::manualinvoice($borrowerKivi->borrowernumber, undef, 'TESTIS3', 'F', 3, 'NOTED'); |
71 |
C4::Accounts::manualinvoice($borrowerIvik->borrowernumber, undef, 'TESTIS1', 'F', 1.123456, 'NOTED'); |
72 |
C4::Accounts::manualinvoice($borrowerIvik->borrowernumber, undef, 'TESTIS2', 'F', 2, 'NOTED'); |
73 |
C4::Accounts::manualinvoice($borrowerIvik->borrowernumber, undef, 'TESTIS3', 'F', 3, 'NOTED'); |
74 |
C4::Accounts::manualinvoice($borrowerIvik->borrowernumber, undef, 'TESTIS4', 'F', 4, 'NOTED'); |
75 |
|
76 |
$badBorrowers = C4::Accounts::GetAllBorrowersWithUnpaidFines(); |
77 |
is($borrowerKivi->cardnumber, |
78 |
$badBorrowers->[0]->{cardnumber}, |
79 |
"Got the correct bad Borrower '".$borrowerKivi->cardnumber."'"); |
80 |
is($badBorrowers->[0]->{amountoutstanding}, |
81 |
6.123456, |
82 |
"Got the correct unpaid fines '6'"); |
83 |
is($borrowerIvik->cardnumber, |
84 |
$badBorrowers->[1]->{cardnumber}, |
85 |
"Got the correct bad Borrower '".$borrowerIvik->cardnumber."'"); |
86 |
is($badBorrowers->[1]->{amountoutstanding}, |
87 |
10.123456, |
88 |
"Got the correct unpaid fines '10'"); |
89 |
ok(not(defined($badBorrowers->[2])), |
90 |
"Good Borrower not on the bad Borrowers list"); |
91 |
|
92 |
}; |
93 |
if ($@) { #Catch all leaking errors and gracefully terminate. |
94 |
ok(0, $@); |
95 |
} |
96 |
} |
97 |
|
98 |
##All tests done, tear down test context |
99 |
tearDown(); |
100 |
done_testing; |
101 |
|
102 |
sub tearDown { |
103 |
t::lib::TestObjects::ObjectFactory->tearDownTestContext($testContext); |
104 |
} |