Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/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 => 6; |
21 |
use Test::Warn; |
22 |
|
23 |
use MARC::Record; |
24 |
use DateTime::Duration; |
25 |
|
26 |
use C4::Biblio; |
27 |
use C4::Items; |
28 |
use C4::Members; |
29 |
use C4::Circulation; |
30 |
use Koha::Holds; |
31 |
use t::lib::TestBuilder; |
32 |
|
33 |
use Koha::DateUtils; |
34 |
|
35 |
|
36 |
use_ok('C4::Reserves'); |
37 |
|
38 |
my $dbh = C4::Context->dbh; |
39 |
|
40 |
# Start transaction |
41 |
$dbh->{AutoCommit} = 0; |
42 |
$dbh->{RaiseError} = 1; |
43 |
|
44 |
my $builder = t::lib::TestBuilder->new(); |
45 |
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; |
46 |
my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode }; |
47 |
|
48 |
my $borrower = $builder->build({ |
49 |
source => 'Borrower', |
50 |
value => { |
51 |
branchcode => $branchcode, |
52 |
categorycode => $categorycode, |
53 |
} |
54 |
}); |
55 |
|
56 |
my $borrower2 = $builder->build({ |
57 |
source => 'Borrower', |
58 |
value => { |
59 |
branchcode => $branchcode, |
60 |
categorycode => $categorycode, |
61 |
} |
62 |
}); |
63 |
|
64 |
my $borrowernumber = $borrower->{borrowernumber}; |
65 |
my $borrowernumber2 = $borrower2->{borrowernumber}; |
66 |
|
67 |
# Create a helper biblio |
68 |
my $biblio = MARC::Record->new(); |
69 |
my $title = 'Alone in the Dark'; |
70 |
my $author = 'Karen Rose'; |
71 |
if( C4::Context->preference('marcflavour') eq 'UNIMARC' ) { |
72 |
$biblio->append_fields( |
73 |
MARC::Field->new('600', '', '1', a => $author), |
74 |
MARC::Field->new('200', '', '', a => $title), |
75 |
); |
76 |
} |
77 |
else { |
78 |
$biblio->append_fields( |
79 |
MARC::Field->new('100', '', '', a => $author), |
80 |
MARC::Field->new('245', '', '', a => $title), |
81 |
); |
82 |
} |
83 |
my ($bibnum, $bibitemnum); |
84 |
($bibnum, $title, $bibitemnum) = AddBiblio($biblio, ''); |
85 |
|
86 |
my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branchcode, holdingbranch => $branchcode, barcode => '333' } , $bibnum); |
87 |
|
88 |
C4::Context->set_preference('AllowHoldDateInFuture', 1); |
89 |
|
90 |
AddReserve($branchcode, $borrowernumber, $bibnum, |
91 |
$bibitemnum, 1, '2015-11-01', '2015-11-20', undef, |
92 |
undef, undef, undef); |
93 |
|
94 |
is(ReservesOnSamePeriod($bibnum, undef, '2015-11-25', '2015-11-30'), undef, "Period doesn't overlaps"); |
95 |
|
96 |
ok(ReservesOnSamePeriod($bibnum, undef, '2015-11-02', '2015-11-10'), "Period overlaps"); |
97 |
|
98 |
my ($item_bibnum2, $item_bibitemnum2, $itemnumber2) = AddItem({ homebranch => $branchcode, holdingbranch => $branchcode, barcode => '444' } , $bibnum); |
99 |
is(ReservesOnSamePeriod($bibnum, undef, '2015-11-02', '2015-11-10'), undef, "Period overlaps but there is 2 items"); |
100 |
|
101 |
AddReserve($branchcode, $borrowernumber2, $bibnum, |
102 |
$bibitemnum, 1, '2016-02-01', '2016-02-10', undef, |
103 |
undef, $itemnumber, undef); |
104 |
is(ReservesOnSamePeriod($bibnum, $itemnumber, '02/12/2015', '10/12/2015'), undef, "Period on item does not overlap (with metric date format)"); |
105 |
|
106 |
my $reserve = ReservesOnSamePeriod($bibnum, $itemnumber, '2016-01-31', '2016-02-05'); |
107 |
is($reserve->[0]->{itemnumber}, $itemnumber, 'Period on item overlaps'); |
108 |
$dbh->rollback; |