From 5b59c521a369c65c58741cf43072718863499d54 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 17 Feb 2021 16:11:19 +0100 Subject: [PATCH] Bug 27718: Add tests --- t/db_dependent/Koha/Holds.t | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/t/db_dependent/Koha/Holds.t b/t/db_dependent/Koha/Holds.t index 8084791fac..6cc767bc27 100755 --- a/t/db_dependent/Koha/Holds.t +++ b/t/db_dependent/Koha/Holds.t @@ -410,16 +410,18 @@ subtest 'Desks' => sub { }; subtest 'get_items_that_can_fill' => sub { - plan tests => 1; + plan tests => 2; my $biblio = $builder->build_sample_biblio; - my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); - my $item_2 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); - my $item_3 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ) + my $itype_1 = $builder->build_object({ class => 'Koha::ItemTypes' }); # For 1, 2, 3, 4 + my $itype_2 = $builder->build_object({ class => 'Koha::ItemTypes' }); + my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itype => $itype_1->itemtype } ); + my $item_2 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itype => $itype_1->itemtype } ); + my $item_3 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itype => $itype_1->itemtype } ) ; # onloan - my $item_4 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ) + my $item_4 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itype => $itype_1->itemtype } ) ; # in transfer - my $item_5 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); + my $item_5 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itype => $itype_2->itemtype } ); my $lost = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itemlost => 1 } ); my $withdrawn = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, withdrawn => 1 } ); my $notforloan = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 1 } ); @@ -479,9 +481,22 @@ subtest 'get_items_that_can_fill' => sub { } ); - my @items = $holds->get_items_that_can_fill; - is_deeply( [ map { $_->itemnumber } @items ], + my $items = $holds->get_items_that_can_fill; + is_deeply( [ map { $_->itemnumber } $items->as_list ], [ $item_2->itemnumber, $item_5->itemnumber ], 'Only item 1 and 5 are available for filling the hold' ); + + # Marking item_5 is no hold allowed + Koha::CirculationRule->new( + { + rule_name => 'holdallowed', + rule_value => 0, + itemtype => $item_5->itype + } + )->store; + $items = $holds->get_items_that_can_fill; + is_deeply( [ map { $_->itemnumber } $items->as_list ], + [ $item_2->itemnumber ], 'Only item 1 is available for filling the hold' ); + }; $schema->storage->txn_rollback; -- 2.20.1