From d7e8e661dc2b8e0b618e43294d91a1c95b0307d9 Mon Sep 17 00:00:00 2001 From: Baptiste Date: Mon, 9 Dec 2024 16:57:40 +0100 Subject: [PATCH] Bug 35292: Move tests for UpdateNotForLoanStatusOnCheckin in a subtest Note: These patches have been split for sake of understandability for review but they should probably be squashe --- t/db_dependent/Circulation/issue.t | 160 +++++++++++++++-------------- 1 file changed, 82 insertions(+), 78 deletions(-) diff --git a/t/db_dependent/Circulation/issue.t b/t/db_dependent/Circulation/issue.t index d42f6e033f6..f4ef34ce549 100755 --- a/t/db_dependent/Circulation/issue.t +++ b/t/db_dependent/Circulation/issue.t @@ -17,8 +17,7 @@ use Modern::Perl; -use Test::NoWarnings; -use Test::More tests => 67; +use Test::More tests => 60; use DateTime::Duration; use t::lib::Mocks; @@ -435,83 +434,88 @@ ok( $return->{returndate} eq '2014-04-01 23:42:00', "Item returned with a return date of '2014-04-01 23:42' has that return date" ); +subtest 'AddIssue Update notforloanstatus according to UpdateNotForLoanStatusOnCheckin' => sub { + plan tests => 7; + my $itemnumber = Koha::Item->new( + { + biblionumber => $biblionumber, + barcode => 'barcode_3', + itemcallnumber => 'callnumber3', + homebranch => $branchcode_1, + holdingbranch => $branchcode_1, + notforloan => 1, + itype => $itemtype, + biblioitemnumber => $biblioitemnumber + }, + )->store->itemnumber; -my $itemnumber = Koha::Item->new( - { - biblionumber => $biblionumber, - barcode => 'barcode_3', - itemcallnumber => 'callnumber3', - homebranch => $branchcode_1, - holdingbranch => $branchcode_1, - notforloan => 1, - itype => $itemtype, - biblioitemnumber => $biblioitemnumber - }, -)->store->itemnumber; - -t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckin', q{} ); -t::lib::Mocks::mock_preference( 'CataloguingLog', 1 ); -my $log_count_before = $schema->resultset('ActionLog')->search( { module => 'CATALOGUING' } )->count(); - -AddReturn( 'barcode_3', $branchcode_1 ); -my $item = Koha::Items->find($itemnumber); -ok( $item->notforloan eq 1, 'UpdateNotForLoanStatusOnCheckin does not modify value when not enabled' ); - -my $updatenotforloanstatusoncheckin = " -_ALL_:\n - 1: 0\n - 9: 1\n\n -$itemtype:\n - 1: 9 -"; -t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckin', $updatenotforloanstatusoncheckin ); -AddReturn( 'barcode_3', $branchcode_1 ); -$item = Koha::Items->find($itemnumber); -ok( $item->notforloan eq 9, q{UpdateNotForLoanStatusOnCheckin prioritises item type specific rule over _ALL_ rules} ); -my $log_count_after = $schema->resultset('ActionLog')->search( { module => 'CATALOGUING' } )->count(); -is( $log_count_before, $log_count_after, "Change from UpdateNotForLoanStatusOnCheckin is not logged" ); + t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckin', q{} ); + t::lib::Mocks::mock_preference( 'CataloguingLog', 1 ); + my $log_count_before = $schema->resultset('ActionLog')->search( { module => 'CATALOGUING' } )->count(); + + AddReturn( 'barcode_3', $branchcode_1 ); + my $item = Koha::Items->find($itemnumber); + ok( $item->notforloan eq 1, 'UpdateNotForLoanStatusOnCheckin does not modify value when not enabled' ); + + my $updatenotforloanstatusoncheckin = " + _ALL_:\n + 1: 0\n + 9: 1\n\n + $itemtype:\n + 1: 9 + "; + t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckin', $updatenotforloanstatusoncheckin ); + AddReturn( 'barcode_3', $branchcode_1 ); + $item = Koha::Items->find($itemnumber); + ok( + $item->notforloan eq 9, + q{UpdateNotForLoanStatusOnCheckin prioritises item type specific rule over _ALL_ rules} + ); + my $log_count_after = $schema->resultset('ActionLog')->search( { module => 'CATALOGUING' } )->count(); + is( $log_count_before, $log_count_after, "Change from UpdateNotForLoanStatusOnCheckin is not logged" ); -AddReturn( 'barcode_3', $branchcode_1 ); -$item = Koha::Items->find($itemnumber); -ok( - $item->notforloan eq 9, - q{UpdateNotForLoanStatusOnCheckin uses item type specific rules even if they do not target the returned items' notforloan value} -); + AddReturn( 'barcode_3', $branchcode_1 ); + $item = Koha::Items->find($itemnumber); + ok( + $item->notforloan eq 9, + q{UpdateNotForLoanStatusOnCheckin uses item type specific rules even if they do not target the returned items' notforloan value} + ); -# Change the returning item to an item type without a rule -Koha::Items->find($itemnumber)->itype($itemtype2)->store; -Koha::Items->find($itemnumber)->notforloan(1)->store; -AddReturn( 'barcode_3', $branchcode_1 ); -$item = Koha::Items->find($itemnumber); -ok( - $item->notforloan eq 0, - q{UpdateNotForLoanStatusOnCheckin _ALL_ rules are applied if there are no specific item type rule matching the returned item} -); + # Change the returning item to an item type without a rule + Koha::Items->find($itemnumber)->itype($itemtype2)->store; + Koha::Items->find($itemnumber)->notforloan(1)->store; + AddReturn( 'barcode_3', $branchcode_1 ); + $item = Koha::Items->find($itemnumber); + ok( + $item->notforloan eq 0, + q{UpdateNotForLoanStatusOnCheckin _ALL_ rules are applied if there are no specific item type rule matching the returned item} + ); -t::lib::Mocks::mock_preference( - 'UpdateNotForLoanStatusOnCheckin', q{_ALL_: - 1: ONLYMESSAGE -} -); -$item->notforloan(1)->store; -AddReturn( 'barcode_3', $branchcode_1 ); -$item->discard_changes; -is( - $item->notforloan, 1, - q{UpdateNotForLoanStatusOnCheckin does not update notforloan value from 1 for _ALL_ with setting "1: ONLYMESSAGE"} -); + t::lib::Mocks::mock_preference( + 'UpdateNotForLoanStatusOnCheckin', q{_ALL_: + 1: ONLYMESSAGE + } + ); + $item->notforloan(1)->store; + AddReturn( 'barcode_3', $branchcode_1 ); + $item->discard_changes; + is( + $item->notforloan, 1, + q{UpdateNotForLoanStatusOnCheckin does not update notforloan value from 1 for _ALL_ with setting "1: ONLYMESSAGE"} + ); -t::lib::Mocks::mock_preference( - 'UpdateNotForLoanStatusOnCheckin', "$itemtype:\n - 1: ONLYMESSAGE -" -); -AddReturn( 'barcode_3', $branchcode_1 ); -$item->discard_changes; -is( - $item->notforloan, 1, - q{UpdateNotForLoanStatusOnCheckin does not update notforloan value for specific itemtype from 1 with setting "1: ONLYMESSAGE"} -); + t::lib::Mocks::mock_preference( + 'UpdateNotForLoanStatusOnCheckin', "$itemtype:\n + 1: ONLYMESSAGE + " + ); + AddReturn( 'barcode_3', $branchcode_1 ); + $item->discard_changes; + is( + $item->notforloan, 1, + q{UpdateNotForLoanStatusOnCheckin does not update notforloan value for specific itemtype from 1 with setting "1: ONLYMESSAGE"} + ); +}; ############################################## # @@ -537,7 +541,7 @@ subtest 'AddReturn: Update notforloanstatus according to UpdateNotForLoanStatusO t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckout', q{} ); AddIssue( $patron_2, 'barcode_6', dt_from_string ); - $item = Koha::Items->find($itemnumber4); + my $item = Koha::Items->find($itemnumber4); ok( $item->notforloan eq -1, 'UpdateNotForLoanStatusOnCheckout does not modify value when not enabled' ); AddReturn( 'barcode_6', $branchcode_1 ); @@ -629,7 +633,7 @@ subtest '_updateNotForLoanFromYaml' => sub { t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckout', q{} ); t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckin', q{} ); - $item = Koha::Items->find($itemnumber4); + my $item = Koha::Items->find($itemnumber4); $item->notforloan(-1)->store; C4::Circulation::_updateNotForLoanFromYaml( $item, 'UpdateNotForLoanStatusOnCheckout' ); ok( @@ -772,7 +776,7 @@ my $item2 = Koha::Items->find($itemnumber2); ok( $item2->location eq 'FIC', 'UpdateItemLocationOnCheckin does not modify value when not enabled' ); t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckin', 'FIC: GEN' ); -$log_count_before = $schema->resultset('ActionLog')->search( { module => 'CATALOGUING' } )->count(); +my $log_count_before = $schema->resultset('ActionLog')->search( { module => 'CATALOGUING' } )->count(); AddReturn( 'barcode_4', $branchcode_1 ); $item2 = Koha::Items->find($itemnumber2); is( @@ -783,7 +787,7 @@ is( $item2->permanent_location, 'GEN', q{UpdateItemLocationOnCheckin updates permanent_location value from 'FIC' to 'GEN' with setting "FIC: GEN"} ); -$log_count_after = $schema->resultset('ActionLog')->search( { module => 'CATALOGUING' } )->count(); +my $log_count_after = $schema->resultset('ActionLog')->search( { module => 'CATALOGUING' } )->count(); is( $log_count_before, $log_count_after, "Change from UpdateNotForLoanStatusOnCheckin is not logged" ); AddReturn( 'barcode_4', $branchcode_1 ); $item2 = Koha::Items->find($itemnumber2); -- 2.30.2