From 0d52731064cf3f019d6d41892c42f96edda7bd4c Mon Sep 17 00:00:00 2001 From: Agustin Moyano Date: Wed, 28 Oct 2020 10:48:09 -0300 Subject: [PATCH] Bug 24359: Add test Signed-off-by: Martin Renvoize --- t/db_dependent/HoldsQueue.t | 69 ++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/HoldsQueue.t b/t/db_dependent/HoldsQueue.t index 06047c647f..04ef9fd73d 100755 --- a/t/db_dependent/HoldsQueue.t +++ b/t/db_dependent/HoldsQueue.t @@ -8,12 +8,13 @@ use Modern::Perl; -use Test::More tests => 55; +use Test::More tests => 56; use Data::Dumper; use C4::Calendar; use C4::Context; use C4::Members; +use C4::Circulation; use Koha::Database; use Koha::DateUtils; use Koha::Items; @@ -1523,3 +1524,69 @@ sub dump_records { my ($tablename) = @_; return $dbh->selectall_arrayref("SELECT * from $tablename where borrowernumber = ?", { Slice => {} }, $borrowernumber); } + +subtest 'Remove holds on check-in match' => sub { + plan tests => 2; + + $schema->storage->txn_begin; + + $dbh->do('DELETE FROM tmp_holdsqueue'); + $dbh->do('DELETE FROM hold_fill_targets'); + + my $lib = $builder->build_object( { class => 'Koha::Libraries' } ); + + my $patron1 = $builder->build_object( + { + class => 'Koha::Patrons', + value => { branchcode => $lib->branchcode } + } + ); + my $patron2 = $builder->build_object( + { + class => 'Koha::Patrons', + value => { branchcode => $lib->branchcode } + } + ); + + my $item = $builder->build_sample_item( + { homebranch => $lib->branchcode, holdingbranch => $lib->branchcode } ); + + t::lib::Mocks::mock_userenv( { branchcode => $lib->branchcode } ); + + AddIssue( $patron1->unblessed, $item->barcode, dt_from_string ); + + my $hold_id = AddReserve( + { + branchcode => $item->homebranch, + borrowernumber => $patron2->borrowernumber, + biblionumber => $item->biblionumber, + itemnumber => undef, + priority => 1 + } + ); + + my $hold = Koha::Holds->find($hold_id); + + AddReturn( $item->barcode, $item->homebranch ); + + C4::HoldsQueue::CreateQueue(); + + my $sth = $dbh->prepare("SELECT count(*) FROM tmp_holdsqueue"); + $sth->execute(); + my ($count_1) = $sth->fetchrow_array; + + is( $count_1, 1, "Holds queue has one element" ); + + AddReturn( $item->barcode, $item->homebranch, undef, dt_from_string ); + + ModReserveAffect( $item->itemnumber, $hold->borrowernumber, 0, + $hold->reserve_id ); + + $sth->execute(); + my ($count_2) = $sth->fetchrow_array; + + is( $count_2, 0, + "Holds queue has no elements, even when queue was not rebuilt" ); + + $schema->storage->txn_rollback; +}; -- 2.20.1