Bug 34440: Unit test for change to Koha::Item
This adds a unit test for the new preparation_period handling introduced into the find_booking method of Koha::Item. Sponsored-by: Cuyahoga County Public Library <https://cuyahogalibrary.org/> Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de> Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
parent
fe71a9f84c
commit
33d5ab614c
2 changed files with 52 additions and 2 deletions
|
@ -586,7 +586,9 @@ sub bookings {
|
|||
|
||||
my $booking = $item->find_booking( { checkout_date => $now, due_date => $future_date } );
|
||||
|
||||
Find the first booking that would conflict with the passed checkout dates for this item.
|
||||
Find the first booking that would conflict with the passed checkout dates for this item. If a booking
|
||||
lead period is configured for the itemtype we will also take that into account here, counting bookings
|
||||
that fall in that lead period as conflicts too.
|
||||
|
||||
FIXME: This can be simplified, it was originally intended to iterate all biblio level bookings
|
||||
to catch cases where this item may be the last available to satisfy a biblio level only booking.
|
||||
|
|
|
@ -2600,7 +2600,7 @@ subtest 'bookings' => sub {
|
|||
};
|
||||
|
||||
subtest 'find_booking' => sub {
|
||||
plan tests => 6;
|
||||
plan tests => 7;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
|
@ -2707,6 +2707,54 @@ subtest 'find_booking' => sub {
|
|||
"Koha::Item->find_booking returns the current booking not a future one"
|
||||
);
|
||||
|
||||
subtest "Preparation period handling" => sub {
|
||||
plan tests => 3;
|
||||
|
||||
# Delete current booking, is the future booking returned?
|
||||
$booking2->delete();
|
||||
$found_booking = $item->find_booking(
|
||||
{
|
||||
checkout_date => dt_from_string(),
|
||||
due_date => dt_from_string()->add( days => 7 ),
|
||||
}
|
||||
);
|
||||
|
||||
is(
|
||||
$found_booking,
|
||||
undef,
|
||||
"Koha::Item->find_booking returns undefined when the current booking is deleted and the future booking is out of range and there's no lead period rule"
|
||||
);
|
||||
|
||||
# Adding lead period rule
|
||||
Koha::CirculationRules->set_rules(
|
||||
{
|
||||
branchcode => '*',
|
||||
itemtype => $item->effective_itemtype,
|
||||
rules => {
|
||||
bookings_lead_period => 3,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
$found_booking = $item->find_booking(
|
||||
{
|
||||
checkout_date => dt_from_string(),
|
||||
due_date => dt_from_string()->add( days => 7 ),
|
||||
}
|
||||
);
|
||||
|
||||
is(
|
||||
ref($found_booking),
|
||||
'Koha::Booking',
|
||||
"Koha::Item->find_booking returns a Koha::Booking if one exists that would clash with the passed dates including lead period"
|
||||
);
|
||||
is(
|
||||
$found_booking->booking_id, $booking3->booking_id,
|
||||
"Koha::Item->find_booking returns the future booking when lead period is included"
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue