Bug 27196: Don't explode if item that is waiting if checked in by SIP
[koha.git] / t / db_dependent / Reserves / ReserveSlip.t
1 #!/usr/bin/perl
2
3 # Copyright 2016 Oslo Public Library
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
22 use Test::More tests => 3;
23 use t::lib::TestBuilder;
24
25 use C4::Reserves qw( ReserveSlip );
26 use C4::Context;
27 use Koha::Database;
28 use Koha::Holds;
29 my $schema = Koha::Database->new->schema;
30 $schema->storage->txn_begin;
31
32 my $dbh = C4::Context->dbh;
33 $dbh->do(q|DELETE FROM letter|);
34 $dbh->do(q|DELETE FROM reserves|);
35
36 my $builder = t::lib::TestBuilder->new();
37 my $library = $builder->build(
38     {
39         source => 'Branch',
40     }
41 );
42
43 my $patron = $builder->build(
44     {
45         source => 'Borrower',
46         value  => {
47             branchcode => $library->{branchcode},
48         },
49     }
50 );
51
52
53 my $biblio = $builder->build_sample_biblio;
54 my $item1 = $builder->build_sample_item(
55     {
56         biblionumber => $biblio->biblionumber,
57         library      => $library->{branchcode},
58     }
59 );
60 my $item2 = $builder->build_sample_item(
61     {
62         biblionumber => $biblio->biblionumber,
63         library      => $library->{branchcode},
64     }
65 );
66
67 my $hold1 = Koha::Hold->new(
68     {
69         biblionumber   => $biblio->biblionumber,
70         itemnumber     => $item1->itemnumber,
71         waitingdate    => '2000-01-01',
72         borrowernumber => $patron->{borrowernumber},
73         branchcode     => $library->{branchcode},
74     }
75 )->store;
76
77 my $hold2 = Koha::Hold->new(
78     {
79         biblionumber   => $biblio->biblionumber,
80         itemnumber     => $item2->itemnumber,
81         waitingdate    => '2000-01-01',
82         borrowernumber => $patron->{borrowernumber},
83         branchcode     => $library->{branchcode},
84     }
85 )->store;
86
87 my $letter = $builder->build(
88     {
89         source => 'Letter',
90         value  => {
91             module => 'circulation',
92             code   => 'HOLD_SLIP',
93             lang   => 'default',
94             branchcode => $library->{branchcode},
95             content => 'Hold found for <<borrowers.firstname>>: Please pick up <<biblio.title>> with barcode <<items.barcode>> at <<branches.branchcode>>.',
96             message_transport_type => 'email',
97         },
98     }
99 );
100
101 is ( ReserveSlip(), undef, "No hold slip returned if invalid or undef borrowernumber and/or biblionumber" );
102 is ( ReserveSlip({
103         branchcode     => $library->{branchcode},
104         reserve_id     => $hold1->reserve_id,
105     })->{code},
106     'HOLD_SLIP', "Get a hold slip from library, patron and biblio" );
107
108 is (ReserveSlip({
109         branchcode     => $library->{branchcode},
110         reserve_id     => $hold1->reserve_id,
111     })->{content},
112     sprintf( "Hold found for %s: Please pick up %s with barcode %s at %s.", $patron->{firstname}, $biblio->title, $item1->barcode, $library->{branchcode}),"Hold slip contains correctly parsed content");
113
114 $schema->storage->txn_rollback;
115
116 1;