Bug 24612: Fix existing ReserveSlip tests
[koha.git] / t / db_dependent / Reserves / ReserveSlip.t
blobcd7a1936b4b4c54af96671a6aa6f8c586675a43f
1 #!/usr/bin/perl
3 # Copyright 2016 Oslo Public Library
5 # This file is part of Koha.
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.
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.
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>.
20 use Modern::Perl;
22 use Test::More tests => 3;
23 use t::lib::TestBuilder;
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;
32 my $dbh = C4::Context->dbh;
33 $dbh->do(q|DELETE FROM letter|);
34 $dbh->do(q|DELETE FROM reserves|);
36 my $builder = t::lib::TestBuilder->new();
37 my $library = $builder->build(
39 source => 'Branch',
43 my $patron = $builder->build(
45 source => 'Borrower',
46 value => {
47 branchcode => $library->{branchcode},
53 my $biblio = $builder->build(
55 source => 'Biblio',
56 value => {
57 title => 'Title 1',
62 my $item1 = $builder->build(
64 source => 'Item',
65 value => {
66 biblionumber => $biblio->{biblionumber},
67 homebranch => $library->{branchcode},
68 holdingbranch => $library->{branchcode},
73 my $item2 = $builder->build(
75 source => 'Item',
76 value => {
77 biblionumber => $biblio->{biblionumber},
78 homebranch => $library->{branchcode},
79 holdingbranch => $library->{branchcode},
84 my $hold1 = Koha::Hold->new(
86 biblionumber => $biblio->{biblionumber},
87 itemnumber => $item1->{itemnumber},
88 waitingdate => '2000-01-01',
89 borrowernumber => $patron->{borrowernumber},
90 branchcode => $library->{branchcode},
92 )->store;
94 my $hold2 = Koha::Hold->new(
96 biblionumber => $biblio->{biblionumber},
97 itemnumber => $item2->{itemnumber},
98 waitingdate => '2000-01-01',
99 borrowernumber => $patron->{borrowernumber},
100 branchcode => $library->{branchcode},
102 )->store;
104 my $letter = $builder->build(
106 source => 'Letter',
107 value => {
108 module => 'circulation',
109 code => 'HOLD_SLIP',
110 lang => 'default',
111 branchcode => $library->{branchcode},
112 content => 'Hold found for <<borrowers.firstname>>: Please pick up <<biblio.title>> with barcode <<items.barcode>> at <<branches.branchcode>>.',
113 message_transport_type => 'email',
118 is ( ReserveSlip(), undef, "No hold slip returned if invalid or undef borrowernumber and/or biblionumber" );
119 is ( ReserveSlip({
120 branchcode => $library->{branchcode},
121 reserve_id => $hold1->reserve_id,
122 })->{code},
123 'HOLD_SLIP', "Get a hold slip from library, patron and biblio" );
125 is (ReserveSlip({
126 branchcode => $library->{branchcode},
127 reserve_id => $hold1->reserve_id,
128 })->{content},
129 "Hold found for $patron->{firstname}: Please pick up $biblio->{title} with barcode $item1->{barcode} at $library->{branchcode}.", "Hold slip contains correctly parsed content");
131 $schema->storage->txn_rollback;