|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# This script tests IsHoldNoteRequired |
| 4 |
|
| 5 |
# Copyright 2016 Rijksmuseum |
| 6 |
# |
| 7 |
# This file is part of Koha. |
| 8 |
# |
| 9 |
# Koha is free software; you can redistribute it and/or modify it |
| 10 |
# under the terms of the GNU General Public License as published by |
| 11 |
# the Free Software Foundation; either version 3 of the License, or |
| 12 |
# (at your option) any later version. |
| 13 |
# |
| 14 |
# Koha is distributed in the hope that it will be useful, but |
| 15 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
# GNU General Public License for more details. |
| 18 |
# |
| 19 |
# You should have received a copy of the GNU General Public License |
| 20 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 21 |
|
| 22 |
use Modern::Perl; |
| 23 |
use Test::More tests => 6; |
| 24 |
use C4::Reserves qw|IsHoldNoteRequired|; |
| 25 |
use Koha::Database; |
| 26 |
|
| 27 |
# we only need the db for the preferences.. |
| 28 |
my $schema = Koha::Database->new->schema; |
| 29 |
$schema->storage->txn_begin; |
| 30 |
|
| 31 |
# MARC record for testing |
| 32 |
my $marc = MARC::Record->new(); |
| 33 |
$marc->leader( '0123456s' ); # we only care about position 7 here |
| 34 |
$marc->append_fields( MARC::Field->new( '245', '', '', 'a', 'Title' ) ); |
| 35 |
$marc->append_fields( MARC::Field->new( '300', '', '', 'a', 'my 1st desc' ) ); |
| 36 |
$marc->append_fields( MARC::Field->new( '300', '', '', 'a', '2 vols' ) ); |
| 37 |
|
| 38 |
# Actual testing starts here! |
| 39 |
C4::Context->set_preference( 'OPACHoldNotes', '1' ); |
| 40 |
C4::Context->set_preference( 'HoldNoteReasons', '' ); |
| 41 |
is( IsHoldNoteRequired( $marc ), undef, 'Check empty HoldNoteReasons' ); |
| 42 |
C4::Context->set_preference( 'HoldNoteReasons', 'ThisReasonDoesNotExist' ); |
| 43 |
is( IsHoldNoteRequired( $marc ), undef, 'Check invalid HoldNoteReasons' ); |
| 44 |
|
| 45 |
C4::Context->set_preference( 'HoldNoteReasons', 'LEADER_SERIAL' ); |
| 46 |
is( IsHoldNoteRequired( $marc ), 1, 'Check LEADER_SERIAL' ); |
| 47 |
$marc->leader( '01234567' ); |
| 48 |
is( IsHoldNoteRequired( $marc ), undef, 'Check LEADER_SERIAL again' ); |
| 49 |
|
| 50 |
C4::Context->set_preference( 'HoldNoteReasons', 'text|marc300a_parts|etc' ); |
| 51 |
is( IsHoldNoteRequired( $marc ), 1, 'Check MARC300A_PARTS' ); |
| 52 |
my @f300 = $marc->field( '300' ); |
| 53 |
$marc->delete_fields( $f300[1] ); # delete the second 300 |
| 54 |
is( IsHoldNoteRequired( $marc ), undef, 'Check MARC300A_PARTS again' ); |
| 55 |
|
| 56 |
# End of game |
| 57 |
$schema->storage->txn_rollback; |
| 58 |
|
| 59 |
1; |