#!perl # FIXME: unlike the rest of the test cases here, we're /not/ enabling # taint checks. The version of DateTime::TimeZone that ships with # Ubuntu 14.04 LTS (Trusty) has a bug where attempting to get the # local time zone can fail (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=737265). # # It's arguable whether taint checking should be enabled at all in # the test suite. On the one hand, it is recommended practice for # all code that accepts external input; on the other hand, a typical # Evergreen installation doesn't run anything setuid/setgid that # would automatically trigger taint-checking. Ideally we would # eat our Wheaties, but we may be looking at consuming an entire # truckload to verify that everything would continue to work if # we turn it on across the board. use Test::More tests => 47; use Test::Warn; use DateTime::TimeZone; use DateTime::Format::ISO8601; use utf8; use_ok( 'OpenILS::Utils::Configure' ); use_ok( 'OpenILS::Utils::Cronscript' ); use_ok( 'OpenILS::Utils::CStoreEditor' ); use_ok( 'OpenILS::Utils::Fieldmapper' ); use_ok( 'OpenILS::Utils::Lockfile' ); use_ok( 'OpenILS::Utils::MFHDParser' ); use_ok( 'OpenILS::Utils::MFHD' ); use_ok( 'OpenILS::Utils::ModsParser' ); use_ok( 'OpenILS::Utils::Normalize' ); use_ok( 'OpenILS::Utils::OfflineStore' ); use_ok( 'OpenILS::Utils::Penalty' ); use_ok( 'OpenILS::Utils::PermitHold' ); use_ok( 'OpenILS::Utils::RemoteAccount' ); use_ok( 'OpenILS::Utils::ZClient' ); use_ok( 'OpenILS::Utils::EDIReader' ); use_ok( 'OpenILS::Utils::HTTPClient' ); use_ok( 'OpenILS::Utils::DateTime' ); # LP 800269 - Test MFHD holdings for records that only contain a caption field my $co_marc = MARC::Record->new(); $co_marc->append_fields( MARC::Field->new('853','','', '8' => '1', 'a' => 'v.', 'b' => '[no.]', ) ); my $co_mfhd = MFHD->new($co_marc); my @comp_holdings; warning_like { @comp_holdings = $co_mfhd->get_compressed_holdings($co_mfhd->field('853')); } [ qr/Cannot compress without pattern data, returning original holdings/ ], "warning when attempting to compress holdings without a pattern"; is(@comp_holdings, 0, "Compressed holdings for an MFHD record that only has a caption"); my @decomp_holdings = $co_mfhd->get_decompressed_holdings($co_mfhd->field('853')); is(@decomp_holdings, 0, "Decompressed holdings for an MFHD record that only has a caption"); my $apostring = OpenILS::Utils::Normalize::naco_normalize("it's time"); is($apostring, "its time", "naco_normalize: strip apostrophes"); my $apos = OpenILS::Utils::Normalize::search_normalize("it's time"); is($apos, "it s time", "search_normalize: replace apostrophes with space"); my $raw_marcxml = < 01614nmm a22003975u 4500 978-0-387-35767-6 Springer 20071022150035.8 cr nn 008mamaa 071022s2008 xx j eng d 9780387685748 Neteler, Markus. Open Source GIS [electronic resource] : A GRASS GIS Approach / edited by Markus Neteler, Helena Mitasova. Third Edition. Boston, MA : Springer Science+Business Media, LLC, 2008. RAWMARC my $exp_xml = '01614nmm a22003975u 4500978-0-387-35767-6Springer20071022150035.8cr nn 008mamaa071022s2008 xx j eng d9780387685748Neteler, Markus.Open Source GIS[electronic resource] :A GRASS GIS Approach /edited by Markus Neteler, Helena Mitasova.Third Edition.Boston, MA :Springer Science+Business Media, LLC,2008.'; my $clean_xml = OpenILS::Utils::Normalize::clean_marc($raw_marcxml); is($clean_xml, $exp_xml, "clean_marc: header and space normalization"); is(OpenILS::Application::AppUtils->entityize('èöçÇÈÀ'), 'èöçÇÈÀ', 'entityize: diacritics NFC'); is(OpenILS::Application::AppUtils->entityize('èöçÇÈÀ', 'D'), 'èöçÇÈÀ', 'entityize: diacritics NFD'); is(OpenILS::Utils::Normalize::clean_marc('èöçÇÈÀ'), 'èöçÇÈÀ', 'clean_marc: diacritics'); 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'"; my $edi_msgs = OpenILS::Utils::EDIReader->new->read($edi_invoice); is($edi_msgs->[0]->{message_type}, 'INVOIC', 'edi reader: message type'); is($edi_msgs->[0]->{purchase_order}, '24', 'edi reader: PO number'); is($edi_msgs->[1]->{invoice_ident}, '5TST084027', 'edi reader: invoice ident'); is(scalar(@{$edi_msgs->[1]->{lineitems}}), '2', 'edi reader: lineitem count'); is (OpenILS::Utils::DateTime::interval_to_seconds('1 second'), 1); is (OpenILS::Utils::DateTime::interval_to_seconds('1 minute'), 60); is (OpenILS::Utils::DateTime::interval_to_seconds('1 hour'), 3600); is (OpenILS::Utils::DateTime::interval_to_seconds('1 day'), 86400); is (OpenILS::Utils::DateTime::interval_to_seconds('1 week'), 604800); is (OpenILS::Utils::DateTime::interval_to_seconds('1 month'), 2628000); # With context, no DST change, with timezone is (OpenILS::Utils::DateTime::interval_to_seconds('1 month', DateTime::Format::ISO8601->new->parse_datetime('2017-02-04T23:59:59-04')->set_time_zone("America/New_York")), 2419200); # With context, with DST change, with timezone is (OpenILS::Utils::DateTime::interval_to_seconds('1 month', DateTime::Format::ISO8601->new->parse_datetime('2017-02-14T23:59:59-04')->set_time_zone("America/New_York")), 2415600); # With context, no DST change, no time zone is (OpenILS::Utils::DateTime::interval_to_seconds('1 month', DateTime::Format::ISO8601->new->parse_datetime('2017-02-04T23:59:59-04')), 2419200); # With context, with DST change, no time zone (so, not DST-aware) is (OpenILS::Utils::DateTime::interval_to_seconds('1 month', DateTime::Format::ISO8601->new->parse_datetime('2017-02-14T23:59:59-04')), 2419200); is (OpenILS::Utils::DateTime::interval_to_seconds('1 year'), 31536000); is (OpenILS::Utils::DateTime::interval_to_seconds('1 year 1 second'), 31536001); is (OpenILS::Utils::DateTime::interval_to_seconds('167:59:59'), 604799, 'correctly convert HHH:MM:SS intervals where hours longer than 2 digits'); sub get_offset { # get current timezone offset for future use my $offset = DateTime::TimeZone::offset_as_string( DateTime::TimeZone->new( name => 'local' )->offset_for_datetime( DateTime::Format::ISO8601->new()->parse_datetime('2018-09-17') ) ); $offset =~ s/^(.\d\d)(\d\d)+/$1:$2/; return $offset; } is (OpenILS::Utils::DateTime::clean_ISO8601('20180917'), '2018-09-17T00:00:00', 'plain date converted to ISO8601 timestamp'); is (OpenILS::Utils::DateTime::clean_ISO8601('I am not a date'), 'I am not a date', 'non-date simply returned as is'); my $offset = get_offset(); is (OpenILS::Utils::DateTime::clean_ISO8601('20180917 08:31:15'), "2018-09-17T08:31:15$offset", 'time zone added to date/time'); # force timezone to specific value to avoid a spurious # pass if this test happens to be run in UTC $ENV{TZ} = 'EST'; is (OpenILS::Utils::DateTime::clean_ISO8601('2018-09-17T17:31:15Z'), "2018-09-17T17:31:15+00:00", 'interpret Z in timestamp correctly');