forked from Koha-Community/Koha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEdiorder.t
executable file
·126 lines (104 loc) · 3.4 KB
/
Ediorder.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/perl
use strict;
use warnings;
use FindBin qw( $Bin );
use Test::More tests => 13;
use t::lib::Mocks;
BEGIN { use_ok('Koha::Edifact::Order') }
t::lib::Mocks::mock_preference('EdifactLSQ', 'location');
# The following tests are for internal methods but they could
# error spectacularly so best
# 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' );
my $orderfields = { budget_code => 'BUDGET', };
my @items = (
{
itype => 'TYPE',
location => 'LOCATION',
itemcallnumber => 'CALL',
branchcode => 'BRANCH',
},
{
itype => 'TYPE',
location => 'LOCATION',
itemcallnumber => 'CALL',
branchcode => 'BRANCH',
}
);
my @gsegs = Koha::Edifact::Order::gir_segments(
{
ol_fields => $orderfields,
items => \@items
}
);
cmp_ok(
$gsegs[0], 'eq',
q{GIR+001+BUDGET:LFN+BRANCH:LLO+TYPE:LST+LOCATION:LSQ+CALL:LSM},
'Single Gir field OK'
);
$orderfields->{servicing_instruction} = 'S_I';
@gsegs = Koha::Edifact::Order::gir_segments(
{
ol_fields => $orderfields,
items => \@items
}
);
cmp_ok(
$gsegs[2], 'eq',
q{GIR+002+BUDGET:LFN+BRANCH:LLO+TYPE:LST+LOCATION:LSQ+CALL:LSM},
'First part of split Gir field OK'
);
cmp_ok( $gsegs[3], 'eq', q{GIR+002+S_I:LVT},
'Second part of split GIR field OK' );