4 use FindBin qw( $Bin );
6 use Test::More tests => 13;
9 BEGIN { use_ok('Koha::Edifact::Order') }
10 t::lib::Mocks::mock_preference('EdifactLSQ', 'location');
12 # The following tests are for internal methods but they could
13 # error spectacularly so best
14 # Check that quoting is done correctly
17 Koha::Edifact::Order::encode_text(q{string containing ?,',:,+});
20 $processed_text, 'eq',
21 q{string containing ??,?',?:,?+},
22 'Outgoing text correctly quoted'
25 # extend above test to test chunking in imd_segment
28 my $data_to_encode = $processed_text;
30 my @segs = Koha::Edifact::Order::imd_segment( $code, $data_to_encode );
32 my $testseg = "IMD+L+010+:::$processed_text";
33 $testseg .= q{'}; # add segment terminator
35 cmp_ok( $segs[0], 'eq', $testseg, 'IMD segment correctly formed' );
37 $data_to_encode = 'A' x 35;
38 $data_to_encode .= 'B' x 35;
39 $data_to_encode .= 'C' x 10;
41 @segs = Koha::Edifact::Order::imd_segment( $code, $data_to_encode );
46 q{IMD+L+010+:::AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA:BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB'},
47 'IMD segment correctly chunked'
49 cmp_ok( $segs[1], 'eq', q{IMD+L+010+:::CCCCCCCCCC'},
50 'IMD segment correctly split across segments' );
52 $data_to_encode .= '??';
54 # this used to cause an infinite loop
55 @segs = Koha::Edifact::Order::imd_segment( $code, $data_to_encode );
56 cmp_ok( $segs[1], 'eq', q{IMD+L+010+:::CCCCCCCCCC??'},
57 'IMD segment deals with quoted character at end' );
59 # special case for text ending in apostrophe e.g. nuthin'
60 $data_to_encode .= q{?'};
61 @segs = Koha::Edifact::Order::imd_segment( $code, $data_to_encode );
64 q{IMD+L+010+:::CCCCCCCCCC???''},
65 'IMD segment deals with quoted apostrophe at end'
68 $data_to_encode =~ s/\?'$//;
69 @segs = Koha::Edifact::Order::imd_segment( $code, $data_to_encode );
70 cmp_ok( $segs[1], 'eq', q{IMD+L+010+:::CCCCCCCCCC??'},
71 'IMD segment deals with apostrophe preceded by quoted ? at end' );
73 my $isbn = '3540556753';
74 my $ean = '9783540556756';
76 my $seg = Koha::Edifact::Order::additional_product_id($isbn);
77 cmp_ok( $seg, 'eq', q{PIA+5+3540556753:IB'},
78 'isbn correctly encoded in PIA segment' );
80 $seg = Koha::Edifact::Order::additional_product_id($ean);
81 cmp_ok( $seg, 'eq', q{PIA+5+9783540556756:EN'},
82 'ean correctly encoded in PIA segment' );
84 my $orderfields = { budget_code => 'BUDGET', };
88 location => 'LOCATION',
89 itemcallnumber => 'CALL',
90 branchcode => 'BRANCH',
94 location => 'LOCATION',
95 itemcallnumber => 'CALL',
96 branchcode => 'BRANCH',
100 my @gsegs = Koha::Edifact::Order::gir_segments(
102 ol_fields => $orderfields,
108 q{GIR+001+BUDGET:LFN+BRANCH:LLO+TYPE:LST+LOCATION:LSQ+CALL:LSM},
109 'Single Gir field OK'
112 $orderfields->{servicing_instruction} = 'S_I';
113 @gsegs = Koha::Edifact::Order::gir_segments(
115 ol_fields => $orderfields,
121 q{GIR+002+BUDGET:LFN+BRANCH:LLO+TYPE:LST+LOCATION:LSQ+CALL:LSM},
122 'First part of split Gir field OK'
125 cmp_ok( $gsegs[3], 'eq', q{GIR+002+S_I:LVT},
126 'Second part of split GIR field OK' );