From 33bd28fb856d496370f7132171aa479c77b28af8 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 28 Jun 2019 12:36:16 +0000 Subject: [PATCH] Bug 14549: Unit tests To test: 1 - Apply just this patch 2 - prove -v t/db_dependent/Reserves.t 3 - Failure 4 - Apply second patch 5 - prove -v t/db_dependent/Reserves.t 6 - Success! Signed-off-by: Chris Cormack Signed-off-by: Tomas Cohen Arazi Signed-off-by: Martin Renvoize --- t/db_dependent/Reserves.t | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index cdc5f06633..33aa3d9f76 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 61; +use Test::More tests => 62; use Test::MockModule; use Test::Warn; @@ -807,6 +807,34 @@ subtest 'reserves.item_level_hold' => sub { }; +subtest 'MoveReserve additional test' => sub { + + plan tests => 4; + + # Create the items and patrons we need + my $biblio = $builder->build_sample_biblio(); + my $itype = $builder->build_object({ class => "Koha::ItemTypes", value => { notforloan => 0 } }); + my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber,notforloan => 0, itype => $itype->itemtype }); + my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, notforloan => 0, itype => $itype->itemtype }); + my $patron_1 = $builder->build_object({ class => "Koha::Patrons" }); + my $patron_2 = $builder->build_object({ class => "Koha::Patrons" }); + + # Place a hold on the title for both patrons + my $reserve_1 = AddReserve( $item_1->homebranch, $patron_1->borrowernumber, $biblio->biblionumber, undef, 1 ); + my $reserve_2 = AddReserve( $item_2->homebranch, $patron_2->borrowernumber, $biblio->biblionumber, undef, 1 ); + is($patron_1->holds->next()->reserve_id, $reserve_1, "The 1st patron has a hold"); + is($patron_2->holds->next()->reserve_id, $reserve_2, "The 2nd patron has a hold"); + + # Fake the holds queue + $dbh->do(q{INSERT INTO hold_fill_targets VALUES (?, ?, ?, ?, ?)},undef,($patron_1->borrowernumber,$biblio->biblionumber,$item_1->itemnumber,$item_1->homebranch,0)); + + # The 2nd hold should be filed even if the item is preselected for the first hold + MoveReserve($item_1->itemnumber,$patron_2->borrowernumber); + is($patron_2->holds->count, 0, "The 2nd patrons no longer has a hold"); + is($patron_2->old_holds->next()->reserve_id, $reserve_2, "The 2nd patrons hold was filled and moved to old holds"); + +}; + sub count_hold_print_messages { my $message_count = $dbh->selectall_arrayref(q{ SELECT COUNT(*)