From 1793d2a59c45b201cf50598ab897d905cec1738b Mon Sep 17 00:00:00 2001 From: Katrin Fischer Date: Thu, 8 Aug 2013 11:01:28 +0200 Subject: [PATCH] Bug 10697 - Adding more unit tests to CheckReserves Adding more unit tests for CheckReserves to cover more use cases. --- t/db_dependent/Reserves.t | 115 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 111 insertions(+), 4 deletions(-) diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index 0e0852a..089976c 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -2,7 +2,7 @@ use Modern::Perl; -use Test::More tests => 4; +use Test::More tests => 14; use MARC::Record; use C4::Branch; @@ -69,10 +69,117 @@ AddReserve($branch, $borrowernumber, $biblionumber, my ($status, $reserve, $all_reserves) = CheckReserves($itemnumber, $barcode); -is($status, "Reserved", "CheckReserves Test 1"); +is($status, "Reserved", "CheckReserves Test 1 - Reserved"); ($status, $reserve, $all_reserves) = CheckReserves($itemnumber); -is($status, "Reserved", "CheckReserves Test 2"); +is($status, "Reserved", "CheckReserves Test 2 - Reserved"); ($status, $reserve, $all_reserves) = CheckReserves(undef, $barcode); -is($status, "Reserved", "CheckReserves Test 3"); +is($status, "Reserved", "CheckReserves Test 3 - Reserved"); + + +# Adding some more unit tests for CheckReserves + +# Prepare bibliographic record and item +diag("Single item"); +my $bib2 = MARC::Record->new(); +$bib2->append_fields( + MARC::Field->new('100', ' ', ' ', a => 'Anonymous'), + MARC::Field->new('245', ' ', ' ', a => 'Some random title'), +); +my ($bibnum2, $bibitemnum2, $title2); +($bibnum2, $title2, $bibitemnum2) = AddBiblio($bib2, ''); +# Helper item for that biblio. +my ($item_bibnum2, $item_bibitemnum2, $itemnumber2) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum2); + +# Modify item; setting barcode. +ModItem({ barcode => '97532' }, $bibnum2, $itemnumber2); + + +diag("- No existing holds"); +($status, $reserve, $all_reserves) = CheckReserves($itemnumber2); +is($status, '', "No holds for this record"); + + +diag("- Item level holds"); +$checkitem = $itemnumber2; +$biblionumber = $bibnum2; +AddReserve ($branch, $borrowernumber, $biblionumber, + $constraint, $bibitems, $priority, $resdate, $expdate, $notes, + $title, $checkitem, $found); + +($status, $reserve, $all_reserves) = CheckReserves($itemnumber2); +is($status, "Reserved", "Reserved - item level hold, still on shelf"); + +# Hold is picked and set to waiting +my $reserve_id = C4::Reserves::GetReserveId({ borrowernumber => $borrowernumber, itemnumber => $itemnumber2 }); +ModReserveAffect($itemnumber2,$borrowernumber,''); + +($status, $reserve, $all_reserves) = CheckReserves($itemnumber2); +is($status, "Waiting", "Waiting - item level hold, ready for pick-up"); + +# Cancel item level hold +$reserve_id = C4::Reserves::GetReserveId({ biblionumber => $bibnum2, borrowernumber => $borrowernumber}); +CancelReserve({ reserve_id => $reserve_id }); + + +diag("- Title level holds"); +$checkitem = $itemnumber2; +$biblionumber = $bibnum2; +AddReserve ($branch, $borrowernumber, $biblionumber, + $constraint, $bibitems, $priority, $resdate, $expdate, $notes, + $title, undef, $found); + +($status, $reserve, $all_reserves) = CheckReserves($itemnumber2); +is($status,"Reserved", "Reserved - title level hold, still on shelf"); + +# Hold is pulled and set to waiting, itemnumber is set +ModReserveAffect($itemnumber2,$borrowernumber,''); + +($status, $reserve, $all_reserves) = CheckReserves($itemnumber2); +is($status,"Waiting", "Waiting - title level hold is ready for pick-up"); + +# Cancel hold +$reserve_id = C4::Reserves::GetReserveId({ biblionumber => $bibnum2, borrowernumber => $borrowernumber}); +CancelReserve({ reserve_id => $reserve_id }); + +($status, $reserve, $all_reserves) = CheckReserves($itemnumber2); +is($status, '', "Hold cancelled - no holds for this record"); + + +diag("Multiple items"); +my ($item_bibnum3, $item_bibitemnum3, $itemnumber3) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum2); +# Modify item; setting barcode. +ModItem({ barcode => '97533' }, $bibnum2, $itemnumber3); + +diag("- Item level holds"); +# Add item level hold on first item +AddReserve ($branch, $borrowernumber, $biblionumber, + $constraint, $bibitems, $priority, $resdate, $expdate, $notes, + $title, $checkitem, $found); + +# Check first item +($status, $reserve, $all_reserves) = CheckReserves($itemnumber2); +is($status, "Reserved", "Reserved - item level hold on this item"); + +# Check second item +($status, $reserve, $all_reserves) = CheckReserves($itemnumber3); +is($status, '', "No item level hold on this item"); + +# Cancel item level hold +$reserve_id = C4::Reserves::GetReserveId({ biblionumber => $bibnum2, borrowernumber => $borrowernumber}); +CancelReserve({ reserve_id => $reserve_id }); + +diag("- Title level holds"); +# Add title level hold +AddReserve ($branch, $borrowernumber, $biblionumber, + $constraint, $bibitems, $priority, $resdate, $expdate, $notes, + $title, undef, $found); + +($status, $reserve, $all_reserves) = CheckReserves($itemnumber2); +is($status, "Reserved", "Reserved - first item can fill title level hold"); + +($status, $reserve, $all_reserves) = CheckReserves($itemnumber2); +is($status, "Reserved", "Reserved - second item can also fill title level hold"); + + -- 1.7.10.4