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 <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
(cherry picked from commit 26ffc16c38)
Signed-off-by: Jacob O'Mara <Jacob.omara@openfifth.co.uk>
This commit is contained in:
Paul Derscheid 2026-01-02 11:16:21 +01:00 committed by Jacob O'Mara
parent 7f16087f60
commit 0a84ef98e7
No known key found for this signature in database
1 changed files with 16 additions and 1 deletions

View File

@ -3869,7 +3869,7 @@ subtest 'effective_not_for_loan_status() tests' => sub {
subtest 'effective_bookable() tests' => sub {
plan tests => 5;
plan tests => 7;
$schema->storage->txn_begin;
@ -3920,5 +3920,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;
};