From c0d61a340262674f45812e835391d8699ce6f005 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Mon, 17 Apr 2023 17:08:35 +0000 Subject: [PATCH] Bug 32702: Unit tests Signed-off-by: Andrew Fuerste Henry --- t/db_dependent/Holds.t | 50 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Holds.t b/t/db_dependent/Holds.t index 4c78b4c480b..57f32e51f19 100755 --- a/t/db_dependent/Holds.t +++ b/t/db_dependent/Holds.t @@ -418,7 +418,7 @@ is( ); subtest 'CanItemBeReserved' => sub { - plan tests => 2; + plan tests => 3; my $itemtype_can = $builder->build({source => "Itemtype"})->{itemtype}; my $itemtype_cant = $builder->build({source => "Itemtype"})->{itemtype}; @@ -627,6 +627,54 @@ subtest 'CanItemBeReserved' => sub { "This patron has already placed reservesallowed holds, tooManyReserves should be raised" ); }; + + subtest 'item status tests' => sub { + plan tests => 6; + + t::lib::Mocks::mock_preference( 'item-level_itypes', 1 ); + my $item = $builder->build_sample_item(); + my $biblioitem = $item->biblio->biblioitem; + $biblioitem->itemtype(undef)->store(); + $item->update( { itype => undef } ); + is( + CanItemBeReserved( $patrons[0], $item )->{status}, 'missing_itemtype', + "Item with no itemtype cannot be reserved" + ); + + my $itemtype = $builder->build_object( { class => 'Koha::ItemTypes', value => { notforloan => 1 } } ); + $item->itype( $itemtype->id )->store(); + + is( + CanItemBeReserved( $patrons[0], $item )->{status}, 'notforloan', + "Item with no notforloan itemtype cannot be reserved" + ); + + $itemtype->notforloan(0)->store(); + $item->notforloan(1)->store(); + + is( + CanItemBeReserved( $patrons[0], $item )->{status}, 'notforloan', + "Item with no notforloan status cannot be reserved" + ); + + $item->notforloan(-1)->store(); + + is( + CanItemBeReserved( $patrons[0], $item )->{status}, 'OK', + "Item with negative notforloan status can be reserved" + ); + + $item->notforloan(0)->store(); + + is( CanItemBeReserved( $patrons[0], $item )->{status}, 'OK', "Item with no notforloan status can be reserved" ); + + $item->withdrawn(1)->store(); + + is( + CanItemBeReserved( $patrons[0], $item )->{status}, 'withdrawn', + "Item with withdrawn status cannot be reserved" + ); + }; }; -- 2.39.2