Bug 10653: add unit tests for C4::RotatingCollections.pm
[koha.git] / t / RecordProcessor.t
blob32acc6bb6d8eab9aba5602548b1575e3051c142a
1 #!/usr/bin/perl
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 under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 use strict;
21 use warnings;
22 use File::Spec;
23 use MARC::Record;
25 use Test::More;
27 BEGIN {
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');
73 eval {
74 $processor = Koha::RecordProcessor->new( { filters => ( 'Koha::Filter::MARC::Null' ) } );
75 undef $processor;
78 ok(!$@, 'Destroyed processor successfully');
80 done_testing();