+ok( !$EVAL_ERROR && $destroy_test == 1, 'Destroyed processor successfully' );
+
+subtest 'new() tests' => sub {
+
+ plan tests => 14;
+
+ my $record_processor;
+
+ # Create a processor with a valid filter
+ $record_processor = Koha::RecordProcessor->new( { filters => 'Null' } );
+ is( ref($record_processor), 'Koha::RecordProcessor', 'Processor created' );
+ is( scalar @{ $record_processor->filters }, 1, 'One filter initialized' );
+ is( ref( $record_processor->filters->[0] ),
+ 'Koha::Filter::MARC::Null', 'Correct filter initialized' );
+
+ # Create a processor with an invalid filter
+ $record_processor = Koha::RecordProcessor->new( { filters => 'Dummy' } );
+ is( ref($record_processor), 'Koha::RecordProcessor', 'Processor created' );
+ is( scalar @{ $record_processor->filters }, 0, 'No filter initialized' );
+ is( ref( $record_processor->filters->[0] ),
+ q{}, 'Make sure no filter initialized' );
+
+ # Create a processor with two valid filters
+ $record_processor = Koha::RecordProcessor->new(
+ { filters => [ 'Null', 'EmbedSeeFromHeadings' ] } );
+ is( ref($record_processor), 'Koha::RecordProcessor', 'Processor created' );
+ is( scalar @{ $record_processor->filters }, 2, 'Two filters initialized' );
+ is(
+ ref( $record_processor->filters->[0] ),
+ 'Koha::Filter::MARC::Null',
+ 'Correct first filter initialized'
+ );
+ is(
+ ref( $record_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' }
+ };
+ $record_processor = Koha::RecordProcessor->new($parameters);
+ is( ref($record_processor), 'Koha::RecordProcessor', 'Processor created' );
+ is( scalar @{ $record_processor->filters }, 1, 'Invalid filter skipped' );
+ is( ref( $record_processor->filters->[0] ),
+ 'Koha::Filter::MARC::Null', 'Correct filter initialized' );
+
+ my $filter_params = $record_processor->filters->[0]->params;
+ is_deeply( $filter_params, $parameters, 'Initialization parameters' );
+};
+
+subtest 'options() tests' => sub {
+
+ plan tests => 6;
+
+ # Create a processor with some options
+ my $record_processor = Koha::RecordProcessor->new(
+ {
+ filters => ['EmbedSeeFromHeadings','Null'],
+ options => {
+ dummy => 'something'
+ }
+ }
+ );
+
+ my $filter = $record_processor->filters->[0];
+
+ is(
+ ref( $filter ),
+ 'Koha::Filter::MARC::EmbedSeeFromHeadings',
+ 'Correct second filter initialized'
+ );
+
+ is_deeply(
+ $filter->params->{options},
+ { dummy => 'something' },
+ 'Options are set correctly'
+ );
+
+ # Update the chosen options
+ my $ret = $record_processor->options(
+ {
+ dummy => 'something else'
+ }
+ );
+
+ is( ref($ret), 'Koha::RecordProcessor', 'The setter return the object for chaining calls' );
+ is_deeply( $record_processor->options, { dummy => 'something else' }, 'The getter works as expected' );
+
+ # Re-fetch the filter
+ $filter = $record_processor->filters->[0];
+
+ is(
+ ref( $filter ),
+ 'Koha::Filter::MARC::EmbedSeeFromHeadings',
+ 'Correct second filter initialized'
+ );
+
+ is_deeply(
+ $filter->params->{options},
+ { dummy => 'something else' },
+ 'Options are updated correctly'
+ );
+};