|
Lines 21-27
Link Here
|
| 21 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
21 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 22 |
|
22 |
|
| 23 |
use Modern::Perl; |
23 |
use Modern::Perl; |
| 24 |
use Test::More tests => 9; |
24 |
use Test::More tests => 10; |
| 25 |
use Test::MockObject; |
25 |
use Test::MockObject; |
| 26 |
use Test::MockModule; |
26 |
use Test::MockModule; |
| 27 |
use Test::Warn; |
27 |
use Test::Warn; |
|
Lines 30-35
use t::lib::Mocks;
Link Here
|
| 30 |
use t::lib::TestBuilder; |
30 |
use t::lib::TestBuilder; |
| 31 |
|
31 |
|
| 32 |
use C4::Reserves qw(AddReserve); |
32 |
use C4::Reserves qw(AddReserve); |
|
|
33 |
use C4::Circulation qw( AddReturn ); |
| 33 |
use Koha::Database; |
34 |
use Koha::Database; |
| 34 |
use Koha::AuthUtils qw(hash_password); |
35 |
use Koha::AuthUtils qw(hash_password); |
| 35 |
use Koha::DateUtils; |
36 |
use Koha::DateUtils; |
|
Lines 66-71
subtest 'Testing Patron Info Request V2' => sub {
Link Here
|
| 66 |
$schema->storage->txn_rollback; |
67 |
$schema->storage->txn_rollback; |
| 67 |
}; |
68 |
}; |
| 68 |
|
69 |
|
|
|
70 |
subtest 'Checkout V2' => sub { |
| 71 |
my $schema = Koha::Database->new->schema; |
| 72 |
$schema->storage->txn_begin; |
| 73 |
plan tests => 3; |
| 74 |
$C4::SIP::Sip::protocol_version = 2; |
| 75 |
test_checkout_v2(); |
| 76 |
$schema->storage->txn_rollback; |
| 77 |
}; |
| 78 |
|
| 69 |
subtest 'Checkin V2' => sub { |
79 |
subtest 'Checkin V2' => sub { |
| 70 |
my $schema = Koha::Database->new->schema; |
80 |
my $schema = Koha::Database->new->schema; |
| 71 |
$schema->storage->txn_begin; |
81 |
$schema->storage->txn_begin; |
|
Lines 486-491
sub test_request_patron_info_v2 {
Link Here
|
| 486 |
check_field( $respcode, $response, FID_SCREEN_MSG, '.+', 'But we have a screen msg', 'regex' ); |
496 |
check_field( $respcode, $response, FID_SCREEN_MSG, '.+', 'But we have a screen msg', 'regex' ); |
| 487 |
} |
497 |
} |
| 488 |
|
498 |
|
|
|
499 |
sub test_checkout_v2 { |
| 500 |
my $builder = t::lib::TestBuilder->new(); |
| 501 |
my $branchcode = $builder->build({ source => 'Branch' })->{branchcode}; |
| 502 |
my $branchcode2 = $builder->build({ source => 'Branch' })->{branchcode}; |
| 503 |
my ( $response, $findpatron ); |
| 504 |
my $mocks = create_mocks( \$response, \$findpatron, \$branchcode ); |
| 505 |
|
| 506 |
# create some data |
| 507 |
my $patron1 = $builder->build({ |
| 508 |
source => 'Borrower', |
| 509 |
value => { |
| 510 |
password => hash_password( PATRON_PW ), |
| 511 |
}, |
| 512 |
}); |
| 513 |
my $card1 = $patron1->{cardnumber}; |
| 514 |
my $sip_patron1 = C4::SIP::ILS::Patron->new( $card1 ); |
| 515 |
$findpatron = $sip_patron1; |
| 516 |
my $item_object = $builder->build_sample_item({ |
| 517 |
damaged => 0, |
| 518 |
withdrawn => 0, |
| 519 |
itemlost => 0, |
| 520 |
restricted => 0, |
| 521 |
homebranch => $branchcode, |
| 522 |
holdingbranch => $branchcode, |
| 523 |
}); |
| 524 |
|
| 525 |
my $mockILS = $mocks->{ils}; |
| 526 |
my $server = { ils => $mockILS, account => {} }; |
| 527 |
$mockILS->mock( 'institution', sub { $branchcode; } ); |
| 528 |
$mockILS->mock( 'supports', sub { return; } ); |
| 529 |
$mockILS->mock( 'checkout', sub { |
| 530 |
shift; |
| 531 |
return C4::SIP::ILS->checkout(@_); |
| 532 |
}); |
| 533 |
my $today = dt_from_string; |
| 534 |
t::lib::Mocks::mock_userenv({ branchcode => $branchcode, flags => 1 }); |
| 535 |
t::lib::Mocks::mock_preference( 'CheckPrevCheckout', 'hardyes' ); |
| 536 |
|
| 537 |
my $issue = Koha::Checkout->new({ branchcode => $branchcode, borrowernumber => $patron1->{borrowernumber}, itemnumber => $item_object->itemnumber })->store; |
| 538 |
my $return = AddReturn($item_object->barcode, $branchcode); |
| 539 |
|
| 540 |
my $siprequest = CHECKOUT . 'YN' . siprequestdate($today) . |
| 541 |
siprequestdate( $today->clone->add( days => 1) ) . |
| 542 |
FID_INST_ID . $branchcode . '|'. |
| 543 |
FID_PATRON_ID . $sip_patron1->id . '|' . |
| 544 |
FID_ITEM_ID . $item_object->barcode . '|' . |
| 545 |
FID_TERMINAL_PWD . 'ignored' . '|'; |
| 546 |
undef $response; |
| 547 |
|
| 548 |
my $msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 ); |
| 549 |
$server->{account}->{prevcheckout_block_checkout} = 1; |
| 550 |
$msg->handle_checkout( $server ); |
| 551 |
my $respcode = substr( $response, 0, 2 ); |
| 552 |
check_field( $respcode, $response, FID_SCREEN_MSG, 'This item was previously checked out by you', 'Check screen msg', 'equals' ); |
| 553 |
|
| 554 |
is( Koha::Checkouts->search({ itemnumber => $item_object->id })->count, 0, "Item was not checked out (prevcheckout_block_checkout enabled)"); |
| 555 |
|
| 556 |
$server->{account}->{prevcheckout_block_checkout} = 0; |
| 557 |
$msg->handle_checkout( $server ); |
| 558 |
$respcode = substr( $response, 0, 2 ); |
| 559 |
is( Koha::Checkouts->search({ itemnumber => $item_object->id })->count, 1, "Item was checked out (prevcheckout_block_checkout disabled)"); |
| 560 |
} |
| 561 |
|
| 489 |
sub test_checkin_v2 { |
562 |
sub test_checkin_v2 { |
| 490 |
my $builder = t::lib::TestBuilder->new(); |
563 |
my $builder = t::lib::TestBuilder->new(); |
| 491 |
my $branchcode = $builder->build({ source => 'Branch' })->{branchcode}; |
564 |
my $branchcode = $builder->build({ source => 'Branch' })->{branchcode}; |
|
Lines 756-760
sub fixed_length { #length of fixed fields including response code
Link Here
|
| 756 |
( PATRON_STATUS_RESP ) => 37, |
829 |
( PATRON_STATUS_RESP ) => 37, |
| 757 |
( PATRON_INFO_RESP ) => 61, |
830 |
( PATRON_INFO_RESP ) => 61, |
| 758 |
( CHECKIN_RESP ) => 24, |
831 |
( CHECKIN_RESP ) => 24, |
|
|
832 |
( CHECKOUT_RESP ) => 24, |
| 759 |
}->{$_[0]}; |
833 |
}->{$_[0]}; |
| 760 |
} |
834 |
} |
| 761 |
- |
|
|