From 1ca239eb31df8f1be25835a39c4229fd902a26fd Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Wed, 13 Jan 2016 10:57:27 +0100 Subject: [PATCH] Bug 15545: Unit test for IsHoldNoteRequired Content-Type: text/plain; charset=utf-8 Adds unit test. Test plan: Run the test t/db../Reserves/IsHoldNoteRequired.t --- t/db_dependent/Reserves/IsHoldNoteRequired.t | 59 ++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 t/db_dependent/Reserves/IsHoldNoteRequired.t diff --git a/t/db_dependent/Reserves/IsHoldNoteRequired.t b/t/db_dependent/Reserves/IsHoldNoteRequired.t new file mode 100755 index 0000000..80e7196 --- /dev/null +++ b/t/db_dependent/Reserves/IsHoldNoteRequired.t @@ -0,0 +1,59 @@ +#!/usr/bin/perl + +# This script tests IsHoldNoteRequired + +# Copyright 2016 Rijksmuseum +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; +use Test::More tests => 6; +use C4::Reserves qw|IsHoldNoteRequired|; +use Koha::Database; + +# we only need the db for the preferences.. +my $schema = Koha::Database->new->schema; +$schema->storage->txn_begin; + +# MARC record for testing +my $marc = MARC::Record->new(); +$marc->leader( '0123456s' ); # we only care about position 7 here +$marc->append_fields( MARC::Field->new( '245', '', '', 'a', 'Title' ) ); +$marc->append_fields( MARC::Field->new( '300', '', '', 'a', 'my 1st desc' ) ); +$marc->append_fields( MARC::Field->new( '300', '', '', 'a', '2 vols' ) ); + +# Actual testing starts here! +C4::Context->set_preference( 'OPACHoldNotes', '1' ); +C4::Context->set_preference( 'HoldNoteReasons', '' ); +is( IsHoldNoteRequired( $marc ), undef, 'Check empty HoldNoteReasons' ); +C4::Context->set_preference( 'HoldNoteReasons', 'ThisReasonDoesNotExist' ); +is( IsHoldNoteRequired( $marc ), undef, 'Check invalid HoldNoteReasons' ); + +C4::Context->set_preference( 'HoldNoteReasons', 'LEADER_SERIAL' ); +is( IsHoldNoteRequired( $marc ), 1, 'Check LEADER_SERIAL' ); +$marc->leader( '01234567' ); +is( IsHoldNoteRequired( $marc ), undef, 'Check LEADER_SERIAL again' ); + +C4::Context->set_preference( 'HoldNoteReasons', 'text|marc300a_parts|etc' ); +is( IsHoldNoteRequired( $marc ), 1, 'Check MARC300A_PARTS' ); +my @f300 = $marc->field( '300' ); +$marc->delete_fields( $f300[1] ); # delete the second 300 +is( IsHoldNoteRequired( $marc ), undef, 'Check MARC300A_PARTS again' ); + +# End of game +$schema->storage->txn_rollback; + +1; -- 1.7.10.4