From ee50e8678400696d69f87e8117487efb29256e3b Mon Sep 17 00:00:00 2001 From: Agustin Moyano Date: Wed, 19 Aug 2020 15:50:22 -0300 Subject: [PATCH] Bug 22789: Add tests Signed-off-by: Lisette Scheer Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart --- t/db_dependent/Holds.t | 77 +++++++++++++++++++++++++++++++++++++++++- t/lib/TestBuilder.pm | 3 ++ 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Holds.t b/t/db_dependent/Holds.t index 37da7b05f7..25793192e3 100755 --- a/t/db_dependent/Holds.t +++ b/t/db_dependent/Holds.t @@ -7,19 +7,21 @@ use t::lib::TestBuilder; use C4::Context; -use Test::More tests => 66; +use Test::More tests => 67; use MARC::Record; use C4::Biblio; use C4::Calendar; use C4::Items; use C4::Reserves; +use C4::Circulation; use Koha::Biblios; use Koha::CirculationRules; use Koha::Database; use Koha::DateUtils qw( dt_from_string output_pref ); use Koha::Holds; +use Koha::Checkout; use Koha::Item::Transfer::Limits; use Koha::Items; use Koha::Libraries; @@ -1251,3 +1253,76 @@ subtest 'CanItemBeReserved / pickup_not_in_hold_group' => sub { $schema->storage->txn_rollback; }; + +subtest 'non priority holds' => sub { + + plan tests => 4; + + $schema->storage->txn_begin; + + # Cleanup database + Koha::Holds->search->delete; + $dbh->do('DELETE FROM issues'); + Koha::CirculationRules->set_rules( + { + branchcode => undef, + categorycode => undef, + itemtype => undef, + rules => { + renewalsallowed => 5, + reservesallowed => 5, + } + } + ); + + my $item = $builder->build_sample_item; + + my $patron1 = $builder->build_object( + { + class => 'Koha::Patrons', + value => { branchcode => $item->homebranch } + } + ); + my $patron2 = $builder->build_object( + { + class => 'Koha::Patrons', + value => { branchcode => $item->homebranch } + } + ); + + Koha::Checkout->new( + { + borrowernumber => $patron1->borrowernumber, + itemnumber => $item->itemnumber, + branchcode => $item->homebranch + } + )->store; + + my $hid = AddReserve( + { + branchcode => $item->homebranch, + borrowernumber => $patron2->borrowernumber, + biblionumber => $item->biblionumber, + priority => 1, + itemnumber => $item->itemnumber, + } + ); + + my ( $ok, $err ) = + CanBookBeRenewed( $patron1->borrowernumber, $item->itemnumber ); + + ok( !$ok, 'Cannot renew' ); + is( $err, 'on_reserve', 'Item is on hold' ); + + my $hold = Koha::Holds->find($hid); + $hold->non_priority(1)->store; + + ( $ok, $err ) = + CanBookBeRenewed( $patron1->borrowernumber, $item->itemnumber ); + + ok( $ok, 'Can renew' ); + is( $err, undef, 'Item is on non priority hold' ); + + $schema->storage->txn_rollback; + +}; diff --git a/t/lib/TestBuilder.pm b/t/lib/TestBuilder.pm index 45646206ba..065af37563 100644 --- a/t/lib/TestBuilder.pm +++ b/t/lib/TestBuilder.pm @@ -563,6 +563,9 @@ sub _gen_default_values { Branch => { pickup_location => 0, }, + Reserve => { + non_priority => 0, + }, Itemtype => { rentalcharge => 0, rentalcharge_daily => 0, -- 2.39.5