From ee68bd5d17a68016383a01f72475ed1882a8fb5f Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Mon, 10 Feb 2020 18:18:45 +0000 Subject: [PATCH] Bug 24620: Unit tests Signed-off-by: Jonathan Druart --- t/db_dependent/Circulation.t | 42 +++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index d0c97ec0b0..1ca01ea6f8 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -18,7 +18,7 @@ use Modern::Perl; use utf8; -use Test::More tests => 47; +use Test::More tests => 48; use Test::MockModule; use Test::Deep qw( cmp_deeply ); @@ -40,8 +40,10 @@ use C4::Overdues qw(UpdateFine CalcFine); use Koha::DateUtils; use Koha::Database; use Koha::Items; +use Koha::Item::Transfers; use Koha::Checkouts; use Koha::Patrons; +use Koha::Holds; use Koha::CirculationRules; use Koha::Subscriptions; use Koha::Account::Lines; @@ -3813,6 +3815,44 @@ subtest 'Do not return on renewal (LOST charge)' => sub { ); }; +subtest 'Filling a hold should cancel existing transfer' => sub { + plan tests => 4; + + t::lib::Mocks::mock_preference('AutomaticItemReturn', 1); + + my $libraryA = $builder->build_object( { class => 'Koha::Libraries' } )->store; + my $libraryB = $builder->build_object( { class => 'Koha::Libraries' } )->store; + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { + categorycode => $patron_category->{categorycode}, + branchcode => $libraryA->branchcode, + } + } + )->store; + + my $item = $builder->build_sample_item({ + homebranch => $libraryB->branchcode, + }); + + my ( undef, $message ) = AddReturn( $item->barcode, $libraryA->branchcode, undef, undef ); + is( Koha::Item::Transfers->search({ itemnumber => $item->itemnumber, datearrived => undef })->count, 1, "We generate a transfer on checkin"); + AddReserve( + $libraryA->branchcode, $patron->borrowernumber, $item->biblionumber, '', + 1, undef, undef, '', + undef, $item->itemnumber, undef, undef + ); + my $reserves = Koha::Holds->search({ itemnumber => $item->itemnumber }); + is( $reserves->count, 1, "Reserve is placed"); + ( undef, $message ) = AddReturn( $item->barcode, $libraryA->branchcode, undef, undef ); + my $reserve = $reserves->next; + ModReserveAffect( $item->itemnumber, $patron->borrowernumber, 0, $reserve->reserve_id ); + $reserve->discard_changes; + ok( $reserve->found eq 'W', "Reserve is marked waiting" ); + is( Koha::Item::Transfers->search({ itemnumber => $item->itemnumber, datearrived => undef })->count, 0, "No outstanding transfers when hold is waiting"); +}; + $schema->storage->txn_rollback; C4::Context->clear_syspref_cache(); $cache->clear_from_cache('single_holidays'); -- 2.20.1