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 |
|
35 |
my $builder = t::lib::TestBuilder->new(); |
36 |
my $library = $builder->build( |
37 |
{ |
38 |
source => 'Branch', |
39 |
} |
40 |
); |
41 |
|
42 |
my $patron = $builder->build( |
43 |
{ |
44 |
source => 'Borrower', |
45 |
value => { |
46 |
branchcode => $library->{branchcode}, |
47 |
}, |
48 |
} |
49 |
); |
50 |
|
51 |
my $letter = Koha::Database->new()->schema()->resultset('Letter')->new( |
52 |
{ |
53 |
module => 'circulation', |
54 |
code => 'HOLD_SLIP', |
55 |
content => 'Hold found for <<borrowers.firstname>>: Please pick up <<biblio.title>> with barcode <<items.barcode>> at <<branches.branchcode>>.', |
56 |
message_transport_type => 'email', |
57 |
|
58 |
} |
59 |
)->insert; |
60 |
|
61 |
my $biblio = $builder->build( |
62 |
{ |
63 |
source => 'Biblio', |
64 |
value => { |
65 |
title => 'Title 1', |
66 |
}, |
67 |
} |
68 |
); |
69 |
my $item1 = $builder->build( |
70 |
{ |
71 |
source => 'Item', |
72 |
value => { |
73 |
biblionumber => $biblio->{biblionumber}, |
74 |
homebranch => $library->{branchcode}, |
75 |
holdingbranch => $library->{branchcode}, |
76 |
}, |
77 |
} |
78 |
); |
79 |
|
80 |
my $item2 = $builder->build( |
81 |
{ |
82 |
source => 'Item', |
83 |
value => { |
84 |
biblionumber => $biblio->{biblionumber}, |
85 |
homebranch => $library->{branchcode}, |
86 |
holdingbranch => $library->{branchcode}, |
87 |
}, |
88 |
} |
89 |
); |
90 |
|
91 |
my $hold1 = Koha::Hold->new( |
92 |
{ |
93 |
biblionumber => $biblio->{biblionumber}, |
94 |
itemnumber => $item1->{itemnumber}, |
95 |
waitingdate => '2000-01-01', |
96 |
borrowernumber => $patron->{borrowernumber}, |
97 |
branchcode => $library->{branchcode}, |
98 |
} |
99 |
)->store; |
100 |
|
101 |
my $hold2 = Koha::Hold->new( |
102 |
{ |
103 |
biblionumber => $biblio->{biblionumber}, |
104 |
itemnumber => $item2->{itemnumber}, |
105 |
waitingdate => '2000-01-01', |
106 |
borrowernumber => $patron->{borrowernumber}, |
107 |
branchcode => $library->{branchcode}, |
108 |
} |
109 |
)->store; |
110 |
|
111 |
is ( ReserveSlip(), undef, "No hold slip returned if invalid or undef borrowernumber and/or biblionumber" ); |
112 |
is ( ReserveSlip($library->{branchcode}, $patron->{borrowernumber}, $biblio->{biblionumber})->{code}, |
113 |
'HOLD_SLIP', "Get a hold slip from library, patron and biblio" ); |
114 |
|
115 |
is (ReserveSlip($library->{branchcode}, $patron->{borrowernumber}, $biblio->{biblionumber})->{content}, |
116 |
"Hold found for $patron->{firstname}: Please pick up $biblio->{title} with barcode $item1->{barcode} at $library->{branchcode}.", "Hold slip contains correctly parsed content"); |
117 |
|
118 |
is_deeply( |
119 |
ReserveSlip($library->{branchcode}, $patron->{borrowernumber}, $biblio->{biblionumber}), |
120 |
ReserveSlip($library->{branchcode}, $patron->{borrowernumber}, $biblio->{biblionumber}, $item1->{itemnumber}, $item1->{barcode}), |
121 |
"No item as param generate hold slip from first item in reserves"); |
122 |
|
123 |
isnt ( |
124 |
ReserveSlip($library->{branchcode}, $patron->{borrowernumber}, $biblio->{biblionumber})->{content}, |
125 |
ReserveSlip($library->{branchcode}, $patron->{borrowernumber}, $biblio->{biblionumber}, $item2->{itemnumber}, $item2->{barcode})->{content}, |
126 |
"Item and/or barcode as params return correct pickup item in hold slip"); |
127 |
|
128 |
$schema->storage->txn_rollback; |
129 |
|
130 |
1; |