From 24628993dbdc0e4f3744cd1ce700a88969e78704 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 20 Sep 2023 08:47:48 +0200 Subject: [PATCH] Bug 34153: Add tests Signed-off-by: Victor Grousset/tuxayo --- t/db_dependent/SIP/Message.t | 68 +++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/SIP/Message.t b/t/db_dependent/SIP/Message.t index a45552ee52..f0747b08f4 100755 --- a/t/db_dependent/SIP/Message.t +++ b/t/db_dependent/SIP/Message.t @@ -21,7 +21,7 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 16; +use Test::More tests => 17; use Test::Exception; use Test::MockObject; use Test::MockModule; @@ -593,6 +593,72 @@ subtest 'SC status tests' => sub { $schema->storage->txn_rollback; }; +subtest 'test_allow_additional_materials_checkout' => sub { + my $schema = Koha::Database->new->schema; + $schema->storage->txn_begin; + + plan tests => 4; + + my $builder = t::lib::TestBuilder->new(); + my $branchcode = $builder->build({ source => 'Branch' })->{branchcode}; + my $branchcode2 = $builder->build({ source => 'Branch' })->{branchcode}; + my ( $response, $findpatron ); + my $mocks = create_mocks( \$response, \$findpatron, \$branchcode ); + + # create some data + my $patron1 = $builder->build({ + source => 'Borrower', + value => { + password => hash_password( PATRON_PW ), + }, + }); + my $card1 = $patron1->{cardnumber}; + my $sip_patron1 = C4::SIP::ILS::Patron->new( $card1 ); + $findpatron = $sip_patron1; + my $item_object = $builder->build_sample_item({ + damaged => 0, + withdrawn => 0, + itemlost => 0, + restricted => 0, + homebranch => $branchcode, + holdingbranch => $branchcode, + materials => "This is a materials note", + }); + + my $mockILS = $mocks->{ils}; + my $server = { ils => $mockILS, account => {} }; + $mockILS->mock( 'institution', sub { $branchcode; } ); + $mockILS->mock( 'supports', sub { return; } ); + $mockILS->mock( 'checkout', sub { + shift; + return C4::SIP::ILS->checkout(@_); + }); + my $today = dt_from_string; + t::lib::Mocks::mock_userenv({ branchcode => $branchcode, flags => 1 }); + t::lib::Mocks::mock_preference( 'CircConfirmItemParts', '1' ); + + my $siprequest = CHECKOUT . 'YN' . siprequestdate($today) . + siprequestdate( $today->clone->add( days => 1) ) . + FID_INST_ID . $branchcode . '|'. + FID_PATRON_ID . $sip_patron1->id . '|' . + FID_ITEM_ID . $item_object->barcode . '|' . + FID_TERMINAL_PWD . 'ignored' . '|'; + undef $response; + + my $msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 ); + $server->{account}->{allow_additional_materials_checkout} = 0; + $msg->handle_checkout( $server ); + my $respcode = substr( $response, 0, 2 ); + check_field( $respcode, $response, FID_SCREEN_MSG, 'Item must be checked out at a circulation desk', 'Check screen msg', 'equals' ); + is( Koha::Checkouts->search({ itemnumber => $item_object->id })->count, 0, "Item was not checked out (allow_additional_materials_checkout disabled)"); + + $server->{account}->{allow_additional_materials_checkout} = 1; + $msg->handle_checkout( $server ); + $respcode = substr( $response, 0, 2 ); + check_field( $respcode, $response, FID_SCREEN_MSG, 'Item has additional materials: This is a materials note', 'Check screen msg', 'equals' ); + is( Koha::Checkouts->search({ itemnumber => $item_object->id })->count, 1, "Item was checked out (allow_additional_materials_checkout enabled"); +}; + # Here is room for some more subtests # END of main code -- 2.42.0