From be2bd4379fa3e06cca06d4e100958d4665b3f860 Mon Sep 17 00:00:00 2001 From: Baptiste Date: Mon, 9 Dec 2024 14:59:14 +0100 Subject: [PATCH] Bug 35292: Update tests for UpdateNotForloanStatusOnCheckout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Note: These patches have been split for sake of understandability for review but they should probably be squashe Signed-off-by: Emmanuel Bétemps --- t/db_dependent/Circulation/issue.t | 114 ++++++++++++++++++++--------- 1 file changed, 80 insertions(+), 34 deletions(-) diff --git a/t/db_dependent/Circulation/issue.t b/t/db_dependent/Circulation/issue.t index 7352505a3b..3330789276 100755 --- a/t/db_dependent/Circulation/issue.t +++ b/t/db_dependent/Circulation/issue.t @@ -18,7 +18,7 @@ use Modern::Perl; use Test::NoWarnings; -use Test::More tests => 68; +use Test::More tests => 66; use DateTime::Duration; use t::lib::Mocks; @@ -519,40 +519,86 @@ is( # ############################################## -my $itemnumber4 = Koha::Item->new( - { - biblionumber => $biblionumber, - barcode => 'barcode_6', - itemcallnumber => 'callnumber6', - homebranch => $branchcode_1, - holdingbranch => $branchcode_1, - notforloan => -1, - itype => $itemtype, - location => 'loc1' - }, -)->store->itemnumber; - -t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckout', q{} ); -AddIssue( $patron_2, 'barcode_6', dt_from_string ); -$item = Koha::Items->find($itemnumber4); -ok( $item->notforloan eq -1, 'UpdateNotForLoanStatusOnCheckout does not modify value when not enabled' ); +subtest 'AddReturn: Update notforloanstatus according to UpdateNotForLoanStatusOnCheckout' => sub { + plan tests => 5; -t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckout', '-1: 0' ); -AddReturn( 'barcode_6', $branchcode_1 ); -my $test = AddIssue( $patron_2, 'barcode_6', dt_from_string ); -$item = Koha::Items->find($itemnumber4); -ok( - $item->notforloan eq 0, - q{UpdateNotForLoanStatusOnCheckout updates notforloan value from -1 to 0 with setting "-1: 0"} -); - -AddIssue( $patron_2, 'barcode_6', dt_from_string ); -AddReturn( 'barcode_6', $branchcode_1 ); -$item = Koha::Items->find($itemnumber4); -ok( - $item->notforloan eq 0, - q{UpdateNotForLoanStatusOnCheckout does not update notforloan value from 0 with setting "-1: 0"} -); + my $itemnumber4 = Koha::Item->new( + { + biblionumber => $biblionumber, + barcode => 'barcode_6', + itemcallnumber => 'callnumber6', + homebranch => $branchcode_1, + holdingbranch => $branchcode_1, + notforloan => -1, + itype => $itemtype, + location => 'loc1' + }, + )->store->itemnumber; + + t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckout', q{} ); + AddIssue( $patron_2, 'barcode_6', dt_from_string ); + $item = Koha::Items->find($itemnumber4); + ok( $item->notforloan eq -1, 'UpdateNotForLoanStatusOnCheckout does not modify value when not enabled' ); + AddReturn( 'barcode_6', $branchcode_1 ); + + t::lib::Mocks::mock_preference( + 'UpdateNotForLoanStatusOnCheckout', q{ _ALL_: + -1: 0 + } + ); + $item->notforloan(-1)->store; + my $test = AddIssue( $patron_2, 'barcode_6', dt_from_string ); + $item = Koha::Items->find($itemnumber4); + ok( + $item->notforloan eq 0, + q{UpdateNotForLoanStatusOnCheckout updates notforloan value from -1 to 0 with setting "_ALL_: -1: 0"} + ); + AddReturn( 'barcode_6', $branchcode_1 ); + + $item->notforloan(1)->store; + AddIssue( $patron_2, 'barcode_6', dt_from_string ); + $item = Koha::Items->find($itemnumber4); + ok( + $item->notforloan eq 1, + q{UpdateNotForLoanStatusOnCheckout does not update notforloan value from 1 with setting "_ALL_: -1: 0"} + ); + AddReturn( 'barcode_6', $branchcode_1 ); + + t::lib::Mocks::mock_preference( + 'UpdateNotForLoanStatusOnCheckout', q{ + _ALL_: + -1: 0 + } . $itemtype . q{: + -1: 1 + } + ); + + $item->notforloan(-1)->store; + AddIssue( $patron_2, 'barcode_6', dt_from_string ); + $item = Koha::Items->find($itemnumber4); + ok( $item->notforloan eq 1, q{UpdateNotForLoanStatusOnCheckout uses the most specific rule to update notforloan } ); + AddReturn( 'barcode_6', $branchcode_1 ); + + t::lib::Mocks::mock_preference( + 'UpdateNotForLoanStatusOnCheckout', q{ + _ALL_: + -1: 0 + NOT_} . $itemtype . q{: + -1: 1 + } + ); + + $item->notforloan(-1)->store; + AddIssue( $patron_2, 'barcode_6', dt_from_string ); + $item = Koha::Items->find($itemnumber4); + ok( + $item->notforloan eq 0, + q{UpdateNotForLoanStatusOnCheckout uses the default rule (_ALL_) if no rule matches the itype} + ); + AddReturn( 'barcode_6', $branchcode_1 ); + + $item->delete; +}; ########################################## # -- 2.39.5