Line 0
Link Here
|
0 |
- |
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 => 5; |
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( |
54 |
{ |
55 |
source => 'Biblio', |
56 |
value => { |
57 |
title => 'Title 1', |
58 |
}, |
59 |
} |
60 |
); |
61 |
|
62 |
my $item1 = $builder->build( |
63 |
{ |
64 |
source => 'Item', |
65 |
value => { |
66 |
biblionumber => $biblio->{biblionumber}, |
67 |
homebranch => $library->{branchcode}, |
68 |
holdingbranch => $library->{branchcode}, |
69 |
}, |
70 |
} |
71 |
); |
72 |
|
73 |
my $item2 = $builder->build( |
74 |
{ |
75 |
source => 'Item', |
76 |
value => { |
77 |
biblionumber => $biblio->{biblionumber}, |
78 |
homebranch => $library->{branchcode}, |
79 |
holdingbranch => $library->{branchcode}, |
80 |
}, |
81 |
} |
82 |
); |
83 |
|
84 |
my $hold1 = Koha::Hold->new( |
85 |
{ |
86 |
biblionumber => $biblio->{biblionumber}, |
87 |
itemnumber => $item1->{itemnumber}, |
88 |
waitingdate => '2000-01-01', |
89 |
borrowernumber => $patron->{borrowernumber}, |
90 |
branchcode => $library->{branchcode}, |
91 |
} |
92 |
)->store; |
93 |
|
94 |
my $hold2 = Koha::Hold->new( |
95 |
{ |
96 |
biblionumber => $biblio->{biblionumber}, |
97 |
itemnumber => $item2->{itemnumber}, |
98 |
waitingdate => '2000-01-01', |
99 |
borrowernumber => $patron->{borrowernumber}, |
100 |
branchcode => $library->{branchcode}, |
101 |
} |
102 |
)->store; |
103 |
|
104 |
my $letter = $builder->build( |
105 |
{ |
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', |
114 |
}, |
115 |
} |
116 |
); |
117 |
|
118 |
is ( ReserveSlip(), undef, "No hold slip returned if invalid or undef borrowernumber and/or biblionumber" ); |
119 |
is ( ReserveSlip({ |
120 |
branchcode => $library->{branchcode}, |
121 |
borrowernumber => $patron->{borrowernumber}, |
122 |
biblionumber => $biblio->{biblionumber}, |
123 |
})->{code}, |
124 |
'HOLD_SLIP', "Get a hold slip from library, patron and biblio" ); |
125 |
|
126 |
is (ReserveSlip({ |
127 |
branchcode => $library->{branchcode}, |
128 |
borrowernumber => $patron->{borrowernumber}, |
129 |
biblionumber => $biblio->{biblionumber}, |
130 |
})->{content}, |
131 |
"Hold found for $patron->{firstname}: Please pick up $biblio->{title} with barcode $item1->{barcode} at $library->{branchcode}.", "Hold slip contains correctly parsed content"); |
132 |
|
133 |
is_deeply( |
134 |
ReserveSlip({ |
135 |
branchcode => $library->{branchcode}, |
136 |
borrowernumber => $patron->{borrowernumber}, |
137 |
biblionumber => $biblio->{biblionumber}, |
138 |
}), |
139 |
ReserveSlip({ |
140 |
branchcode => $library->{branchcode}, |
141 |
borrowernumber => $patron->{borrowernumber}, |
142 |
biblionumber => $biblio->{biblionumber}, |
143 |
itemnumber => $item1->{itemnumber}, |
144 |
barcode => $item1->{barcode}, |
145 |
}), |
146 |
"No item as param generate hold slip from first item in reserves"); |
147 |
|
148 |
isnt ( |
149 |
ReserveSlip({ |
150 |
branchcode => $library->{branchcode}, |
151 |
borrowernumber => $patron->{borrowernumber}, |
152 |
biblionumber => $biblio->{biblionumber}, |
153 |
})->{content}, |
154 |
ReserveSlip({ |
155 |
branchcode => $library->{branchcode}, |
156 |
borrowernumber => $patron->{borrowernumber}, |
157 |
biblionumber => $biblio->{biblionumber}, |
158 |
itemnumber => $item2->{itemnumber}, |
159 |
barcode => $item2->{barcode}, |
160 |
})->{content}, |
161 |
"Item and/or barcode as params return correct pickup item in hold slip"); |
162 |
|
163 |
$schema->storage->txn_rollback; |
164 |
|
165 |
1; |