|
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 228-234
sub test_request_patron_info_v2 {
Link Here
|
| 228 |
check_field( $respcode, $response, FID_VALID_PATRON_PWD, 'Y', 'code CQ should be Y if empty AD allowed' ); |
221 |
check_field( $respcode, $response, FID_VALID_PATRON_PWD, 'Y', 'code CQ should be Y if empty AD allowed' ); |
| 229 |
|
222 |
|
| 230 |
# Finally, we send a wrong card number |
223 |
# Finally, we send a wrong card number |
| 231 |
$schema->resultset('Borrower')->search({ cardnumber => $card })->delete; |
224 |
Koha::Patrons->search({ cardnumber => $card })->delete; |
| 232 |
undef $findpatron; |
225 |
undef $findpatron; |
| 233 |
$msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 ); |
226 |
$msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 ); |
| 234 |
undef $response; |
227 |
undef $response; |
|
Lines 240-245
sub test_request_patron_info_v2 {
Link Here
|
| 240 |
} |
233 |
} |
| 241 |
|
234 |
|
| 242 |
sub test_checkin_v2 { |
235 |
sub test_checkin_v2 { |
|
|
236 |
my $builder = t::lib::TestBuilder->new(); |
| 237 |
my $branchcode = $builder->build({ source => 'Branch' })->{branchcode}; |
| 238 |
my ( $response, $findpatron ); |
| 239 |
my $mocks = create_mocks( \$response, \$findpatron, \$branchcode ); |
| 240 |
|
| 243 |
# create some data |
241 |
# create some data |
| 244 |
my $patron1 = $builder->build({ |
242 |
my $patron1 = $builder->build({ |
| 245 |
source => 'Borrower', |
243 |
source => 'Borrower', |
|
Lines 255-260
sub test_checkin_v2 {
Link Here
|
| 255 |
value => { damaged => 0, withdrawn => 0, itemlost => 0, restricted => 0, homebranch => $branchcode, holdingbranch => $branchcode }, |
253 |
value => { damaged => 0, withdrawn => 0, itemlost => 0, restricted => 0, homebranch => $branchcode, holdingbranch => $branchcode }, |
| 256 |
}); |
254 |
}); |
| 257 |
|
255 |
|
|
|
256 |
my $mockILS = $mocks->{ils}; |
| 258 |
my $server = { ils => $mockILS, account => {} }; |
257 |
my $server = { ils => $mockILS, account => {} }; |
| 259 |
$mockILS->mock( 'institution', sub { $branchcode; } ); |
258 |
$mockILS->mock( 'institution', sub { $branchcode; } ); |
| 260 |
$mockILS->mock( 'supports', sub { return; } ); |
259 |
$mockILS->mock( 'supports', sub { return; } ); |
|
Lines 342-353
sub test_checkin_v2 {
Link Here
|
| 342 |
|
341 |
|
| 343 |
# Helper routines |
342 |
# Helper routines |
| 344 |
|
343 |
|
|
|
344 |
sub create_mocks { |
| 345 |
my ( $response, $findpatron, $branchcode ) = @_; # referenced variables ! |
| 346 |
|
| 347 |
# mock write_msg (imported from Sip.pm into Message.pm) |
| 348 |
my $mockMsg = Test::MockModule->new( 'C4::SIP::Sip::MsgType' ); |
| 349 |
$mockMsg->mock( 'write_msg', sub { $$response = $_[1]; } ); # save response |
| 350 |
|
| 351 |
# mock ils object |
| 352 |
my $mockILS = Test::MockObject->new; |
| 353 |
$mockILS->mock( 'check_inst_id', sub {} ); |
| 354 |
$mockILS->mock( 'institution_id', sub { $$branchcode; } ); |
| 355 |
$mockILS->mock( 'find_patron', sub { $$findpatron; } ); |
| 356 |
|
| 357 |
return { ils => $mockILS, message => $mockMsg }; |
| 358 |
} |
| 359 |
|
| 345 |
sub check_field { |
360 |
sub check_field { |
| 346 |
my ( $code, $resp, $fld, $expr, $msg, $mode ) = @_; |
361 |
my ( $code, $resp, $fld, $expr, $msg, $mode ) = @_; |
| 347 |
# mode: contains || equals || regex (by default: equals) |
362 |
# mode: contains || equals || regex (by default: equals) |
| 348 |
|
363 |
|
| 349 |
# strip fixed part; prefix to simplify next regex |
364 |
# strip fixed part; prefix to simplify next regex |
| 350 |
$resp = '|'. substr( $resp, $fixed_length->{$code} ); |
365 |
$resp = '|'. substr( $resp, fixed_length( $code ) ); |
| 351 |
my $fldval; |
366 |
my $fldval; |
| 352 |
if( $resp =~ /\|$fld([^\|]*)\|/ ) { |
367 |
if( $resp =~ /\|$fld([^\|]*)\|/ ) { |
| 353 |
$fldval = $1; |
368 |
$fldval = $1; |
|
Lines 372-374
sub siprequestdate {
Link Here
|
| 372 |
my ( $dt ) = @_; |
387 |
my ( $dt ) = @_; |
| 373 |
return $dt->ymd('').(' 'x4).$dt->hms(''); |
388 |
return $dt->ymd('').(' 'x4).$dt->hms(''); |
| 374 |
} |
389 |
} |
| 375 |
- |
390 |
|
|
|
391 |
sub fixed_length { #length of fixed fields including response code |
| 392 |
return { |
| 393 |
( PATRON_STATUS_RESP ) => 37, |
| 394 |
( PATRON_INFO_RESP ) => 61, |
| 395 |
( CHECKIN_RESP ) => 24, |
| 396 |
}->{$_[0]}; |
| 397 |
} |