Bug 16357: (QA follow-up) Only initialize Log4perl module
[koha.git] / t / Ediorder.t
blob30767a96716c1e3038d0ff09eb482b094bf07636
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use FindBin qw( $Bin );
6 use Test::More tests => 13;
8 BEGIN { use_ok('Koha::Edifact::Order') }
10 # The following tests are for internal methods but they could
11 # error spectacularly so best
12 # Check that quoting is done correctly
14 my $processed_text =
15 Koha::Edifact::Order::encode_text(q{string containing ?,',:,+});
17 cmp_ok(
18 $processed_text, 'eq',
19 q{string containing ??,?',?:,?+},
20 'Outgoing text correctly quoted'
23 # extend above test to test chunking in imd_segment
25 my $code = '010';
26 my $data_to_encode = $processed_text;
28 my @segs = Koha::Edifact::Order::imd_segment( $code, $data_to_encode );
30 my $testseg = "IMD+L+010+:::$processed_text";
31 $testseg .= q{'}; # add segment terminator
33 cmp_ok( $segs[0], 'eq', $testseg, 'IMD segment correctly formed' );
35 $data_to_encode = 'A' x 35;
36 $data_to_encode .= 'B' x 35;
37 $data_to_encode .= 'C' x 10;
39 @segs = Koha::Edifact::Order::imd_segment( $code, $data_to_encode );
41 cmp_ok(
42 $segs[0],
43 'eq',
44 q{IMD+L+010+:::AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA:BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB'},
45 'IMD segment correctly chunked'
47 cmp_ok( $segs[1], 'eq', q{IMD+L+010+:::CCCCCCCCCC'},
48 'IMD segment correctly split across segments' );
50 $data_to_encode .= '??';
52 # this used to cause an infinite loop
53 @segs = Koha::Edifact::Order::imd_segment( $code, $data_to_encode );
54 cmp_ok( $segs[1], 'eq', q{IMD+L+010+:::CCCCCCCCCC??'},
55 'IMD segment deals with quoted character at end' );
57 # special case for text ending in apostrophe e.g. nuthin'
58 $data_to_encode .= q{?'};
59 @segs = Koha::Edifact::Order::imd_segment( $code, $data_to_encode );
60 cmp_ok(
61 $segs[1], 'eq',
62 q{IMD+L+010+:::CCCCCCCCCC???''},
63 'IMD segment deals with quoted apostrophe at end'
66 $data_to_encode =~ s/\?'$//;
67 @segs = Koha::Edifact::Order::imd_segment( $code, $data_to_encode );
68 cmp_ok( $segs[1], 'eq', q{IMD+L+010+:::CCCCCCCCCC??'},
69 'IMD segment deals with apostrophe preceded by quoted ? at end' );
71 my $isbn = '3540556753';
72 my $ean = '9783540556756';
74 my $seg = Koha::Edifact::Order::additional_product_id($isbn);
75 cmp_ok( $seg, 'eq', q{PIA+5+3540556753:IB'},
76 'isbn correctly encoded in PIA segment' );
78 $seg = Koha::Edifact::Order::additional_product_id($ean);
79 cmp_ok( $seg, 'eq', q{PIA+5+9783540556756:EN'},
80 'ean correctly encoded in PIA segment' );
82 my $orderfields = { budget_code => 'BUDGET', };
83 my @items = (
85 itype => 'TYPE',
86 location => 'LOCATION',
87 itemcallnumber => 'CALL',
88 branchcode => 'BRANCH',
91 itype => 'TYPE',
92 location => 'LOCATION',
93 itemcallnumber => 'CALL',
94 branchcode => 'BRANCH',
98 my @gsegs = Koha::Edifact::Order::gir_segments(
100 ol_fields => $orderfields,
101 items => \@items
104 cmp_ok(
105 $gsegs[0], 'eq',
106 q{GIR+001+BUDGET:LFN+BRANCH:LLO+TYPE:LST+LOCATION:LSQ+CALL:LSM},
107 'Single Gir field OK'
110 $orderfields->{servicing_instruction} = 'S_I';
111 @gsegs = Koha::Edifact::Order::gir_segments(
113 ol_fields => $orderfields,
114 items => \@items
117 cmp_ok(
118 $gsegs[2], 'eq',
119 q{GIR+002+BUDGET:LFN+BRANCH:LLO+TYPE:LST+LOCATION:LSQ+CALL:LSM},
120 'First part of split Gir field OK'
123 cmp_ok( $gsegs[3], 'eq', q{GIR+002+S_I:LVT},
124 'Second part of split GIR field OK' );