Line 0
Link Here
|
|
|
1 |
#!/usr/bin/env 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 |
use Test::NoWarnings; |
22 |
use C4::Members; |
23 |
use C4::Reserves qw( AddReserve ReservesOnSamePeriod ); |
24 |
use C4::Circulation qw( CanBookBeIssued ); |
25 |
use Koha::DateUtils qw( dt_from_string ); |
26 |
|
27 |
use t::lib::Mocks; |
28 |
use t::lib::TestBuilder; |
29 |
|
30 |
my $schema = Koha::Database->new->schema; |
31 |
$schema->storage->txn_begin; |
32 |
|
33 |
my $builder = t::lib::TestBuilder->new(); |
34 |
|
35 |
subtest 'Tests for CanBookBeIssued with overlap reserves' => sub { |
36 |
plan tests => 7; |
37 |
|
38 |
Koha::CirculationRules->set_rules( |
39 |
{ |
40 |
branchcode => undef, |
41 |
categorycode => undef, |
42 |
itemtype => undef, |
43 |
rules => { |
44 |
reservesallowed => 25, |
45 |
holds_per_record => 1, |
46 |
} |
47 |
} |
48 |
); |
49 |
|
50 |
t::lib::Mocks::mock_preference( 'PreventCheckoutOnSameReservePeriod', 1 ); |
51 |
my $categorycode = $builder->build( { source => 'Category' } )->{categorycode}; |
52 |
my $branch = $builder->build( { source => 'Branch', value => { branchcode => 'BRC' } } ); |
53 |
my $branchcode = $branch->{branchcode}; |
54 |
|
55 |
my $patron_1 = $builder->build_object( |
56 |
{ |
57 |
class => 'Koha::Patrons', |
58 |
value => { |
59 |
branchcode => $branchcode, |
60 |
categorycode => $categorycode, |
61 |
} |
62 |
} |
63 |
); |
64 |
|
65 |
my $patron_2 = $builder->build_object( |
66 |
{ |
67 |
class => 'Koha::Patrons', |
68 |
value => { |
69 |
branchcode => $branchcode, |
70 |
categorycode => $categorycode, |
71 |
} |
72 |
} |
73 |
); |
74 |
|
75 |
my $biblio = $builder->build( { source => 'Biblio' } ); |
76 |
my $biblioitem = $builder->build( |
77 |
{ |
78 |
source => 'Biblioitem', |
79 |
value => { |
80 |
biblionumber => $biblio->{biblionumber}, |
81 |
}, |
82 |
} |
83 |
); |
84 |
my $item = $builder->build( |
85 |
{ |
86 |
source => 'Item', |
87 |
value => { |
88 |
biblionumber => $biblio->{biblionumber}, |
89 |
biblioitemnumber => $biblioitem->{biblioitemnumber}, |
90 |
withdrawn => 0, |
91 |
itemlost => 0, |
92 |
notforloan => 0, |
93 |
}, |
94 |
} |
95 |
); |
96 |
|
97 |
my $startdate = dt_from_string(); |
98 |
$startdate->add_duration( DateTime::Duration->new( days => 4 ) ); |
99 |
my $expdate = $startdate->clone(); |
100 |
$expdate->add_duration( DateTime::Duration->new( days => 10 ) ); |
101 |
|
102 |
my $reserveid = AddReserve( |
103 |
{ |
104 |
branchcode => $branchcode, |
105 |
borrowernumber => $patron_1->borrowernumber, |
106 |
biblionumber => $item->{biblionumber}, |
107 |
priority => 1, |
108 |
reservation_date => $startdate->ymd, |
109 |
expiration_date => $expdate->ymd, |
110 |
} |
111 |
); |
112 |
is( defined $reserveid, 1, "Hold has been placed" ); |
113 |
|
114 |
my $non_overlap_duedate = dt_from_string(); |
115 |
$non_overlap_duedate->add_duration( DateTime::Duration->new( days => 2 ) ); |
116 |
my ( $error, $question, $alerts ) = |
117 |
CanBookBeIssued( $patron_2, $item->{barcode}, $non_overlap_duedate, 1, 0 ); |
118 |
|
119 |
is_deeply( $error, {}, "" ); |
120 |
is_deeply( $question, {}, "" ); |
121 |
is_deeply( $alerts, {}, "" ); |
122 |
|
123 |
my $overlap_duedate = dt_from_string(); |
124 |
$overlap_duedate->add_duration( DateTime::Duration->new( days => 5 ) ); |
125 |
( $error, $question, $alerts ) = |
126 |
CanBookBeIssued( $patron_2, $item->{barcode}, $overlap_duedate, 1, 0 ); |
127 |
|
128 |
is_deeply( $error, {}, "" ); |
129 |
my $expected = { |
130 |
RESERVED => 1, |
131 |
resfirstname => $patron_1->firstname, |
132 |
ressurname => $patron_1->surname, |
133 |
rescardnumber => $patron_1->cardnumber, |
134 |
resborrowernumber => $patron_1->borrowernumber, |
135 |
resbranchcode => $patron_1->branchcode, |
136 |
resreservedate => $startdate->ymd, |
137 |
reserve_id => $reserveid, |
138 |
}; |
139 |
|
140 |
is_deeply( $question, $expected, "Need confirmation" ); |
141 |
is_deeply( $alerts, {}, "" ); |
142 |
}; |
143 |
|
144 |
$schema->storage->txn_rollback; |