Bug 21316: Handle control fields in the ACQ frameworks
[koha.git] / t / Ediorder.t
blob50926a9127bbf943e3cd06c28c4b75f84970539f
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use FindBin qw( $Bin );
6 use Test::More tests => 8;
8 BEGIN { use_ok('Koha::Edifact::Order') }
11 # The following tests are for internal methods but they could
12 # error spectacularly so yest
13 # Check that quoting is done correctly
15 my $processed_text =
16 Koha::Edifact::Order::encode_text(q{string containing ?,',:,+});
18 cmp_ok(
19 $processed_text, 'eq',
20 q{string containing ??,?',?:,?+},
21 'Outgoing text correctly quoted'
24 # extend above test to test chunking in imd_segment
26 my $code = '010';
27 my $data_to_encode = $processed_text;
29 my @segs = Koha::Edifact::Order::imd_segment( $code, $data_to_encode );
31 my $testseg = "IMD+L+010+:::$processed_text";
32 $testseg .= q{'}; # add segment terminator
34 cmp_ok( $segs[0], 'eq', $testseg, 'IMD segment correctly formed' );
36 $data_to_encode = 'A' x 35;
37 $data_to_encode .= 'B' x 35;
38 $data_to_encode .= 'C' x 10;
40 @segs = Koha::Edifact::Order::imd_segment( $code, $data_to_encode );
42 cmp_ok(
43 $segs[0],
44 'eq',
45 q{IMD+L+010+:::AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA:BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB'},
46 'IMD segment correctly chunked'
48 cmp_ok( $segs[1], 'eq', q{IMD+L+010+:::CCCCCCCCCC'},
49 'IMD segment correctly split across segments' );
51 $data_to_encode .= '??';
53 # this used to cause an infinite loop
54 @segs = Koha::Edifact::Order::imd_segment( $code, $data_to_encode );
55 cmp_ok( $segs[1], 'eq', q{IMD+L+010+:::CCCCCCCCCC??'},
56 'IMD segment deals with quoted character at end' );
58 my $isbn = '3540556753';
59 my $ean = '9783540556756';
61 my $seg = Koha::Edifact::Order::additional_product_id($isbn);
62 cmp_ok( $seg, 'eq', q{PIA+5+3540556753:IB'},
63 'isbn correctly encoded in PIA segment' );
65 $seg = Koha::Edifact::Order::additional_product_id($ean);
66 cmp_ok( $seg, 'eq', q{PIA+5+9783540556756:EN'},
67 'ean correctly encoded in PIA segment' );