#
# 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 2 of the License, or (at your option) any later
-# version.
+# 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.
+# 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, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# 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 strict;
-use warnings;
use File::Spec;
use MARC::Record;
ok(!$@, 'Destroyed processor successfully');
+subtest "new() tests" => sub {
+
+ plan tests => 14;
+
+ 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.
+ # use hash reference for regression testing
+ my $parameters = {
+ filters => [ 'Null', 'Dummy' ],
+ options => { 'test' => 'true' }
+ };
+ $processor = new Koha::RecordProcessor($parameters);
+ 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' );
+
+ my $filter_params = $processor->filters->[0]->params;
+ is_deeply( $filter_params, $parameters, 'Initialization parameters' );
+};
+
done_testing();