From 92398f1eeb9ea84d2799a01d520c35c5444fa4ed Mon Sep 17 00:00:00 2001
From: Janusz Kaczmarek <januszop@gmail.com>
Date: Fri, 4 Oct 2024 19:18:16 +0000
Subject: [PATCH] Bug 38100: Unit tests

Signed-off-by: Roman Dolny <roman.dolny@jezuici.pl>
---
 t/db_dependent/XSLT.t | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/t/db_dependent/XSLT.t b/t/db_dependent/XSLT.t
index 5f79b35b13..4f7ef3c84b 100755
--- a/t/db_dependent/XSLT.t
+++ b/t/db_dependent/XSLT.t
@@ -82,12 +82,13 @@ subtest 'Tests moved from t' => sub {
 };
 
 subtest 'buildKohaItemsNamespace status tests' => sub {
-    plan tests => 18;
+    plan tests => 20;
     $schema->storage->txn_begin;
 
     t::lib::Mocks::mock_preference('Reference_NFL_Statuses', '1|2');
     t::lib::Mocks::mock_preference( 'OPACResultsLibrary', 'holdingbranch' );
     t::lib::Mocks::mock_preference( 'OPACResultsMaxItems', '2' );
+    t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', '0' );
 
     my $itype = $builder->build_object({ class => 'Koha::ItemTypes' });
     my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' });
@@ -152,6 +153,17 @@ subtest 'buildKohaItemsNamespace status tests' => sub {
     $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
     like($xml,qr{<substatus>Damaged</substatus>},"Damaged status takes precedence over Lost");
 
+    my $item2 = $builder->build_sample_item( { itype => $itype->itemtype } );
+    $item2->holdingbranch( $holdinglibrary->branchcode )->store;
+    $item2->biblioitem->itemtype( $itemtype->itemtype )->store;
+    $item2->damaged(1)->store;
+
+    $xml = C4::XSLT::buildKohaItemsNamespace( $item2->biblionumber, [] );
+    like( $xml, qr{<status>other</status>}, "Damaged status with AllowHoldsOnDamagedItems = 0 results in 'other'" );
+    t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', '1' );
+    $xml = C4::XSLT::buildKohaItemsNamespace( $item2->biblionumber, [] );
+    like( $xml, qr{<status>available</status>}, "Damaged status with AllowHoldsOnDamagedItems results in 'available'" );
+
     $builder->build({ source => "Branchtransfer", value => {
         itemnumber  => $item->itemnumber,
         datearrived => undef,
-- 
2.39.5