From caa1cd9a7084659b97ef2f3efd7940088651543d Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 20 Jan 2014 16:40:50 +0100 Subject: [PATCH] Bug 10827: Regression tests The unit tests in the file db_dependent/Reserves/priorities.t describe the issue. To reproduce using the interface: - Create 3 patrons A, B and C - Check an item out to A - Place a hold on this item for B and C - Check the item in - Confirm the hold - Verify the hold list: The item is waiting for B and C has a priority 2 - Delete the hold for B - Now you can see the item is not waiting for C. He has not been notified neither. If you apply all patches from this bug, at the next ste, the item is marked as waiting for C and C has been notified when the hold for B has been deleted. /!\Important note: This patch only manages item-level holds! The commented UT is for biblio-level holds. Signed-off-by: Kyle M Hall --- t/db_dependent/Reserves/priorities.t | 169 ++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 t/db_dependent/Reserves/priorities.t diff --git a/t/db_dependent/Reserves/priorities.t b/t/db_dependent/Reserves/priorities.t new file mode 100644 index 0000000..c02bfee --- /dev/null +++ b/t/db_dependent/Reserves/priorities.t @@ -0,0 +1,169 @@ +#!/usr/bin/perl + +use Modern::Perl; + +use Data::Dumper; +use Test::More; + +use MARC::Record; + +use C4::Biblio; +use C4::Circulation; +use C4::Context; +use C4::Items; +use C4::Members; +use C4::Reserves; + +my $dbh = C4::Context->dbh; + +# Start transaction +$dbh->{AutoCommit} = 0; +$dbh->{RaiseError} = 1; + +C4::Context->_new_userenv('xxx'); +C4::Context::set_userenv(0,0,0,'firstname','surname', 'CPL', 'CPL', '', '', ''); + +my $record = MARC::Record->new; +my ( $biblionumber ) = AddBiblio( $record, '' ); +my ( $barcode1, $barcode2 ) = ( 'UT_prio_barcode_1', 'UT_prio_barcode_2' ); +my ( undef, undef, $itemnumber1) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL', barcode => $barcode1 }, $biblionumber); +my ( undef, undef, $itemnumber2) = AddItem({ homebranch => 'MPL', holdingbranch => 'MPL', barcode => $barcode2 }, $biblionumber); + +my $borrowernumber1 = AddMember ( + firstname => 'ill borrow', + surname => 'foo', + categorycode => 'PT', + branchcode => 'CPL', +); +my $borrower1 = GetMember( borrowernumber => $borrowernumber1 ); +my $borrowernumber2 = AddMember ( + firstname => 'ill place the first hold', + surname => 'foo', + categorycode => 'PT', + branchcode => 'CPL', +); +my $borrower2 = GetMember( borrowernumber => $borrowernumber2 ); +my $borrowernumber3 = AddMember ( + firstname => 'ill place the second hold', + surname => 'foo', + categorycode => 'PT', + branchcode => 'CPL', +); +my $borrower3 = GetMember( borrowernumber => $borrowernumber3 ); + + +my ( $reserve2, $reserve3 ); +AddIssue( $borrower1, $barcode1 ); +AddReserve( 'CPL', $borrowernumber2, $biblionumber, 'a', undef, 1, undef, undef, undef, undef, $itemnumber1 ); +AddReserve( 'CPL', $borrowernumber3, $biblionumber, 'a', undef, 2, undef, undef, undef, undef, $itemnumber1 ); + +( $reserve2 ) = GetReservesFromBorrowernumber( $borrowernumber2 ); +AddReturn( $barcode1 ); +ModReserveAffect( $itemnumber1, $borrowernumber2 ); + +( $reserve2 ) = GetReservesFromBorrowernumber( $borrowernumber2 ); +is( $reserve2->{borrowernumber}, $borrowernumber2 ); +is( $reserve2->{priority}, 0 ); +is( $reserve2->{itemnumber}, $itemnumber1 ); +is( $reserve2->{found}, 'W' ); + +( $reserve3 ) = GetReservesFromBorrowernumber( $borrowernumber3 ); +is( $reserve3->{borrowernumber}, $borrowernumber3 ); +is( $reserve3->{priority}, 2 ); +is( $reserve3->{itemnumber}, $itemnumber1 ); +is( $reserve3->{found}, undef ); + +CancelReserve({ reserve_id => $reserve2->{reserve_id} }); + +( $reserve2 ) = GetReservesFromBorrowernumber( $borrowernumber2 ); +is( $reserve2, undef ); + +( $reserve3 ) = GetReservesFromBorrowernumber( $borrowernumber3 ); +is( $reserve3->{borrowernumber}, $borrowernumber3 ); +is( $reserve3->{priority}, 0 ); +is( $reserve3->{itemnumber}, $itemnumber1 ); +is( $reserve3->{found}, 'W' ); + +CancelReserve({ reserve_id => $reserve3->{reserve_id} }); + +( $reserve3 ) = GetReservesFromBorrowernumber( $borrowernumber3 ); +is( $reserve3, undef ); + + + +AddIssue( $borrower1, $barcode1 ); +AddReserve( 'CPL', $borrowernumber2, $biblionumber, 'a', undef, 1); +AddReserve( 'CPL', $borrowernumber3, $biblionumber, 'a', undef, 2 ); +C4::Context->set_preference('ConfirmFutureHolds', 2); +my ( undef, $message ) = AddReturn( $barcode1 ); +ModReserveAffect( $itemnumber1, $borrowernumber2 ); + +( $reserve2 ) = GetReservesFromBorrowernumber( $borrowernumber2 ); +is( $reserve2->{borrowernumber}, $borrowernumber2 ); +is( $reserve2->{priority}, 0 ); +is( $reserve2->{itemnumber}, $itemnumber1 ); +is( $reserve2->{found}, 'W' ); + +( $reserve3 ) = GetReservesFromBorrowernumber( $borrowernumber3 ); +is( $reserve3->{borrowernumber}, $borrowernumber3 ); +is( $reserve3->{priority}, 2 ); +is( $reserve3->{itemnumber}, undef ); +is( $reserve3->{found}, undef ); + +CancelReserve({ reserve_id => $reserve2->{reserve_id} }); + +( $reserve2 ) = GetReservesFromBorrowernumber( $borrowernumber2 ); +is( $reserve2, undef ); + +# FIXME +#( $reserve3 ) = GetReservesFromBorrowernumber( $borrowernumber3 ); +#is( $reserve3->{borrowernumber}, $borrowernumber3 ); +#is( $reserve3->{priority}, 0 ); +#is( $reserve3->{itemnumber}, $itemnumber1 ); +#is( $reserve3->{found}, 'W' ); + +CancelReserve({ reserve_id => $reserve3->{reserve_id} }); + +( $reserve3 ) = GetReservesFromBorrowernumber( $borrowernumber3 ); +is( $reserve3, undef ); + + + +AddIssue( $borrower1, $barcode1 ); +AddReserve( 'MPL', $borrowernumber2, $biblionumber, 'a', undef, 1, undef, undef, undef, undef, $itemnumber2 ); +AddReserve( 'MPL', $borrowernumber3, $biblionumber, 'a', undef, 2, undef, undef, undef, undef, $itemnumber2 ); + +( $reserve2 ) = GetReservesFromBorrowernumber( $borrowernumber2 ); +AddReturn( $barcode1 ); +ModReserveAffect( $itemnumber2, $borrowernumber2, 1 ); + +( $reserve2 ) = GetReservesFromBorrowernumber( $borrowernumber2 ); +is( $reserve2->{borrowernumber}, $borrowernumber2 ); +is( $reserve2->{priority}, 0 ); +is( $reserve2->{itemnumber}, $itemnumber2 ); +is( $reserve2->{found}, 'T' ); + +( $reserve3 ) = GetReservesFromBorrowernumber( $borrowernumber3 ); +is( $reserve3->{borrowernumber}, $borrowernumber3 ); +is( $reserve3->{priority}, 2 ); +is( $reserve3->{itemnumber}, $itemnumber2 ); +is( $reserve3->{found}, undef ); + +CancelReserve({ reserve_id => $reserve2->{reserve_id} }); + +( $reserve2 ) = GetReservesFromBorrowernumber( $borrowernumber2 ); +is( $reserve2, undef ); + +( $reserve3 ) = GetReservesFromBorrowernumber( $borrowernumber3 ); +is( $reserve3->{borrowernumber}, $borrowernumber3 ); +is( $reserve3->{priority}, 0 ); +is( $reserve3->{itemnumber}, $itemnumber2 ); +is( $reserve3->{found}, 'T' ); + +CancelReserve({ reserve_id => $reserve3->{reserve_id} }); + +( $reserve3 ) = GetReservesFromBorrowernumber( $borrowernumber3 ); +is( $reserve3, undef ); + + +done_testing; -- 1.7.10.4