Debian Codegraph @

t/Catmandu/Fix/marc_map.t

raw
1 #!perl
2
3 use strict;
4 use warnings;
5 use Test::More;
6 use Test::Exception;
7 use Catmandu::Importer::MARC;
8 use Catmandu::Fix;
9 use utf8;
10
11 my $pkg;
12
13 BEGIN {
14 $pkg = 'Catmandu::Fix::marc_map';
15 use_ok $pkg;
16 }
17
18 require_ok $pkg;
19
20 my $fixer = Catmandu::Fix->new(fixes => ['t/test.fix']);
21 my $importer = Catmandu::Importer::MARC->new( file => 't/camel.mrc', type => "ISO" );
22 my $records = $fixer->fix($importer)->to_array;
23
24 is $records->[0]->{my}{id}, 'fol05731351 ', q|fix: marc_map('001','my.id');|;
25
26 is $records->[0]->{my}{title}, 'ActivePerl with ASP and ADO /', q|fix: marc_map('245a','my.title');|;
27
28 is_deeply
29 $records->[0]->{my}{split_title},
30 ['ActivePerl with ASP and ADO /', 'Tobias Martinsson.'],
31 q|fix: marc_map('245','my.split.title','-split', 1);|;
32
33 # field 666 does not exist in camel.mrc
34 # the '$append' fix creates $my->{'references'} hash key with empty array ref as value
35 ok !$records->[0]->{'my'}{'references'}, q|fix: marc_map('666', 'my.references.$append');|;
36
37 is $records->[0]->{my}{substr_id}, "057" , 'substring';
38
39 is $records->[0]->{my}{substr_id2}->[0], "057", 'substring + split';
40
41 ok !exists $records->[0]->{my}{failed_substr_id} , 'failed substring';
42
43 ok $records->[0]->{record} =~ /marc:datafield/ , "marcxml";
44
45 is $records->[0]->{my}->{found005} , 1 , 'if marc_match';
46
47 is $records->[0]->{my}->{found008} , 1 , 'if marc_match';
48
49 is $records->[0]->{my}->{pluck} , "M33 2000QA76.73.P22" , 'pluck feature';
50
51 is $records->[0]->{my}->{has_title}, 'Y' , 'value feature';
52
53 is $records->[0]->{has_260c}, 'OK' , 'value subfield';
54
55 ok ! $records->[0]->{has_260h}, 'value subfield';
56
57 is $records->[0]->{has_500_not_c}, 'OK' , '^c value subfield';
58
59 ok ! $records->[0]->{has_500_not_a}, '^a value subfield';
60
61 is $records->[0]->{has_800_0} , '0' , '800/0';
62
63 # gh#46: Test for subfield codes 0
64 {
65 my $mrc
66 = '00093nam a2200037 c 45001000055000001 aPoe, Curtis0(DE-601)7303424090(DE-588)1028093195';
67
68 my $fixer = Catmandu::Fix->new(
69 fixes => [
70 'marc_map(100,subf_all,join => "~")',
71 'marc_map(1000,subf_zero,join => "~")',
72 'marc_map(1000a,subf_zero_pluck,join => "~",pluck => 1)',
73 ]
74 );
75 my $importer = Catmandu::Importer::MARC->new( file => \$mrc, type => 'ISO' );
76 my $record = $fixer->fix($importer)->first;
77
78 is( $record->{subf_all},
79 'Poe, Curtis~(DE-601)730342409~(DE-588)1028093195',
80 'all subfields'
81 );
82 is( $record->{subf_zero}, '(DE-601)730342409~(DE-588)1028093195',
83 'subfields 0' );
84 is( $record->{subf_zero_pluck}, '(DE-601)730342409~(DE-588)1028093195~Poe, Curtis',
85 'subfields 0 pluck' );
86 }
87
88 done_testing;