Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# This script tests C4::Reserves::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 File::Temp qw/tempdir/; |
24 |
use MARC::Record; |
25 |
use Test::More tests => 3; |
26 |
|
27 |
use t::lib::Mocks; |
28 |
use C4::Context; |
29 |
use C4::Reserves; |
30 |
use Koha::Database; |
31 |
|
32 |
my $schema = Koha::Database->new->schema; |
33 |
$schema->storage->txn_begin; |
34 |
|
35 |
# Add a temporary plugin |
36 |
C4::Context->set_preference( 'OPACHoldNotes', '1' ); |
37 |
t::lib::Mocks::mock_config( 'enable_plugins', 1); |
38 |
my $tempdir = tempdir( CLEANUP => 1 ); |
39 |
my $org_pluginsdir = C4::Context->config('pluginsdir') // ''; |
40 |
t::lib::Mocks::mock_config( 'pluginsdir', $tempdir ); |
41 |
add_myplugin( $tempdir ); |
42 |
# Adjust searchable module dirs |
43 |
@INC = grep { $_ ne $org_pluginsdir } ( @INC, $tempdir ); |
44 |
|
45 |
# First test with disabled plugins |
46 |
C4::Context->set_preference( 'UseKohaPlugins', '0' ); |
47 |
isnt( C4::Reserves::IsHoldNoteRequired(), 1, 'Should be false if plugins are disabled' ); |
48 |
|
49 |
# Enable plugin now |
50 |
# Note: the plugin actually ignores $marc and returns true for a non-zero bibno |
51 |
my $marc = MARC::Record->new; |
52 |
C4::Context->set_preference( 'UseKohaPlugins', '1' ); |
53 |
is( C4::Reserves::IsHoldNoteRequired( 2, $marc ), 1, 'Should be true for biblionumber 2' ); |
54 |
isnt( C4::Reserves::IsHoldNoteRequired( 0, $marc ), 1, 'Should be false for biblionumber 0' ); |
55 |
|
56 |
# End |
57 |
$schema->storage->txn_rollback; |
58 |
|
59 |
sub add_myplugin { |
60 |
my ( $dir ) = @_; |
61 |
system( "mkdir -p $dir/Koha/Plugin" ); |
62 |
open my $fh, '>', $dir.'/Koha/Plugin/Rijks_MyPlugin.pm'; |
63 |
print $fh |
64 |
q|package Koha::Plugin::Rijks_MyPlugin; |
65 |
use Modern::Perl; |
66 |
use base qw(Koha::Plugins::Base); |
67 |
|
68 |
our $metadata = { |
69 |
name => 'Rijks_MyPlugin', |
70 |
implements => 'IsHoldNoteRequired', # needed for C4::Reserves |
71 |
}; |
72 |
|
73 |
sub new { |
74 |
my ( $class, $args ) = @_; |
75 |
$args->{'metadata'} = $metadata; |
76 |
my $self = $class->SUPER::new($args); |
77 |
return $self; |
78 |
} |
79 |
|
80 |
sub check { |
81 |
my ( $self, $args ) = @_; |
82 |
return $args->{biblionumber}; # unusual return value for testing |
83 |
} |
84 |
|
85 |
1;|; |
86 |
close $fh; |
87 |
} |
88 |
|
89 |
1; |