From b89e48ca36eb4f4cc37a13474e7731b9867d2128 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Thu, 23 Apr 2015 11:54:40 +0200 Subject: [PATCH] Bug 11999: Check for age restriction in CanBookBeReserved + improve t/db_dependent/Reserves.t to make tests pass on UNIMARC installation Maxreserves and alreadyreserved works on ILSDI Maxreserves works also on staff and opac Already reserves works also on staff and opac tests on t/db_dependent/Reserves.t and t/db_dependent/Holds.t passe (using koha_ut db) Signed-off-by: Alex Arnaud --- C4/Reserves.pm | 6 ++++++ t/db_dependent/Reserves.t | 12 ++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index c3ff373..2f9a82d 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -431,6 +431,12 @@ sub CanBookBeReserved{ return 'tooManyReserves'; } + # Check for the age restriction + my $biblioData = C4::Biblio::GetBiblioData( $biblionumber ); + my $borrower = C4::Members::GetMember(borrowernumber => $borrowernumber); + my ($ageRestriction, $daysToAgeRestriction) = C4::Circulation::GetAgeRestriction( $biblioData->{agerestriction}, $borrower ); + return 'ageRestricted' if $daysToAgeRestriction && $daysToAgeRestriction > 0; + my $items = GetItemnumbersForBiblio($biblionumber); #get items linked via host records my @hostitems = get_hostitemnumbers_of($biblionumber); diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index cfc6eee..8a32051 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -19,6 +19,7 @@ use Modern::Perl; use Test::More tests => 73; use Test::Warn; +use Test::MockModule; use MARC::Record; use DateTime::Duration; @@ -39,9 +40,8 @@ BEGIN { } # a very minimal mack of userenv for use by the test of DelItemCheck -*C4::Context::userenv = sub { - return {}; -}; +my $c4_context = Test::MockModule->new('C4::Context'); +$c4_context->mock('userenv', sub { return { flags => 1 } }); my $dbh = C4::Context->dbh; @@ -50,7 +50,11 @@ $dbh->{AutoCommit} = 0; $dbh->{RaiseError} = 1; # Somewhat arbitrary field chosen for age restriction unit tests. Must be added to db before the framework is cached -$dbh->do("update marc_subfield_structure set kohafield='biblioitems.agerestriction' where tagfield='521' and tagsubfield='a'"); +$dbh->do(q| + INSERT INTO marc_subfield_structure (frameworkcode, tagfield, tagsubfield, kohafield) + VALUES ('', '521', 'a', 'biblioitems.agerestriction') + ON DUPLICATE KEY UPDATE kohafield = VALUES(kohafield) +|); # Setup Test------------------------ -- 2.1.4