From cd437faf27f32d5f1dd4d32cea75f2aef0488e96 Mon Sep 17 00:00:00 2001
From: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Date: Fri, 18 Oct 2024 11:40:45 +0100
Subject: [PATCH] Bug 35906: (QA follow-up) Unit tests for effective_bookable

---
 t/db_dependent/Koha/Item.t | 58 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 57 insertions(+), 1 deletion(-)

diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t
index 9fa642be693..22eebc36648 100755
--- a/t/db_dependent/Koha/Item.t
+++ b/t/db_dependent/Koha/Item.t
@@ -20,7 +20,7 @@
 use Modern::Perl;
 use utf8;
 
-use Test::More tests => 37;
+use Test::More tests => 38;
 use Test::Exception;
 use Test::MockModule;
 
@@ -3175,3 +3175,59 @@ subtest 'effective_not_for_loan_status() tests' => sub {
 
     $schema->storage->txn_rollback;
 };
+
+subtest 'effective_bookable() tests' => sub {
+
+    plan tests => 5;
+
+    $schema->storage->txn_begin;
+
+    my $biblio       = $builder->build_sample_biblio;
+    my $biblio_itype = Koha::ItemTypes->find( $biblio->itemtype );
+    $biblio_itype->bookable(0)->store();
+    $biblio_itype->discard_changes;
+
+    my $item_itype = $builder->build_object( { class => 'Koha::ItemTypes' } );
+    $item_itype->bookable(1)->store();
+    $item_itype->discard_changes;
+
+    my $item = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itype => $item_itype->itemtype } );
+    $item->bookable(undef)->store();
+    $item->discard_changes;
+
+    isnt( $biblio->itemtype, $item_itype->itemtype, "Biblio level itemtype and item level itemtype does not match" );
+
+    t::lib::Mocks::mock_preference( 'item-level_itypes', 0 );
+    note("item-level_itypes: 0");
+
+    is(
+        $item->effective_bookable, $biblio_itype->bookable,
+        '->effective_bookable returns biblio level itemtype bookable value when item bookable is undefined'
+    );
+
+    $item->bookable(1)->store();
+    $item->discard_changes;
+    isnt(
+        $item->effective_bookable, $biblio_itype->bookable,
+        '->effective_bookable returns item specific bookable value when item bookable is defined'
+    );
+
+    t::lib::Mocks::mock_preference( 'item-level_itypes', 1 );
+    note("item-level_itypes: 1");
+
+    $item->bookable(undef)->store();
+    $item->discard_changes;
+    is(
+        $item->effective_bookable, $item_itype->bookable,
+        '->effective_bookable returns item level itemtype bookable value when item bookable is undefined'
+    );
+
+    $item->bookable(0)->store();
+    $item->discard_changes;
+    isnt(
+        $item->effective_bookable, $item_itype->bookable,
+        '->effective_bookable returns item specific bookable value when item bookable is defined'
+    );
+
+    $schema->storage->txn_rollback;
+};
-- 
2.47.0