614c51308e1f06696b1043aeb40cd36ae08d71bc
[koha.git] / t / db_dependent / Circulation / NoIssuesChargeGuarantees.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use Test::More tests => 2;
21
22 use t::lib::TestBuilder;
23
24 use C4::Accounts qw( manualinvoice );
25 use C4::Circulation qw( CanBookBeIssued );
26
27 my $schema = Koha::Database->new->schema;
28 $schema->storage->txn_begin;
29
30 my $builder = t::lib::TestBuilder->new();
31
32 my $item = $builder->build(
33     {
34         source => 'Item',
35         value  => {
36             notforloan => 0,
37             withdrawn  => 0
38         }
39     }
40 );
41
42 my $patron = $builder->build(
43     {
44         source => 'Borrower',
45     }
46 );
47 my $guarantee = $builder->build(
48     {
49         source => 'Borrower',
50         value  => {
51             guarantorid => $patron->{borrowernumber},
52         }
53     }
54 );
55
56 C4::Context->set_preference( 'NoIssuesChargeGuarantees', '5.00' );
57
58 my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->{barcode} );
59 is( $issuingimpossible->{DEBT_GUARANTEES}, undef, "Patron can check out item" );
60
61 manualinvoice( $guarantee->{borrowernumber}, undef, undef, 'L', 10.00 );
62 ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->{barcode} );
63 is( $issuingimpossible->{DEBT_GUARANTEES}, '10.00', "Patron cannot check out item due to debt for guarantee" );
64
65 $schema->storage->txn_rollback;
66
67 1;