180686f7c0599db304efd772f063b25ffcb98d5f
[working/Evergreen.git] / Open-ILS / src / perlmods / t / 14-OpenILS-Utils.t
1 #!perl -T
2
3 use Test::More tests => 29;
4 use Test::Warn;
5 use utf8;
6
7 use_ok( 'OpenILS::Utils::Configure' );
8 use_ok( 'OpenILS::Utils::Cronscript' );
9 use_ok( 'OpenILS::Utils::CStoreEditor' );
10 use_ok( 'OpenILS::Utils::Fieldmapper' );
11 use_ok( 'OpenILS::Utils::ISBN' );
12 use_ok( 'OpenILS::Utils::Lockfile' );
13 use_ok( 'OpenILS::Utils::MFHDParser' );
14 use_ok( 'OpenILS::Utils::MFHD' );
15 use_ok( 'OpenILS::Utils::ModsParser' );
16 use_ok( 'OpenILS::Utils::Normalize' );
17 use_ok( 'OpenILS::Utils::OfflineStore' );
18 use_ok( 'OpenILS::Utils::Penalty' );
19 use_ok( 'OpenILS::Utils::PermitHold' );
20 use_ok( 'OpenILS::Utils::RemoteAccount' );
21 use_ok( 'OpenILS::Utils::ZClient' );
22 use_ok( 'OpenILS::Utils::EDIReader' );
23
24 # LP 800269 - Test MFHD holdings for records that only contain a caption field
25 my $co_marc = MARC::Record->new();
26 $co_marc->append_fields(
27     MARC::Field->new('853','','',
28         '8' => '1',
29         'a' => 'v.',
30         'b' => '[no.]',
31     )
32 );
33 my $co_mfhd = MFHD->new($co_marc);
34
35 my @comp_holdings;
36 warning_like {
37     @comp_holdings = $co_mfhd->get_compressed_holdings($co_mfhd->field('853'));
38 } [ qr/Cannot compress without pattern data, returning original holdings/ ],
39     "warning when attempting to compress holdings without a pattern";
40
41 is(@comp_holdings, 0, "Compressed holdings for an MFHD record that only has a caption");
42
43 my @decomp_holdings = $co_mfhd->get_decompressed_holdings($co_mfhd->field('853'));
44 is(@decomp_holdings, 0, "Decompressed holdings for an MFHD record that only has a caption");
45
46 my $apostring = OpenILS::Utils::Normalize::naco_normalize("it's time");
47 is($apostring, "its time", "naco_normalize: strip apostrophes");
48
49 my $apos = OpenILS::Utils::Normalize::search_normalize("it's time");
50 is($apos, "it s time", "search_normalize: replace apostrophes with space");
51
52 my $raw_marcxml = <<RAWMARC;
53 <?xml version="1.0" encoding="utf-8"?>
54 <record>
55   <leader>01614nmm a22003975u 4500</leader>
56   <controlfield tag="001">978-0-387-35767-6</controlfield>
57   <controlfield tag="003">Springer</controlfield>
58   <controlfield tag="005">20071022150035.8</controlfield>
59   <controlfield tag="007">cr nn 008mamaa</controlfield>
60   <controlfield tag="008">071022s2008    xx         j        eng d</controlfield>
61   <datafield tag="020" ind1=" " ind2=" ">
62     <subfield code="a">9780387685748</subfield>
63   </datafield>
64   <datafield tag="100" ind1="1" ind2=" ">
65     <subfield code="a">Neteler, Markus.</subfield>
66   </datafield>
67   <datafield tag="245" ind1="1" ind2="0">
68     <subfield code="a">Open Source GIS</subfield>
69     <subfield code="h">[electronic resource] :</subfield>
70     <subfield code="b">A GRASS GIS Approach /</subfield>
71     <subfield code="c">edited by Markus Neteler, Helena Mitasova.</subfield>
72   </datafield>
73   <datafield tag="250" ind1=" " ind2=" ">
74     <subfield code="a">Third Edition.</subfield>
75   </datafield>
76   <datafield tag="260" ind1=" " ind2=" ">
77     <subfield code="a">Boston, MA :</subfield>
78     <subfield code="b">Springer Science+Business Media, LLC,</subfield>
79     <subfield code="c">2008.</subfield>
80   </datafield>
81 </record>
82 RAWMARC
83 my $exp_xml = '<record><leader>01614nmm a22003975u 4500</leader><controlfield tag="001">978-0-387-35767-6</controlfield><controlfield tag="003">Springer</controlfield><controlfield tag="005">20071022150035.8</controlfield><controlfield tag="007">cr nn 008mamaa</controlfield><controlfield tag="008">071022s2008    xx         j        eng d</controlfield><datafield tag="020" ind1=" " ind2=" "><subfield code="a">9780387685748</subfield></datafield><datafield tag="100" ind1="1" ind2=" "><subfield code="a">Neteler, Markus.</subfield></datafield><datafield tag="245" ind1="1" ind2="0"><subfield code="a">Open Source GIS</subfield><subfield code="h">[electronic resource] :</subfield><subfield code="b">A GRASS GIS Approach /</subfield><subfield code="c">edited by Markus Neteler, Helena Mitasova.</subfield></datafield><datafield tag="250" ind1=" " ind2=" "><subfield code="a">Third Edition.</subfield></datafield><datafield tag="260" ind1=" " ind2=" "><subfield code="a">Boston, MA :</subfield><subfield code="b">Springer Science+Business Media, LLC,</subfield><subfield code="c">2008.</subfield></datafield></record>';
84 my $clean_xml = OpenILS::Utils::Normalize::clean_marc($raw_marcxml);
85 is($clean_xml, $exp_xml, "clean_marc: header and space normalization");
86
87 is(OpenILS::Application::AppUtils->entityize('èöçÇÈÀ'), '&#xE8;&#xF6;&#xE7;&#xC7;&#xC8;&#xC0;', 'entityize: diacritics NFC');
88 is(OpenILS::Application::AppUtils->entityize('èöçÇÈÀ', 'D'), 'e&#x300;o&#x308;c&#x327;C&#x327;E&#x300;A&#x300;', 'entityize: diacritics NFD');
89 is(OpenILS::Utils::Normalize::clean_marc('èöçÇÈÀ'), '&#xE8;&#xF6;&#xE7;&#xC7;&#xC8;&#xC0;', 'clean_marc: diacritics');
90
91 my $edi_invoice = "UNA:+.? 'UNB+UNOC:3+1556150:31B+123EVER:31B+120926:1621+4'UNH+11+INVOIC:D:96A:UN'BGM+380+5TST084026+9'DTM+137:20120924:102'RFF+ON:24'NAD+BY+123EVER 0001::91'NAD+SU+1691503::31B'CUX+2:USD:4'LIN+1++9780446360272'QTY+47:5'MOA+146:4.5:USD:10'MOA+203:14.65'PRI+AAF:2.93:DI:NTP'RFF+LI:24/102'LIN+2++9780446357197'QTY+47:8'MOA+146:6.5:USD:10'MOA+203:33.84'PRI+AAF:4.23:DI:NTP'RFF+LI:24/100'UNS+S'MOA+86:66.18'ALC+C++++DL'MOA+8:2'ALC+C++++CA'MOA+131:12.3'ALC+C++++TX'MOA+8:3.39'UNT+28+11'UNH+12+INVOIC:D:96A:UN'BGM+380+5TST084027+9'DTM+137:20120924:102'RFF+ON:26'NAD+BY+123EVER 0001::91'NAD+SU+1691503::31B'CUX+2:USD:4'LIN+1++9780446360272'QTY+47:1'MOA+146:4.5:USD:10'MOA+203:4.05'PRI+AAF:4.05:DI:NTP'RFF+LI:26/106'LIN+2++9780446350105'QTY+47:3'MOA+146:6.99:USD:10'MOA+203:14.67'PRI+AAF:4.89:DI:NTP'RFF+LI:26/105'UNS+S'MOA+86:25.03'ALC+C++++DL'MOA+8:2'ALC+C++++CA'MOA+131:3'ALC+C++++TX'MOA+8:1.31'UNT+28+12'UNZ+4+4'";
92
93 my $edi_msgs = OpenILS::Utils::EDIReader->new->read($edi_invoice);
94
95 is($edi_msgs->[0]->{message_type}, 'INVOIC', 'edi reader: message type');
96 is($edi_msgs->[0]->{purchase_order}, '24', 'edi reader: PO number');
97 is($edi_msgs->[1]->{invoice_ident}, '5TST084027', 'edi reader: invoice ident');
98 is(scalar(@{$edi_msgs->[1]->{lineitems}}), '2', 'edi reader: lineitem count');
99