LP#1541559: HTTPClient: a utility for sending HTTP requests and handling responses
[working/Evergreen.git] / Open-ILS / src / perlmods / t / 14-OpenILS-Utils.t
1 #!perl -T
2
3 use Test::More tests => 30;
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 use_ok( 'OpenILS::Utils::HTTPClient' );
24
25 # LP 800269 - Test MFHD holdings for records that only contain a caption field
26 my $co_marc = MARC::Record->new();
27 $co_marc->append_fields(
28     MARC::Field->new('853','','',
29         '8' => '1',
30         'a' => 'v.',
31         'b' => '[no.]',
32     )
33 );
34 my $co_mfhd = MFHD->new($co_marc);
35
36 my @comp_holdings;
37 warning_like {
38     @comp_holdings = $co_mfhd->get_compressed_holdings($co_mfhd->field('853'));
39 } [ qr/Cannot compress without pattern data, returning original holdings/ ],
40     "warning when attempting to compress holdings without a pattern";
41
42 is(@comp_holdings, 0, "Compressed holdings for an MFHD record that only has a caption");
43
44 my @decomp_holdings = $co_mfhd->get_decompressed_holdings($co_mfhd->field('853'));
45 is(@decomp_holdings, 0, "Decompressed holdings for an MFHD record that only has a caption");
46
47 my $apostring = OpenILS::Utils::Normalize::naco_normalize("it's time");
48 is($apostring, "its time", "naco_normalize: strip apostrophes");
49
50 my $apos = OpenILS::Utils::Normalize::search_normalize("it's time");
51 is($apos, "it s time", "search_normalize: replace apostrophes with space");
52
53 my $raw_marcxml = <<RAWMARC;
54 <?xml version="1.0" encoding="utf-8"?>
55 <record>
56   <leader>01614nmm a22003975u 4500</leader>
57   <controlfield tag="001">978-0-387-35767-6</controlfield>
58   <controlfield tag="003">Springer</controlfield>
59   <controlfield tag="005">20071022150035.8</controlfield>
60   <controlfield tag="007">cr nn 008mamaa</controlfield>
61   <controlfield tag="008">071022s2008    xx         j        eng d</controlfield>
62   <datafield tag="020" ind1=" " ind2=" ">
63     <subfield code="a">9780387685748</subfield>
64   </datafield>
65   <datafield tag="100" ind1="1" ind2=" ">
66     <subfield code="a">Neteler, Markus.</subfield>
67   </datafield>
68   <datafield tag="245" ind1="1" ind2="0">
69     <subfield code="a">Open Source GIS</subfield>
70     <subfield code="h">[electronic resource] :</subfield>
71     <subfield code="b">A GRASS GIS Approach /</subfield>
72     <subfield code="c">edited by Markus Neteler, Helena Mitasova.</subfield>
73   </datafield>
74   <datafield tag="250" ind1=" " ind2=" ">
75     <subfield code="a">Third Edition.</subfield>
76   </datafield>
77   <datafield tag="260" ind1=" " ind2=" ">
78     <subfield code="a">Boston, MA :</subfield>
79     <subfield code="b">Springer Science+Business Media, LLC,</subfield>
80     <subfield code="c">2008.</subfield>
81   </datafield>
82 </record>
83 RAWMARC
84 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>';
85 my $clean_xml = OpenILS::Utils::Normalize::clean_marc($raw_marcxml);
86 is($clean_xml, $exp_xml, "clean_marc: header and space normalization");
87
88 is(OpenILS::Application::AppUtils->entityize('èöçÇÈÀ'), '&#xE8;&#xF6;&#xE7;&#xC7;&#xC8;&#xC0;', 'entityize: diacritics NFC');
89 is(OpenILS::Application::AppUtils->entityize('èöçÇÈÀ', 'D'), 'e&#x300;o&#x308;c&#x327;C&#x327;E&#x300;A&#x300;', 'entityize: diacritics NFD');
90 is(OpenILS::Utils::Normalize::clean_marc('èöçÇÈÀ'), '&#xE8;&#xF6;&#xE7;&#xC7;&#xC8;&#xC0;', 'clean_marc: diacritics');
91
92 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'";
93
94 my $edi_msgs = OpenILS::Utils::EDIReader->new->read($edi_invoice);
95
96 is($edi_msgs->[0]->{message_type}, 'INVOIC', 'edi reader: message type');
97 is($edi_msgs->[0]->{purchase_order}, '24', 'edi reader: PO number');
98 is($edi_msgs->[1]->{invoice_ident}, '5TST084027', 'edi reader: invoice ident');
99 is(scalar(@{$edi_msgs->[1]->{lineitems}}), '2', 'edi reader: lineitem count');
100