forked from Koha-Community/Koha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRecordProcessor.t
executable file
·113 lines (82 loc) · 4.35 KB
/
RecordProcessor.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/perl
# Copyright 2012 C & P Bibliography Services
#
# 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 <http://www.gnu.org/licenses>.
use Modern::Perl;
use File::Spec;
use MARC::Record;
use Test::More;
BEGIN {
use_ok('Koha::RecordProcessor');
}
my $isbn = '0590353403';
my $title = 'Foundation';
my $marc_record=MARC::Record->new;
my $field = MARC::Field->new('020','','','a' => $isbn);
$marc_record->append_fields($field);
$field = MARC::Field->new('245','','','a' => $title);
$marc_record->append_fields($field);
my $filterdir = File::Spec->rel2abs('Koha/Filter') . '/MARC';
opendir(my $dh, $filterdir);
my @installed_filters = map { ( /\.pm$/ && -f "$filterdir/$_" && s/\.pm$// ) ? "Koha::Filters::MARC::$_" : () } readdir($dh);
my @available_filters = Koha::RecordProcessor::AvailableFilters();
foreach my $filter (@installed_filters) {
ok(grep($filter, @available_filters), "Found filter $filter");
}
my $marc_filters = grep (/MARC/, @available_filters);
is(scalar Koha::RecordProcessor::AvailableFilters('MARC'), $marc_filters, 'Retrieved list of MARC filters');
my $processor = Koha::RecordProcessor->new( { filters => ( 'ABCD::EFGH::IJKL' ) } );
is(ref($processor), 'Koha::RecordProcessor', 'Created record processor with invalid filter');
is($processor->process($marc_record), $marc_record, 'Process record with empty processor');
$processor = Koha::RecordProcessor->new( { filters => ( 'Null' ) } );
is(ref($processor->filters->[0]), 'Koha::Filter::MARC::Null', 'Created record processor with implicitly scoped Null filter');
$processor = Koha::RecordProcessor->new( { filters => ( 'Koha::Filter::MARC::Null' ) } );
is(ref($processor->filters->[0]), 'Koha::Filter::MARC::Null', 'Created record processor with explicitly scoped Null filter');
is($processor->process($marc_record), $marc_record, 'Process record');
$processor->bind($marc_record);
is($processor->record, $marc_record, 'Bound record to processor');
is($processor->process(), $marc_record, 'Filter bound record');
eval {
$processor = Koha::RecordProcessor->new( { filters => ( 'Koha::Filter::MARC::Null' ) } );
undef $processor;
};
ok(!$@, 'Destroyed processor successfully');
subtest "new() tests" => sub {
plan tests => 13;
my $processor;
# Create a processor with a valid filter
$processor = new Koha::RecordProcessor({ filters => 'Null' });
is( ref($processor), 'Koha::RecordProcessor', 'Processor created' );
is( scalar @{ $processor->filters }, 1, 'One filter initialized' );
is( ref($processor->filters->[0]), 'Koha::Filter::MARC::Null', 'Correct filter initialized' );
# Create a processor with an invalid filter
$processor = new Koha::RecordProcessor({ filters => 'Dummy' });
is( ref($processor), 'Koha::RecordProcessor', 'Processor created' );
is( scalar @{ $processor->filters }, 0, 'No filter initialized' );
is( ref($processor->filters->[0]), '', 'Make sure no filter initialized' );
# Create a processor with two valid filters
$processor = new Koha::RecordProcessor({ filters => [ 'Null', 'EmbedSeeFromHeadings' ] });
is( ref($processor), 'Koha::RecordProcessor', 'Processor created' );
is( scalar @{ $processor->filters }, 2, 'Two filters initialized' );
is( ref($processor->filters->[0]), 'Koha::Filter::MARC::Null', 'Correct first filter initialized' );
is( ref($processor->filters->[1]), 'Koha::Filter::MARC::EmbedSeeFromHeadings', 'Correct second filter initialized' );
# Create a processor with both valid and invalid filters.
$processor = new Koha::RecordProcessor({ filters => [ 'Null', 'Dummy' ] });
is( ref($processor), 'Koha::RecordProcessor', 'Processor created' );
is( scalar @{ $processor->filters }, 1, 'Invalid filter skipped' );
is( ref($processor->filters->[0]), 'Koha::Filter::MARC::Null', 'Correct filter initialized' );
};
done_testing();