Lines 28-33
use C4::Items;
Link Here
|
28 |
use C4::Members; |
28 |
use C4::Members; |
29 |
use C4::Circulation; |
29 |
use C4::Circulation; |
30 |
use Koha::Holds; |
30 |
use Koha::Holds; |
|
|
31 |
use t::lib::Mocks; |
31 |
use t::lib::TestBuilder; |
32 |
use t::lib::TestBuilder; |
32 |
|
33 |
|
33 |
use Koha::DateUtils; |
34 |
use Koha::DateUtils; |
Lines 35-49
use Koha::DateUtils;
Link Here
|
35 |
|
36 |
|
36 |
use_ok('C4::Reserves'); |
37 |
use_ok('C4::Reserves'); |
37 |
|
38 |
|
38 |
my $dbh = C4::Context->dbh; |
|
|
39 |
|
39 |
|
40 |
# Start transaction |
40 |
# Start transaction |
|
|
41 |
my $database = Koha::Database->new(); |
42 |
my $schema = $database->schema(); |
43 |
$schema->storage->txn_begin(); |
44 |
my $dbh = C4::Context->dbh; |
45 |
$dbh->do('DELETE FROM circulation_rules'); |
46 |
|
41 |
$dbh->{AutoCommit} = 0; |
47 |
$dbh->{AutoCommit} = 0; |
42 |
$dbh->{RaiseError} = 1; |
48 |
$dbh->{RaiseError} = 1; |
43 |
|
49 |
|
44 |
my $builder = t::lib::TestBuilder->new(); |
50 |
my $builder = t::lib::TestBuilder->new; |
|
|
51 |
|
45 |
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; |
52 |
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; |
46 |
my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode }; |
53 |
my $library = $builder->build({ source => 'Branch' })->{ branchcode }; |
|
|
54 |
my $branchcode = Koha::Libraries->search->next->branchcode; |
55 |
|
56 |
my $frameworkcode = q//; |
47 |
|
57 |
|
48 |
my $borrower = $builder->build({ |
58 |
my $borrower = $builder->build({ |
49 |
source => 'Borrower', |
59 |
source => 'Borrower', |
Lines 64-108
my $borrower2 = $builder->build({
Link Here
|
64 |
my $borrowernumber = $borrower->{borrowernumber}; |
74 |
my $borrowernumber = $borrower->{borrowernumber}; |
65 |
my $borrowernumber2 = $borrower2->{borrowernumber}; |
75 |
my $borrowernumber2 = $borrower2->{borrowernumber}; |
66 |
|
76 |
|
67 |
# Create a helper biblio |
77 |
# Create a helper biblio and item |
68 |
my $biblio = MARC::Record->new(); |
78 |
my $bibnum = $builder->build_sample_biblio({frameworkcode => $frameworkcode})->biblionumber; |
69 |
my $title = 'Alone in the Dark'; |
79 |
my $item = $builder->build_sample_item({ biblionumber => $bibnum, library => $branchcode, barcode => '333' }); |
70 |
my $author = 'Karen Rose'; |
80 |
my ($item_bibnum, $bibitemnum, $itemnumber) = ($bibnum, $item->biblioitemnumber, $item->itemnumber); |
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 |
|
81 |
|
88 |
C4::Context->set_preference('AllowHoldDateInFuture', 1); |
82 |
C4::Context->set_preference('AllowHoldDateInFuture', 1); |
89 |
|
83 |
t::lib::Mocks::mock_preference('PreventReservesOnSamePeriod', 1); |
90 |
AddReserve($branchcode, $borrowernumber, $bibnum, |
84 |
|
91 |
$bibitemnum, 1, '2015-11-01', '2015-11-20', undef, |
85 |
AddReserve( |
92 |
undef, undef, undef); |
86 |
{ |
|
|
87 |
branchcode => $branchcode, |
88 |
borrowernumber => $borrowernumber, |
89 |
biblionumber => $bibnum, |
90 |
biblioitemnumber => $bibitemnum, |
91 |
priority => 1, |
92 |
reservation_date => '2015-11-01', |
93 |
expiration_date => '2015-11-20', |
94 |
} |
95 |
); |
93 |
|
96 |
|
94 |
is(ReservesOnSamePeriod($bibnum, undef, '2015-11-25', '2015-11-30'), undef, "Period doesn't overlaps"); |
97 |
is(ReservesOnSamePeriod($bibnum, undef, '2015-11-25', '2015-11-30'), undef, "Period doesn't overlaps"); |
95 |
|
98 |
|
96 |
ok(ReservesOnSamePeriod($bibnum, undef, '2015-11-02', '2015-11-10'), "Period overlaps"); |
99 |
ok(ReservesOnSamePeriod($bibnum, undef, '2015-11-02', '2015-11-10'), "Period overlaps"); |
97 |
|
100 |
|
98 |
my ($item_bibnum2, $item_bibitemnum2, $itemnumber2) = AddItem({ homebranch => $branchcode, holdingbranch => $branchcode, barcode => '444' } , $bibnum); |
101 |
my $item2 = $builder->build_sample_item({ biblionumber => $bibnum, homebranch => $branchcode, holdingbranch => $branchcode, barcode => '444' }); |
|
|
102 |
my ($item_bibnum2, $bibitemnum2, $itemnumber2) = ($bibnum, $item2->biblioitemnumber, $item2->itemnumber); |
103 |
|
99 |
is(ReservesOnSamePeriod($bibnum, undef, '2015-11-02', '2015-11-10'), undef, "Period overlaps but there is 2 items"); |
104 |
is(ReservesOnSamePeriod($bibnum, undef, '2015-11-02', '2015-11-10'), undef, "Period overlaps but there is 2 items"); |
100 |
|
105 |
|
101 |
AddReserve($branchcode, $borrowernumber2, $bibnum, |
106 |
|
102 |
$bibitemnum, 1, '2016-02-01', '2016-02-10', undef, |
107 |
AddReserve( |
103 |
undef, $itemnumber, undef); |
108 |
{ |
|
|
109 |
branchcode => $branchcode, |
110 |
borrowernumber => $borrowernumber2, |
111 |
biblionumber => $bibnum, |
112 |
biblioitemnumber => $bibitemnum, |
113 |
priority => 1, |
114 |
reservation_date => '2016-02-01', |
115 |
expiration_date => '2016-02-10', |
116 |
itemnumber => $itemnumber, |
117 |
} |
118 |
); |
119 |
|
104 |
is(ReservesOnSamePeriod($bibnum, $itemnumber, '02/12/2015', '10/12/2015'), undef, "Period on item does not overlap (with metric date format)"); |
120 |
is(ReservesOnSamePeriod($bibnum, $itemnumber, '02/12/2015', '10/12/2015'), undef, "Period on item does not overlap (with metric date format)"); |
105 |
|
121 |
|
106 |
my $reserve = ReservesOnSamePeriod($bibnum, $itemnumber, '2016-01-31', '2016-02-05'); |
122 |
my $reserve = ReservesOnSamePeriod($bibnum, $itemnumber, '2016-01-31', '2016-02-05'); |
107 |
is($reserve->[0]->{itemnumber}, $itemnumber, 'Period on item overlaps'); |
123 |
is($reserve->[0]->{itemnumber}, $itemnumber, 'Period on item overlaps'); |
|
|
124 |
|
108 |
$dbh->rollback; |
125 |
$dbh->rollback; |
109 |
- |
|
|