From a082811973da3a60c37becd2735b87d1637ceebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joonas=20Kylm=C3=A4l=C3=A4?= Date: Thu, 18 Feb 2021 17:37:36 +0200 Subject: [PATCH] Bug 25690: Add SIP2 tests for checking out with holds This should cover whether checking out is allowed for all different hold states: Attached: - Waiting - In processing - Transfer Unattached: - Reserved To test: 1) prove t/db_dependent/SIP/Transaction.t => passes Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall --- t/db_dependent/SIP/Transaction.t | 73 +++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/SIP/Transaction.t b/t/db_dependent/SIP/Transaction.t index ee29265998..6439fe1944 100755 --- a/t/db_dependent/SIP/Transaction.t +++ b/t/db_dependent/SIP/Transaction.t @@ -4,7 +4,7 @@ # Current state is very rudimentary. Please help to extend it! use Modern::Perl; -use Test::More tests => 11; +use Test::More tests => 12; use Koha::Database; use t::lib::TestBuilder; @@ -367,6 +367,77 @@ subtest do_checkin => sub { }; }; +subtest do_checkout_with_holds => sub { + plan tests => 7; + + my $library = $builder->build_object( { class => 'Koha::Libraries' } ); + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { + branchcode => $library->branchcode, + } + } + ); + my $patron2 = $builder->build_object( + { + class => 'Koha::Patrons', + value => { + branchcode => $library->branchcode, + } + } + ); + + t::lib::Mocks::mock_userenv( + { branchcode => $library->branchcode, flags => 1 } ); + + my $item = $builder->build_sample_item( + { + library => $library->branchcode, + } + ); + + my $reserve = AddReserve( + { + branchcode => $library->branchcode, + borrowernumber => $patron2->borrowernumber, + biblionumber => $item->biblionumber, + } + ); + + my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber ); + my $sip_item = C4::SIP::ILS::Item->new( $item->barcode ); + my $co_transaction = C4::SIP::ILS::Transaction::Checkout->new(); + is( $co_transaction->patron($sip_patron), + $sip_patron, "Patron assigned to transaction" ); + is( $co_transaction->item($sip_item), + $sip_item, "Item assigned to transaction" ); + + # Test attached holds + ModReserveAffect( $item->itemnumber, $patron->borrowernumber, 0, $reserve ); # Mark waiting (W) + my $hold = Koha::Holds->find($reserve); + $co_transaction->do_checkout(); + is( $patron->checkouts->count, 0, 'Checkout was not done due to attached hold (W)'); + + $hold->set_transfer; + $co_transaction->do_checkout(); + is( $patron->checkouts->count, 0, 'Checkout was not done due to attached hold (T)'); + + $hold->set_processing; + $co_transaction->do_checkout(); + is( $patron->checkouts->count, 0, 'Checkout was not done due to attached hold (P)'); + + # Test non-attached holds + C4::Reserves::RevertWaitingStatus({ itemnumber => $hold->itemnumber }); + t::lib::Mocks::mock_preference('AllowItemsOnHoldCheckoutSIP', '0'); + $co_transaction->do_checkout(); + is( $patron->checkouts->count, 0, 'Checkout refused due to hold and AllowItemsOnHoldCheckoutSIP'); + + t::lib::Mocks::mock_preference('AllowItemsOnHoldCheckoutSIP', '1'); + $co_transaction->do_checkout(); + is( $patron->checkouts->count, 1, 'Checkout allowed due to hold and AllowItemsOnHoldCheckoutSIP'); +}; + subtest checkin_lost => sub { plan tests => 2; -- 2.24.1 (Apple Git-126)