| 1 |
#!perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use Test::More; |
| 6 |
use Test::Exception; |
| 7 |
|
| 8 |
my $pkg; |
| 9 |
|
| 10 |
BEGIN { |
| 11 |
$pkg = 'Catmandu::Fix::Condition::marc_has_many'; |
| 12 |
use_ok $pkg; |
| 13 |
} |
| 14 |
|
| 15 |
require_ok $pkg; |
| 16 |
|
| 17 |
my $mrc = <<'MRC'; |
| 18 |
<?xml version="1.0" encoding="UTF-8"?> |
| 19 |
<marc:collection xmlns:marc="http://www.loc.gov/MARC21/slim"> |
| 20 |
<marc:record> |
| 21 |
<marc:controlfield tag="001"> 92005291 </marc:controlfield> |
| 22 |
<marc:datafield ind1="1" ind2="0" tag="245"> |
| 23 |
<marc:subfield code="a">Title / </marc:subfield> |
| 24 |
<marc:subfield code="c">Name</marc:subfield> |
| 25 |
</marc:datafield> |
| 26 |
<marc:datafield ind1=" " ind2=" " tag="998"> |
| 27 |
<marc:subfield code="a">X</marc:subfield> |
| 28 |
<marc:subfield code="a">Y</marc:subfield> |
| 29 |
<marc:subfield code="b">Z</marc:subfield> |
| 30 |
</marc:datafield> |
| 31 |
<marc:datafield ind1=" " ind2=" " tag="999"> |
| 32 |
<marc:subfield code="a">X</marc:subfield> |
| 33 |
<marc:subfield code="a">Y</marc:subfield> |
| 34 |
</marc:datafield> |
| 35 |
<marc:datafield ind1=" " ind2=" " tag="999"> |
| 36 |
<marc:subfield code="a">Z</marc:subfield> |
| 37 |
</marc:datafield> |
| 38 |
</marc:record> |
| 39 |
</marc:collection> |
| 40 |
MRC |
| 41 |
|
| 42 |
note 'marc_has_many(001)'; |
| 43 |
{ |
| 44 |
my $importer = Catmandu->importer( |
| 45 |
'MARC', |
| 46 |
file => \$mrc, |
| 47 |
type => 'XML', |
| 48 |
fix => 'if marc_has_many(001) add_field(test,failed) end' |
| 49 |
); |
| 50 |
my $record = $importer->first; |
| 51 |
|
| 52 |
ok ! $record->{test} , 'ok no match'; |
| 53 |
} |
| 54 |
|
| 55 |
note 'marc_has_many(999)'; |
| 56 |
{ |
| 57 |
my $importer = Catmandu->importer( |
| 58 |
'MARC', |
| 59 |
file => \$mrc, |
| 60 |
type => 'XML', |
| 61 |
fix => 'if marc_has_many(999) add_field(test,ok) end' |
| 62 |
); |
| 63 |
my $record = $importer->first; |
| 64 |
|
| 65 |
is $record->{test} , "ok" , 'ok match'; |
| 66 |
} |
| 67 |
|
| 68 |
note 'marc_has_many(998a)'; |
| 69 |
{ |
| 70 |
my $importer = Catmandu->importer( |
| 71 |
'MARC', |
| 72 |
file => \$mrc, |
| 73 |
type => 'XML', |
| 74 |
fix => 'if marc_has_many(998a) add_field(test,ok) end' |
| 75 |
); |
| 76 |
my $record = $importer->first; |
| 77 |
|
| 78 |
is $record->{test} , "ok" , 'ok match'; |
| 79 |
} |
| 80 |
|
| 81 |
note 'marc_has_many(998b)'; |
| 82 |
{ |
| 83 |
my $importer = Catmandu->importer( |
| 84 |
'MARC', |
| 85 |
file => \$mrc, |
| 86 |
type => 'XML', |
| 87 |
fix => 'if marc_has_many(998b) add_field(test,failed) end' |
| 88 |
); |
| 89 |
my $record = $importer->first; |
| 90 |
|
| 91 |
ok ! $record->{test} , 'ok no match'; |
| 92 |
} |
| 93 |
|
| 94 |
done_testing; |