From 099db8419fe4076101086b41052a58a7d80c3812 Mon Sep 17 00:00:00 2001 From: Thibaud Guillot Date: Fri, 23 Feb 2024 10:00:01 +0100 Subject: [PATCH] Bug 35906: Add unit test Signed-off-by: Esther Signed-off-by: Martin Renvoize --- t/db_dependent/Koha/Items.t | 19 ++++++++++++++++++- t/lib/TestBuilder.pm | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Items.t b/t/db_dependent/Koha/Items.t index 3a0ffd11cc0..31ba253f1e7 100755 --- a/t/db_dependent/Koha/Items.t +++ b/t/db_dependent/Koha/Items.t @@ -2078,7 +2078,7 @@ subtest 'filter_by_for_hold' => sub { }; subtest 'filter_by_bookable' => sub { - plan tests => 2; + plan tests => 3; $schema->storage->txn_begin; @@ -2097,5 +2097,22 @@ subtest 'filter_by_bookable' => sub { "the correct item is returned from filter_by_bookable" ); + # unset level booking on item (for itemtype) + t::lib::Mocks::mock_preference( 'item-level_booking', 0 ); + + # test with itemtype directly bookable + my $item_type = $builder->build_object( { class => 'Koha::ItemTypes', value => { bookable => 1 } } ); + my $biblio2 = $builder->build_sample_biblio( { itemtype => $item_type->itemtype } ); + + # bookable items + my $bookable_item3 = $builder->build_sample_item( + { biblionumber => $biblio2->biblionumber, itype => $item_type->itemtype, bookable => 1 } ); + my $bookable_item4 = $builder->build_sample_item( + { biblionumber => $biblio2->biblionumber, itype => $item_type->itemtype, bookable => 0 } ); + + # items are bookable even if bookable => 0 on item (due to itemtype bookable => 1) + is( $biblio2->items->filter_by_bookable->count, 2, "filter_by_bookable returns the correct number of items" ); + $schema->storage->txn_rollback; + }; diff --git a/t/lib/TestBuilder.pm b/t/lib/TestBuilder.pm index 57506b11d78..6a4587fe824 100644 --- a/t/lib/TestBuilder.pm +++ b/t/lib/TestBuilder.pm @@ -638,6 +638,7 @@ sub _gen_default_values { defaultreplacecost => 0, processfee => 0, notforloan => 0, + bookable => 0, }, Aqbookseller => { tax_rate => 0, -- 2.45.2