From fda3d39a04698817be8faffc96f47f3b4e92e1c9 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 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 | 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 3330789276..d42f6e033f 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 => 66; +use Test::More tests => 67; use DateTime::Duration; use t::lib::Mocks; @@ -606,6 +606,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.39.5