From 408c7bf001d5b9b8c2ab9118a2f67b564e79e085 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 8 Sep 2016 09:45:27 +0000 Subject: [PATCH] Bug 14695 [QA Followup] * Add tests for CanItemBeReserved returns 'itemAlreadyOnHold' to t/db_dependent/Holds.t * Don't let GetReserveId explode * Use search instead of map * Remove instances of resbarcode * Fix badly formed li closing tag Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart --- C4/Reserves.pm | 2 ++ Koha/Holds.pm | 12 +++--------- .../intranet-tmpl/prog/en/modules/circ/returns.tt | 2 -- .../prog/en/modules/reserve/request.tt | 6 +++--- t/db_dependent/Holds.t | 15 ++++++++++++++- 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 876580eb34..ae1c7b7d78 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -2332,6 +2332,8 @@ sub GetReserveId { my $hold = Koha::Holds->search( $params )->next(); + return unless $hold; + return $hold->id(); } diff --git a/Koha/Holds.pm b/Koha/Holds.pm index 235f1d4611..bde63c91e2 100644 --- a/Koha/Holds.pm +++ b/Koha/Holds.pm @@ -71,15 +71,9 @@ that would prevent one or the other. sub forced_hold_level { my ($self) = @_; - my $force_hold_level; - - if ( $self->count() ) { - my $has_item_level_holds; - map { $has_item_level_holds ||= $_->itemnumber } $self->as_list(); - $force_hold_level = $has_item_level_holds ? 'item' : 'record'; - } - - return $force_hold_level; + return $self->search( { itemnumber => { '!=' => undef } } )->count() + ? 'item' + : 'record'; } =head3 type diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt index 66b1275849..7b94e7e22e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt @@ -315,7 +315,6 @@ $(document).ready(function () { - @@ -532,7 +531,6 @@ $(document).ready(function () { - diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt index 061bbb26af..633de39388 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt @@ -276,13 +276,13 @@ function checkMultiHold() { [% ELSIF ( exceeded_holds_per_record ) %]
  • Too many holds for this record: [% borrowerfirstname %] [% borrowersurname %] can only place a maximum of [% max_holds_for_record %] hold(s) on this record.
  • [% ELSIF ( alreadypossession ) %] -
  • [% borrowerfirstname %] [% borrowersurname %] is already in possession of one item [% borrowerfirstname %] [% borrowersurname %] is already in possession of one item.
  • [% ELSIF ( alreadyreserved ) %] -
  • [% borrowerfirstname %] [% borrowersurname %] already has a hold on this item
  • +
  • [% borrowerfirstname %] [% borrowersurname %] already has a hold on this item.
  • [% ELSIF ( ageRestricted ) %]
  • Age restricted
  • [% ELSIF ( none_available ) %] -
  • No items are available to be placed on hold
  • +
  • No items are available to be placed on hold.
  • [% ELSIF ( maxreserves ) %]
  • Too many holds: [% borrowerfirstname %] [% borrowersurname %] has too many holds.
  • [% END %] diff --git a/t/db_dependent/Holds.t b/t/db_dependent/Holds.t index da67f51f0b..ff87922e21 100755 --- a/t/db_dependent/Holds.t +++ b/t/db_dependent/Holds.t @@ -8,7 +8,7 @@ use t::lib::TestBuilder; use C4::Context; use C4::Branch; -use Test::More tests => 60; +use Test::More tests => 61; use MARC::Record; use C4::Biblio; use C4::Items; @@ -339,6 +339,19 @@ ModItem({ damaged => 1 }, $item_bibnum, $itemnumber); t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 1 ); is( CanItemBeReserved( $borrowernumbers[0], $itemnumber), 'OK', "Patron can reserve damaged item with AllowHoldsOnDamagedItems enabled" ); ok( defined( ( CheckReserves($itemnumber) )[1] ), "Hold can be trapped for damaged item with AllowHoldsOnDamagedItems enabled" ); + +$hold = Koha::Hold->new( + { + borrowernumber => $borrowernumbers[0], + itemnumber => $itemnumber, + biblionumber => $item_bibnum, + } +)->store(); +is( CanItemBeReserved( $borrowernumbers[0], $itemnumber ), + 'itemAlreadyOnHold', + "Patron cannot place a second item level hold for a given item" ); +$hold->delete(); + t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 0 ); ok( CanItemBeReserved( $borrowernumbers[0], $itemnumber) eq 'damaged', "Patron cannot reserve damaged item with AllowHoldsOnDamagedItems disabled" ); ok( !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for damaged item with AllowHoldsOnDamagedItems disabled" ); -- 2.39.5