Lines 35-40
use Koha::DateUtils;
Link Here
|
35 |
use Koha::Items; |
35 |
use Koha::Items; |
36 |
use Koha::Checkouts; |
36 |
use Koha::Checkouts; |
37 |
use Koha::Old::Checkouts; |
37 |
use Koha::Old::Checkouts; |
|
|
38 |
use Koha::Patrons; |
38 |
|
39 |
|
39 |
use C4::SIP::ILS; |
40 |
use C4::SIP::ILS; |
40 |
use C4::SIP::ILS::Patron; |
41 |
use C4::SIP::ILS::Patron; |
Lines 44-72
use C4::SIP::Sip::MsgType;
Link Here
|
44 |
|
45 |
|
45 |
use constant PATRON_PW => 'do_not_ever_use_this_one'; |
46 |
use constant PATRON_PW => 'do_not_ever_use_this_one'; |
46 |
|
47 |
|
47 |
our $fixed_length = { #length of fixed fields including response code |
|
|
48 |
( PATRON_STATUS_RESP ) => 37, |
49 |
( PATRON_INFO_RESP ) => 61, |
50 |
( CHECKIN_RESP ) => 24, |
51 |
}; |
52 |
|
53 |
our $schema = Koha::Database->new->schema; |
54 |
our $builder = t::lib::TestBuilder->new(); |
55 |
|
56 |
# COMMON: Some common stuff for all/most subtests |
57 |
our ( $response, $findpatron, $branchcode ); |
58 |
$branchcode = $builder->build({ source => 'Branch' })->{branchcode}; |
59 |
# mock write_msg (imported from Sip.pm into Message.pm) |
60 |
my $mockMsg = Test::MockModule->new( 'C4::SIP::Sip::MsgType' ); |
61 |
$mockMsg->mock( 'write_msg', sub { $response = $_[1]; } ); # save response |
62 |
# mock ils object |
63 |
our $mockILS = Test::MockObject->new; |
64 |
$mockILS->mock( 'check_inst_id', sub {} ); |
65 |
$mockILS->mock( 'institution_id', sub { $branchcode; } ); |
66 |
$mockILS->mock( 'find_patron', sub { $findpatron; } ); |
67 |
|
68 |
# START testing |
48 |
# START testing |
69 |
subtest 'Testing Patron Status Request V2' => sub { |
49 |
subtest 'Testing Patron Status Request V2' => sub { |
|
|
50 |
my $schema = Koha::Database->new->schema; |
70 |
$schema->storage->txn_begin; |
51 |
$schema->storage->txn_begin; |
71 |
plan tests => 13; |
52 |
plan tests => 13; |
72 |
$C4::SIP::Sip::protocol_version = 2; |
53 |
$C4::SIP::Sip::protocol_version = 2; |
Lines 75-80
subtest 'Testing Patron Status Request V2' => sub {
Link Here
|
75 |
}; |
56 |
}; |
76 |
|
57 |
|
77 |
subtest 'Testing Patron Info Request V2' => sub { |
58 |
subtest 'Testing Patron Info Request V2' => sub { |
|
|
59 |
my $schema = Koha::Database->new->schema; |
78 |
$schema->storage->txn_begin; |
60 |
$schema->storage->txn_begin; |
79 |
plan tests => 18; |
61 |
plan tests => 18; |
80 |
$C4::SIP::Sip::protocol_version = 2; |
62 |
$C4::SIP::Sip::protocol_version = 2; |
Lines 83-88
subtest 'Testing Patron Info Request V2' => sub {
Link Here
|
83 |
}; |
65 |
}; |
84 |
|
66 |
|
85 |
subtest 'Checkin V2' => sub { |
67 |
subtest 'Checkin V2' => sub { |
|
|
68 |
my $schema = Koha::Database->new->schema; |
86 |
$schema->storage->txn_begin; |
69 |
$schema->storage->txn_begin; |
87 |
plan tests => 21; |
70 |
plan tests => 21; |
88 |
$C4::SIP::Sip::protocol_version = 2; |
71 |
$C4::SIP::Sip::protocol_version = 2; |
Lines 95-100
subtest 'Checkin V2' => sub {
Link Here
|
95 |
# END of main code |
78 |
# END of main code |
96 |
|
79 |
|
97 |
sub test_request_patron_status_v2 { |
80 |
sub test_request_patron_status_v2 { |
|
|
81 |
my $builder = t::lib::TestBuilder->new(); |
82 |
my $branchcode = $builder->build({ source => 'Branch' })->{branchcode}; |
83 |
my ( $response, $findpatron ); |
84 |
my $mocks = create_mocks( \$response, \$findpatron, \$branchcode ); |
85 |
|
98 |
my $patron1 = $builder->build({ |
86 |
my $patron1 = $builder->build({ |
99 |
source => 'Borrower', |
87 |
source => 'Borrower', |
100 |
value => { |
88 |
value => { |
Lines 111-117
sub test_request_patron_status_v2 {
Link Here
|
111 |
FID_PATRON_PWD. PATRON_PW. '|'; |
99 |
FID_PATRON_PWD. PATRON_PW. '|'; |
112 |
my $msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 ); |
100 |
my $msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 ); |
113 |
|
101 |
|
114 |
my $server = { ils => $mockILS }; |
102 |
my $server = { ils => $mocks->{ils} }; |
115 |
undef $response; |
103 |
undef $response; |
116 |
$msg->handle_patron_status( $server ); |
104 |
$msg->handle_patron_status( $server ); |
117 |
|
105 |
|
Lines 150-156
sub test_request_patron_status_v2 {
Link Here
|
150 |
|
138 |
|
151 |
# Finally, we send a wrong card number and check AE, BL |
139 |
# Finally, we send a wrong card number and check AE, BL |
152 |
# This is done by removing the new patron first |
140 |
# This is done by removing the new patron first |
153 |
$schema->resultset('Borrower')->search({ cardnumber => $card1 })->delete; |
141 |
Koha::Patrons->search({ cardnumber => $card1 })->delete; |
154 |
undef $findpatron; |
142 |
undef $findpatron; |
155 |
$siprequest = PATRON_STATUS_REQ. 'engYYYYMMDDZZZZHHMMSS'. |
143 |
$siprequest = PATRON_STATUS_REQ. 'engYYYYMMDDZZZZHHMMSS'. |
156 |
FID_INST_ID. $branchcode. '|'. |
144 |
FID_INST_ID. $branchcode. '|'. |
Lines 166-171
sub test_request_patron_status_v2 {
Link Here
|
166 |
} |
154 |
} |
167 |
|
155 |
|
168 |
sub test_request_patron_info_v2 { |
156 |
sub test_request_patron_info_v2 { |
|
|
157 |
my $builder = t::lib::TestBuilder->new(); |
158 |
my $branchcode = $builder->build({ source => 'Branch' })->{branchcode}; |
159 |
my ( $response, $findpatron ); |
160 |
my $mocks = create_mocks( \$response, \$findpatron, \$branchcode ); |
161 |
|
169 |
my $patron2 = $builder->build({ |
162 |
my $patron2 = $builder->build({ |
170 |
source => 'Borrower', |
163 |
source => 'Borrower', |
171 |
value => { |
164 |
value => { |
Lines 181-187
sub test_request_patron_info_v2 {
Link Here
|
181 |
FID_PATRON_PWD. PATRON_PW. '|'; |
174 |
FID_PATRON_PWD. PATRON_PW. '|'; |
182 |
my $msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 ); |
175 |
my $msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 ); |
183 |
|
176 |
|
184 |
my $server = { ils => $mockILS }; |
177 |
my $server = { ils => $mocks->{ils} }; |
185 |
undef $response; |
178 |
undef $response; |
186 |
$msg->handle_patron_info( $server ); |
179 |
$msg->handle_patron_info( $server ); |
187 |
isnt( $response, undef, 'At least we got a response.' ); |
180 |
isnt( $response, undef, 'At least we got a response.' ); |
Lines 219-225
sub test_request_patron_info_v2 {
Link Here
|
219 |
check_field( $respcode, $response, FID_VALID_PATRON_PWD, 'Y', 'code CQ should be Y if empty AD allowed' ); |
212 |
check_field( $respcode, $response, FID_VALID_PATRON_PWD, 'Y', 'code CQ should be Y if empty AD allowed' ); |
220 |
|
213 |
|
221 |
# Finally, we send a wrong card number |
214 |
# Finally, we send a wrong card number |
222 |
$schema->resultset('Borrower')->search({ cardnumber => $card })->delete; |
215 |
Koha::Patrons->search({ cardnumber => $card })->delete; |
223 |
undef $findpatron; |
216 |
undef $findpatron; |
224 |
$msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 ); |
217 |
$msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 ); |
225 |
undef $response; |
218 |
undef $response; |
Lines 231-236
sub test_request_patron_info_v2 {
Link Here
|
231 |
} |
224 |
} |
232 |
|
225 |
|
233 |
sub test_checkin_v2 { |
226 |
sub test_checkin_v2 { |
|
|
227 |
my $builder = t::lib::TestBuilder->new(); |
228 |
my $branchcode = $builder->build({ source => 'Branch' })->{branchcode}; |
229 |
my ( $response, $findpatron ); |
230 |
my $mocks = create_mocks( \$response, \$findpatron, \$branchcode ); |
231 |
|
234 |
# create some data |
232 |
# create some data |
235 |
my $patron1 = $builder->build({ |
233 |
my $patron1 = $builder->build({ |
236 |
source => 'Borrower', |
234 |
source => 'Borrower', |
Lines 246-251
sub test_checkin_v2 {
Link Here
|
246 |
value => { damaged => 0, withdrawn => 0, itemlost => 0, restricted => 0, homebranch => $branchcode, holdingbranch => $branchcode }, |
244 |
value => { damaged => 0, withdrawn => 0, itemlost => 0, restricted => 0, homebranch => $branchcode, holdingbranch => $branchcode }, |
247 |
}); |
245 |
}); |
248 |
|
246 |
|
|
|
247 |
my $mockILS = $mocks->{ils}; |
249 |
my $server = { ils => $mockILS, account => {} }; |
248 |
my $server = { ils => $mockILS, account => {} }; |
250 |
$mockILS->mock( 'institution', sub { $branchcode; } ); |
249 |
$mockILS->mock( 'institution', sub { $branchcode; } ); |
251 |
$mockILS->mock( 'supports', sub { return; } ); |
250 |
$mockILS->mock( 'supports', sub { return; } ); |
Lines 333-344
sub test_checkin_v2 {
Link Here
|
333 |
|
332 |
|
334 |
# Helper routines |
333 |
# Helper routines |
335 |
|
334 |
|
|
|
335 |
sub create_mocks { |
336 |
my ( $response, $findpatron, $branchcode ) = @_; # referenced variables ! |
337 |
|
338 |
# mock write_msg (imported from Sip.pm into Message.pm) |
339 |
my $mockMsg = Test::MockModule->new( 'C4::SIP::Sip::MsgType' ); |
340 |
$mockMsg->mock( 'write_msg', sub { $$response = $_[1]; } ); # save response |
341 |
|
342 |
# mock ils object |
343 |
my $mockILS = Test::MockObject->new; |
344 |
$mockILS->mock( 'check_inst_id', sub {} ); |
345 |
$mockILS->mock( 'institution_id', sub { $$branchcode; } ); |
346 |
$mockILS->mock( 'find_patron', sub { $$findpatron; } ); |
347 |
|
348 |
return { ils => $mockILS, message => $mockMsg }; |
349 |
} |
350 |
|
336 |
sub check_field { |
351 |
sub check_field { |
337 |
my ( $code, $resp, $fld, $expr, $msg, $mode ) = @_; |
352 |
my ( $code, $resp, $fld, $expr, $msg, $mode ) = @_; |
338 |
# mode: contains || equals || regex (by default: equals) |
353 |
# mode: contains || equals || regex (by default: equals) |
339 |
|
354 |
|
340 |
# strip fixed part; prefix to simplify next regex |
355 |
# strip fixed part; prefix to simplify next regex |
341 |
$resp = '|'. substr( $resp, $fixed_length->{$code} ); |
356 |
$resp = '|'. substr( $resp, fixed_length( $code ) ); |
342 |
my $fldval; |
357 |
my $fldval; |
343 |
if( $resp =~ /\|$fld([^\|]*)\|/ ) { |
358 |
if( $resp =~ /\|$fld([^\|]*)\|/ ) { |
344 |
$fldval = $1; |
359 |
$fldval = $1; |
Lines 363-365
sub siprequestdate {
Link Here
|
363 |
my ( $dt ) = @_; |
378 |
my ( $dt ) = @_; |
364 |
return $dt->ymd('').(' 'x4).$dt->hms(''); |
379 |
return $dt->ymd('').(' 'x4).$dt->hms(''); |
365 |
} |
380 |
} |
366 |
- |
381 |
|
|
|
382 |
sub fixed_length { #length of fixed fields including response code |
383 |
return { |
384 |
( PATRON_STATUS_RESP ) => 37, |
385 |
( PATRON_INFO_RESP ) => 61, |
386 |
( CHECKIN_RESP ) => 24, |
387 |
}->{$_[0]}; |
388 |
} |