From 4bb4dfd7808f158343b547e44615e656ded0f910 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 --- 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 a7e1fc72c1..8dc564023e 100755 --- a/t/db_dependent/Koha/Items.t +++ b/t/db_dependent/Koha/Items.t @@ -2002,7 +2002,7 @@ subtest 'filter_by_for_hold' => sub { }; subtest 'filter_by_bookable' => sub { - plan tests => 2; + plan tests => 3; $schema->storage->txn_begin; @@ -2021,5 +2021,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 91fb518494..b4b9a1f780 100644 --- a/t/lib/TestBuilder.pm +++ b/t/lib/TestBuilder.pm @@ -627,6 +627,7 @@ sub _gen_default_values { defaultreplacecost => 0, processfee => 0, notforloan => 0, + bookable => 0, }, Aqbookseller => { tax_rate => 0, -- 2.30.2