From 52fb5ac852c95c527661c84a3c1aab40af4e34af Mon Sep 17 00:00:00 2001 From: Baptiste Date: Mon, 9 Dec 2024 16:16:21 +0100 Subject: [PATCH] Bug 35292: Add tests for _updateNotForLoanFromYaml Note: These patches have been split for sake of understandability for review but they should probably be squashe --- t/db_dependent/Circulation/issue.t | 148 ++++++++++++++++++++++++++++- 1 file changed, 147 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Circulation/issue.t b/t/db_dependent/Circulation/issue.t index 9f0ee4c2e38..b4e787c1b06 100755 --- a/t/db_dependent/Circulation/issue.t +++ b/t/db_dependent/Circulation/issue.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 65; +use Test::More tests => 66; use DateTime::Duration; use t::lib::Mocks; @@ -583,6 +583,152 @@ subtest 'AddReturn: Update notforloanstatus according to UpdateNotForLoanStatusO # ########################################## +########################################## +# +# _updateNotForLoanFromYaml +# +########################################## + +subtest '_updateNotForLoanFromYaml' => sub { + plan tests => 10; + 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{} ); + t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckin', q{} ); + $item = Koha::Items->find($itemnumber4); + $item->notforloan(-1)->store; + C4::Circulation::_updateNotForLoanFromYaml( $item, 'UpdateNotForLoanStatusOnCheckout' ); + ok( + $item->notforloan eq -1, + '_updateNotForLoanFromYaml: UpdateNotForLoanStatusOnCheckout does not modify value when not enabled' + ); + C4::Circulation::_updateNotForLoanFromYaml( $item, 'UpdateNotForLoanStatusOnCheckin' ); + ok( + $item->notforloan eq -1, + '_updateNotForLoanFromYaml: UpdateNotForLoanStatusOnCheckin does not modify value when not enabled' + ); + + t::lib::Mocks::mock_preference( + 'UpdateNotForLoanStatusOnCheckout', q{ _ALL_: + -1: 0 + } + ); + t::lib::Mocks::mock_preference( + 'UpdateNotForLoanStatusOnCheckin', q{ _ALL_: + -2: 0 + } + ); + + $item->notforloan(-1)->store; + C4::Circulation::_updateNotForLoanFromYaml( $item, 'UpdateNotForLoanStatusOnCheckout' ); + ok( + $item->notforloan eq 0, + q{_updateNotForLoanFromYaml: UpdateNotForLoanStatusOnCheckout updates notforloan value from -1 to 0 with setting "_ALL_: -1: 0"} + ); + + $item->notforloan(-2)->store; + C4::Circulation::_updateNotForLoanFromYaml( $item, 'UpdateNotForLoanStatusOnCheckin' ); + ok( + $item->notforloan eq 0, + q{_updateNotForLoanFromYaml: UpdateNotForLoanStatusOnCheckin updates notforloan value from -1 to 0 with setting "_ALL_: -1: 0"} + ); + + $item->notforloan(1)->store; + C4::Circulation::_updateNotForLoanFromYaml( $item, 'UpdateNotForLoanStatusOnCheckout' ); + ok( + $item->notforloan eq 1, + q{_updateNotForLoanFromYaml: UpdateNotForLoanStatusOnCheckout does not update notforloan value from 1 with setting "_ALL_: -1: 0"} + ); + + $item->notforloan(1)->store; + C4::Circulation::_updateNotForLoanFromYaml( $item, 'UpdateNotForLoanStatusOnCheckin' ); + ok( + $item->notforloan eq 1, + q{_updateNotForLoanFromYaml: UpdateNotForLoanStatusOnCheckin does not update notforloan value from 1 with setting "_ALL_: -1: 0"} + ); + + t::lib::Mocks::mock_preference( + 'UpdateNotForLoanStatusOnCheckout', q{ + _ALL_: + -1: 0 + } . $itemtype . q{: + -1: 1 + } + ); + t::lib::Mocks::mock_preference( + 'UpdateNotForLoanStatusOnCheckin', q{ + _ALL_: + -2: 0 + } . $itemtype . q{: + -2: 1 + } + ); + + $item->notforloan(-1)->store; + C4::Circulation::_updateNotForLoanFromYaml( $item, 'UpdateNotForLoanStatusOnCheckout' ); + ok( + $item->notforloan eq 1, + q{_updateNotForLoanFromYaml: UpdateNotForLoanStatusOnCheckout uses the most specific rule to update notforloan } + ); + + $item->notforloan(-2)->store; + C4::Circulation::_updateNotForLoanFromYaml( $item, 'UpdateNotForLoanStatusOnCheckin' ); + ok( + $item->notforloan eq 1, + q{_updateNotForLoanFromYaml: UpdateNotForLoanStatusOnCheckout uses the most specific rule to update notforloan } + ); + + t::lib::Mocks::mock_preference( + 'UpdateNotForLoanStatusOnCheckout', q{ + _ALL_: + -1: 0 + NOT_} . $itemtype . q{: + -1: 1 + } + ); + t::lib::Mocks::mock_preference( + 'UpdateNotForLoanStatusOnCheckin', q{ + _ALL_: + -2: 0 + NOT_} . $itemtype . q{: + -2: 1 + } + ); + + $item->notforloan(-1)->store; + C4::Circulation::_updateNotForLoanFromYaml( $item, 'UpdateNotForLoanStatusOnCheckout' ); + ok( + $item->notforloan eq 0, + q{_updateNotForLoanFromYaml: UpdateNotForLoanStatusOnCheckout uses the default rule (_ALL_) if no rule matches the itype} + ); + + $item->notforloan(-2)->store; + C4::Circulation::_updateNotForLoanFromYaml( $item, 'UpdateNotForLoanStatusOnCheckin' ); + ok( + $item->notforloan eq 0, + q{_updateNotForLoanFromYaml: UpdateNotForLoanStatusOnCheckin uses the default rule (_ALL_) if no rule matches the itype} + ); + + $item->delete; +}; + +########################################## +# +# END _updateNotForLoanFromYaml +# +########################################## + my $itemnumber2 = Koha::Item->new( { biblionumber => $biblionumber, -- 2.30.2