|
Lines 25-80
use MARC::Record;
Link Here
|
| 25 |
use Test::More; |
25 |
use Test::More; |
| 26 |
|
26 |
|
| 27 |
BEGIN { |
27 |
BEGIN { |
| 28 |
use_ok('Koha::RecordProcessor'); |
28 |
use_ok('Koha::RecordProcessor'); |
| 29 |
} |
29 |
} |
| 30 |
|
30 |
|
| 31 |
my $isbn = '0590353403'; |
31 |
my $isbn = '0590353403'; |
| 32 |
my $title = 'Foundation'; |
32 |
my $title = 'Foundation'; |
| 33 |
my $marc_record=MARC::Record->new; |
33 |
my $marc_record = MARC::Record->new; |
| 34 |
my $field = MARC::Field->new('020','','','a' => $isbn); |
34 |
my $field = MARC::Field->new( '020', '', '', 'a' => $isbn ); |
| 35 |
$marc_record->append_fields($field); |
35 |
$marc_record->append_fields($field); |
| 36 |
$field = MARC::Field->new('245','','','a' => $title); |
36 |
$field = MARC::Field->new( '245', '', '', 'a' => $title ); |
| 37 |
$marc_record->append_fields($field); |
37 |
$marc_record->append_fields($field); |
| 38 |
|
38 |
|
| 39 |
|
|
|
| 40 |
my $filterdir = File::Spec->rel2abs('Koha/Filter') . '/MARC'; |
39 |
my $filterdir = File::Spec->rel2abs('Koha/Filter') . '/MARC'; |
| 41 |
|
40 |
|
| 42 |
opendir(my $dh, $filterdir); |
41 |
opendir( my $dh, $filterdir ); |
| 43 |
my @installed_filters = map { ( /\.pm$/ && -f "$filterdir/$_" && s/\.pm$// ) ? "Koha::Filters::MARC::$_" : () } readdir($dh); |
42 |
my @installed_filters = map { |
|
|
43 |
( /\.pm$/ && -f "$filterdir/$_" && s/\.pm$// ) |
| 44 |
? "Koha::Filters::MARC::$_" |
| 45 |
: () |
| 46 |
} readdir($dh); |
| 44 |
my @available_filters = Koha::RecordProcessor::AvailableFilters(); |
47 |
my @available_filters = Koha::RecordProcessor::AvailableFilters(); |
| 45 |
|
48 |
|
| 46 |
foreach my $filter (@installed_filters) { |
49 |
foreach my $filter (@installed_filters) { |
| 47 |
ok(grep($filter, @available_filters), "Found filter $filter"); |
50 |
ok( grep( $filter, @available_filters ), "Found filter $filter" ); |
| 48 |
} |
51 |
} |
| 49 |
|
52 |
|
| 50 |
my $marc_filters = grep (/MARC/, @available_filters); |
53 |
my $marc_filters = grep ( /MARC/, @available_filters ); |
| 51 |
is(scalar Koha::RecordProcessor::AvailableFilters('MARC'), $marc_filters, 'Retrieved list of MARC filters'); |
54 |
is( scalar Koha::RecordProcessor::AvailableFilters('MARC'), |
|
|
55 |
$marc_filters, 'Retrieved list of MARC filters' ); |
| 52 |
|
56 |
|
| 53 |
my $processor = Koha::RecordProcessor->new( { filters => ( 'ABCD::EFGH::IJKL' ) } ); |
57 |
my $processor = |
|
|
58 |
Koha::RecordProcessor->new( { filters => ('ABCD::EFGH::IJKL') } ); |
| 54 |
|
59 |
|
| 55 |
is(ref($processor), 'Koha::RecordProcessor', 'Created record processor with invalid filter'); |
60 |
is( ref($processor), 'Koha::RecordProcessor', |
|
|
61 |
'Created record processor with invalid filter' ); |
| 56 |
|
62 |
|
| 57 |
is($processor->process($marc_record), $marc_record, 'Process record with empty processor'); |
63 |
is( $processor->process($marc_record), |
|
|
64 |
$marc_record, 'Process record with empty processor' ); |
| 58 |
|
65 |
|
| 59 |
$processor = Koha::RecordProcessor->new( { filters => ( 'Null' ) } ); |
66 |
$processor = Koha::RecordProcessor->new( { filters => ('Null') } ); |
| 60 |
is(ref($processor->filters->[0]), 'Koha::Filter::MARC::Null', 'Created record processor with implicitly scoped Null filter'); |
67 |
is( ref( $processor->filters->[0] ), |
|
|
68 |
'Koha::Filter::MARC::Null', |
| 69 |
'Created record processor with implicitly scoped Null filter' ); |
| 61 |
|
70 |
|
| 62 |
$processor = Koha::RecordProcessor->new( { filters => ( 'Koha::Filter::MARC::Null' ) } ); |
71 |
$processor = |
| 63 |
is(ref($processor->filters->[0]), 'Koha::Filter::MARC::Null', 'Created record processor with explicitly scoped Null filter'); |
72 |
Koha::RecordProcessor->new( { filters => ('Koha::Filter::MARC::Null') } ); |
|
|
73 |
is( ref( $processor->filters->[0] ), |
| 74 |
'Koha::Filter::MARC::Null', |
| 75 |
'Created record processor with explicitly scoped Null filter' ); |
| 64 |
|
76 |
|
| 65 |
is($processor->process($marc_record), $marc_record, 'Process record'); |
77 |
is( $processor->process($marc_record), $marc_record, 'Process record' ); |
| 66 |
|
78 |
|
| 67 |
$processor->bind($marc_record); |
79 |
$processor->bind($marc_record); |
| 68 |
|
80 |
|
| 69 |
is($processor->record, $marc_record, 'Bound record to processor'); |
81 |
is( $processor->record, $marc_record, 'Bound record to processor' ); |
| 70 |
|
82 |
|
| 71 |
is($processor->process(), $marc_record, 'Filter bound record'); |
83 |
is( $processor->process(), $marc_record, 'Filter bound record' ); |
| 72 |
|
84 |
|
| 73 |
eval { |
85 |
eval { |
| 74 |
$processor = Koha::RecordProcessor->new( { filters => ( 'Koha::Filter::MARC::Null' ) } ); |
86 |
$processor = |
|
|
87 |
Koha::RecordProcessor->new( { filters => ('Koha::Filter::MARC::Null') } ); |
| 75 |
undef $processor; |
88 |
undef $processor; |
| 76 |
}; |
89 |
}; |
| 77 |
|
90 |
|
| 78 |
ok(!$@, 'Destroyed processor successfully'); |
91 |
ok( !$@, 'Destroyed processor successfully' ); |
| 79 |
|
92 |
|
| 80 |
done_testing(); |
93 |
done_testing(); |