3 # Copyright 2012 C & P Bibliography Services
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
28 use_ok
('Koha::RecordProcessor');
31 my $isbn = '0590353403';
32 my $title = 'Foundation';
33 my $marc_record=MARC
::Record
->new;
34 my $field = MARC
::Field
->new('020','','','a' => $isbn);
35 $marc_record->append_fields($field);
36 $field = MARC
::Field
->new('245','','','a' => $title);
37 $marc_record->append_fields($field);
40 my $filterdir = File
::Spec
->rel2abs('Koha/Filter') . '/MARC';
42 opendir(my $dh, $filterdir);
43 my @installed_filters = map { ( /\.pm$/ && -f
"$filterdir/$_" && s
/\
.pm
$// ) ?
"Koha::Filters::MARC::$_" : () } readdir($dh);
44 my @available_filters = Koha
::RecordProcessor
::AvailableFilters
();
46 foreach my $filter (@installed_filters) {
47 ok
(grep($filter, @available_filters), "Found filter $filter");
50 my $marc_filters = grep (/MARC/, @available_filters);
51 is
(scalar Koha
::RecordProcessor
::AvailableFilters
('MARC'), $marc_filters, 'Retrieved list of MARC filters');
53 my $processor = Koha
::RecordProcessor
->new( { filters
=> ( 'ABCD::EFGH::IJKL' ) } );
55 is
(ref($processor), 'Koha::RecordProcessor', 'Created record processor with invalid filter');
57 is
($processor->process($marc_record), $marc_record, 'Process record with empty processor');
59 $processor = Koha
::RecordProcessor
->new( { filters
=> ( 'Null' ) } );
60 is
(ref($processor->filters->[0]), 'Koha::Filter::MARC::Null', 'Created record processor with implicitly scoped Null filter');
62 $processor = Koha
::RecordProcessor
->new( { filters
=> ( 'Koha::Filter::MARC::Null' ) } );
63 is
(ref($processor->filters->[0]), 'Koha::Filter::MARC::Null', 'Created record processor with explicitly scoped Null filter');
65 is
($processor->process($marc_record), $marc_record, 'Process record');
67 $processor->bind($marc_record);
69 is
($processor->record, $marc_record, 'Bound record to processor');
71 is
($processor->process(), $marc_record, 'Filter bound record');
74 $processor = Koha
::RecordProcessor
->new( { filters
=> ( 'Koha::Filter::MARC::Null' ) } );
78 ok
(!$@
, 'Destroyed processor successfully');