From af1f4d4c1c35efea949e20edc503bbaf477edd20 Mon Sep 17 00:00:00 2001 From: Paul Derscheid Date: Fri, 2 Jan 2026 11:16:21 +0100 Subject: [PATCH] Bug 41510: Add test for effective_bookable with missing itemtype - Add test case for the scenario where an item has no itemtype because both items.itype and biblioitems.itemtype are NULL - Note: We must set biblioitems.itemtype to NULL before creating the item because Koha::Item->store() automatically populates itype from biblioitems.itemtype when itype is not set Test plan: - Apply this patch only - Run: prove t/db_dependent/Koha/Item.t :: effective_bookable - Verify test 6 FAILS with "Can't call method 'bookable' on an undefined value" - Apply the follow-up patch - Run the test again - Verify all tests PASS Signed-off-by: David Nind --- t/db_dependent/Koha/Item.t | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t index 2485928770..bb74943bcf 100755 --- a/t/db_dependent/Koha/Item.t +++ b/t/db_dependent/Koha/Item.t @@ -3846,7 +3846,7 @@ subtest 'effective_not_for_loan_status() tests' => sub { subtest 'effective_bookable() tests' => sub { - plan tests => 5; + plan tests => 7; $schema->storage->txn_begin; @@ -3897,5 +3897,20 @@ subtest 'effective_bookable() tests' => sub { '->effective_bookable returns item specific bookable value when item bookable is defined' ); + my $biblio_no_itype = $builder->build_sample_biblio; + $biblio_no_itype->biblioitem->set({ itemtype => undef })->store; + my $item_no_itype = $builder->build_sample_item({ + biblionumber => $biblio_no_itype->biblionumber, + itype => undef, + }); + warning_like { + is( + $item_no_itype->effective_bookable, 0, + '->effective_bookable returns 0 when item has no itemtype and item bookable is undefined' + ); + } + qr/item-level_itypes set but no itemtype set for item/, + 'Warning raised for missing itemtype when item-level_itypes is set'; + $schema->storage->txn_rollback; }; -- 2.39.5