Koha/t/Ediorder.t
Colin Campbell 0c4112a200
Bug 23251: Correct formatting of IMD data ending in apostrophe
IMD text data may end in an apostrophe (e.g. dreamin' )
This was causing the segment to be incorrectly formatted
as only the last character was checked, not the preceding
character to check whether it was quoted

add a test for this specific occurence

Signed-off-by: Hayley Mapley <hayleymapley@catalyst.net.nz>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
2019-07-26 16:23:03 +01:00

78 lines
2.3 KiB
Perl
Executable file

#!/usr/bin/perl
use strict;
use warnings;
use FindBin qw( $Bin );
use Test::More tests => 10;
BEGIN { use_ok('Koha::Edifact::Order') }
# The following tests are for internal methods but they could
# error spectacularly so yest
# Check that quoting is done correctly
#
my $processed_text =
Koha::Edifact::Order::encode_text(q{string containing ?,',:,+});
cmp_ok(
$processed_text, 'eq',
q{string containing ??,?',?:,?+},
'Outgoing text correctly quoted'
);
# extend above test to test chunking in imd_segment
#
my $code = '010';
my $data_to_encode = $processed_text;
my @segs = Koha::Edifact::Order::imd_segment( $code, $data_to_encode );
my $testseg = "IMD+L+010+:::$processed_text";
$testseg .= q{'}; # add segment terminator
cmp_ok( $segs[0], 'eq', $testseg, 'IMD segment correctly formed' );
$data_to_encode = 'A' x 35;
$data_to_encode .= 'B' x 35;
$data_to_encode .= 'C' x 10;
@segs = Koha::Edifact::Order::imd_segment( $code, $data_to_encode );
cmp_ok(
$segs[0],
'eq',
q{IMD+L+010+:::AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA:BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB'},
'IMD segment correctly chunked'
);
cmp_ok( $segs[1], 'eq', q{IMD+L+010+:::CCCCCCCCCC'},
'IMD segment correctly split across segments' );
$data_to_encode .= '??';
# this used to cause an infinite loop
@segs = Koha::Edifact::Order::imd_segment( $code, $data_to_encode );
cmp_ok( $segs[1], 'eq', q{IMD+L+010+:::CCCCCCCCCC??'},
'IMD segment deals with quoted character at end' );
# special case for text ending in apostrophe e.g. nuthin'
$data_to_encode .= q{?'};
@segs = Koha::Edifact::Order::imd_segment( $code, $data_to_encode );
cmp_ok( $segs[1], 'eq', q{IMD+L+010+:::CCCCCCCCCC???''},
'IMD segment deals with quoted apostrophe at end' );
$data_to_encode =~s/\?'$//;
@segs = Koha::Edifact::Order::imd_segment( $code, $data_to_encode );
cmp_ok( $segs[1], 'eq', q{IMD+L+010+:::CCCCCCCCCC??'},
'IMD segment deals with apostrophe preceded by quoted ? at end' );
my $isbn = '3540556753';
my $ean = '9783540556756';
my $seg = Koha::Edifact::Order::additional_product_id($isbn);
cmp_ok( $seg, 'eq', q{PIA+5+3540556753:IB'},
'isbn correctly encoded in PIA segment' );
$seg = Koha::Edifact::Order::additional_product_id($ean);
cmp_ok( $seg, 'eq', q{PIA+5+9783540556756:EN'},
'ean correctly encoded in PIA segment' );