Lines 583-646
subtest 'test_allow_additional_materials_checkout' => sub {
Link Here
|
583 |
|
583 |
|
584 |
plan tests => 4; |
584 |
plan tests => 4; |
585 |
|
585 |
|
586 |
my $builder = t::lib::TestBuilder->new(); |
586 |
my $builder = t::lib::TestBuilder->new(); |
587 |
my $branchcode = $builder->build({ source => 'Branch' })->{branchcode}; |
587 |
my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; |
588 |
my $branchcode2 = $builder->build({ source => 'Branch' })->{branchcode}; |
588 |
my $branchcode2 = $builder->build( { source => 'Branch' } )->{branchcode}; |
589 |
my ( $response, $findpatron ); |
589 |
my ( $response, $findpatron ); |
590 |
my $mocks = create_mocks( \$response, \$findpatron, \$branchcode ); |
590 |
my $mocks = create_mocks( \$response, \$findpatron, \$branchcode ); |
591 |
|
591 |
|
592 |
# create some data |
592 |
# create some data |
593 |
my $patron1 = $builder->build({ |
593 |
my $patron1 = $builder->build( |
594 |
source => 'Borrower', |
594 |
{ |
595 |
value => { |
595 |
source => 'Borrower', |
596 |
password => hash_password( PATRON_PW ), |
596 |
value => { |
597 |
}, |
597 |
password => hash_password(PATRON_PW), |
598 |
}); |
598 |
}, |
599 |
my $card1 = $patron1->{cardnumber}; |
599 |
} |
600 |
my $sip_patron1 = C4::SIP::ILS::Patron->new( $card1 ); |
600 |
); |
|
|
601 |
my $card1 = $patron1->{cardnumber}; |
602 |
my $sip_patron1 = C4::SIP::ILS::Patron->new($card1); |
601 |
$findpatron = $sip_patron1; |
603 |
$findpatron = $sip_patron1; |
602 |
my $item_object = $builder->build_sample_item({ |
604 |
my $item_object = $builder->build_sample_item( |
603 |
damaged => 0, |
605 |
{ |
604 |
withdrawn => 0, |
606 |
damaged => 0, |
605 |
itemlost => 0, |
607 |
withdrawn => 0, |
606 |
restricted => 0, |
608 |
itemlost => 0, |
607 |
homebranch => $branchcode, |
609 |
restricted => 0, |
608 |
holdingbranch => $branchcode, |
610 |
homebranch => $branchcode, |
609 |
materials => "This is a materials note", |
611 |
holdingbranch => $branchcode, |
610 |
}); |
612 |
materials => "This is a materials note", |
|
|
613 |
} |
614 |
); |
611 |
|
615 |
|
612 |
my $mockILS = $mocks->{ils}; |
616 |
my $mockILS = $mocks->{ils}; |
613 |
my $server = { ils => $mockILS, account => {} }; |
617 |
my $server = { ils => $mockILS, account => {} }; |
614 |
$mockILS->mock( 'institution', sub { $branchcode; } ); |
618 |
$mockILS->mock( 'institution', sub { $branchcode; } ); |
615 |
$mockILS->mock( 'supports', sub { return; } ); |
619 |
$mockILS->mock( 'supports', sub { return; } ); |
616 |
$mockILS->mock( 'checkout', sub { |
620 |
$mockILS->mock( |
617 |
shift; |
621 |
'checkout', |
618 |
return C4::SIP::ILS->checkout(@_); |
622 |
sub { |
619 |
}); |
623 |
shift; |
|
|
624 |
return C4::SIP::ILS->checkout(@_); |
625 |
} |
626 |
); |
620 |
my $today = dt_from_string; |
627 |
my $today = dt_from_string; |
621 |
t::lib::Mocks::mock_userenv({ branchcode => $branchcode, flags => 1 }); |
628 |
t::lib::Mocks::mock_userenv( { branchcode => $branchcode, flags => 1 } ); |
622 |
t::lib::Mocks::mock_preference( 'CircConfirmItemParts', '1' ); |
629 |
t::lib::Mocks::mock_preference( 'CircConfirmItemParts', '1' ); |
623 |
|
630 |
|
624 |
my $siprequest = CHECKOUT . 'YN' . siprequestdate($today) . |
631 |
my $siprequest = |
625 |
siprequestdate( $today->clone->add( days => 1) ) . |
632 |
CHECKOUT . 'YN' |
626 |
FID_INST_ID . $branchcode . '|'. |
633 |
. siprequestdate($today) |
627 |
FID_PATRON_ID . $sip_patron1->id . '|' . |
634 |
. siprequestdate( $today->clone->add( days => 1 ) ) |
628 |
FID_ITEM_ID . $item_object->barcode . '|' . |
635 |
. FID_INST_ID |
629 |
FID_TERMINAL_PWD . 'ignored' . '|'; |
636 |
. $branchcode . '|' |
|
|
637 |
. FID_PATRON_ID |
638 |
. $sip_patron1->id . '|' |
639 |
. FID_ITEM_ID |
640 |
. $item_object->barcode . '|' |
641 |
. FID_TERMINAL_PWD |
642 |
. 'ignored' . '|'; |
630 |
undef $response; |
643 |
undef $response; |
631 |
|
644 |
|
632 |
my $msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 ); |
645 |
my $msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 ); |
633 |
$server->{account}->{allow_additional_materials_checkout} = 0; |
646 |
$server->{account}->{allow_additional_materials_checkout} = 0; |
634 |
$msg->handle_checkout( $server ); |
647 |
$msg->handle_checkout($server); |
635 |
my $respcode = substr( $response, 0, 2 ); |
648 |
my $respcode = substr( $response, 0, 2 ); |
636 |
check_field( $respcode, $response, FID_SCREEN_MSG, 'Item must be checked out at a circulation desk', 'Check screen msg', 'equals' ); |
649 |
check_field( |
637 |
is( Koha::Checkouts->search({ itemnumber => $item_object->id })->count, 0, "Item was not checked out (allow_additional_materials_checkout disabled)"); |
650 |
$respcode, $response, FID_SCREEN_MSG, 'Item must be checked out at a circulation desk', |
|
|
651 |
'Check screen msg', 'equals' |
652 |
); |
653 |
is( |
654 |
Koha::Checkouts->search( { itemnumber => $item_object->id } )->count, 0, |
655 |
"Item was not checked out (allow_additional_materials_checkout disabled)" |
656 |
); |
638 |
|
657 |
|
639 |
$server->{account}->{allow_additional_materials_checkout} = 1; |
658 |
$server->{account}->{allow_additional_materials_checkout} = 1; |
640 |
$msg->handle_checkout( $server ); |
659 |
$msg->handle_checkout($server); |
641 |
$respcode = substr( $response, 0, 2 ); |
660 |
$respcode = substr( $response, 0, 2 ); |
642 |
check_field( $respcode, $response, FID_SCREEN_MSG, 'Item has additional materials: This is a materials note', 'Check screen msg', 'equals' ); |
661 |
check_field( |
643 |
is( Koha::Checkouts->search({ itemnumber => $item_object->id })->count, 1, "Item was checked out (allow_additional_materials_checkout enabled"); |
662 |
$respcode, $response, FID_SCREEN_MSG, 'Item has additional materials: This is a materials note', |
|
|
663 |
'Check screen msg', 'equals' |
664 |
); |
665 |
is( |
666 |
Koha::Checkouts->search( { itemnumber => $item_object->id } )->count, 1, |
667 |
"Item was checked out (allow_additional_materials_checkout enabled" |
668 |
); |
644 |
}; |
669 |
}; |
645 |
|
670 |
|
646 |
# Here is room for some more subtests |
671 |
# Here is room for some more subtests |
647 |
- |
|
|