From b0ccaaf8ef1f59b6c2f9634146bf7170aad39dc9 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 28 Jan 2020 16:47:39 +0100 Subject: [PATCH] Bug 18936: Fix IssuingRules/guess_article_requestable_itemtypes.t MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Minna Kivinen Signed-off-by: Joonas Kylmälä Signed-off-by: Martin Renvoize --- Koha/CirculationRules.pm | 2 +- .../guess_article_requestable_itemtypes.t | 33 ++++++++++--------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Koha/CirculationRules.pm b/Koha/CirculationRules.pm index 1e50251fa7..3e54740097 100644 --- a/Koha/CirculationRules.pm +++ b/Koha/CirculationRules.pm @@ -481,7 +481,7 @@ sub guess_article_requestable_itemtypes { }); return $res if !$rules; foreach my $rule ( $rules->as_list ) { - $res->{ $rule->itemtype } = 1; + $res->{ $rule->itemtype // '*' } = 1; } $last_article_requestable_guesses->{$key} = $res; $cache->set_in_cache(GUESSED_ITEMTYPES_KEY, $last_article_requestable_guesses); diff --git a/t/db_dependent/Koha/IssuingRules/guess_article_requestable_itemtypes.t b/t/db_dependent/Koha/IssuingRules/guess_article_requestable_itemtypes.t index dc5203dfd5..f5c0f8aa9b 100644 --- a/t/db_dependent/Koha/IssuingRules/guess_article_requestable_itemtypes.t +++ b/t/db_dependent/Koha/IssuingRules/guess_article_requestable_itemtypes.t @@ -21,28 +21,29 @@ subtest 'guess_article_requestable_itemtypes' => sub { t::lib::Mocks::mock_preference('ArticleRequestsLinkControl', 'calc'); $cache->clear_from_cache( Koha::CirculationRules::GUESSED_ITEMTYPES_KEY ); Koha::CirculationRules->delete; + my $library = $builder->build_object({ class => 'Koha::Libraries' }); my $itype1 = $builder->build_object({ class => 'Koha::ItemTypes' }); my $itype2 = $builder->build_object({ class => 'Koha::ItemTypes' }); my $catg1 = $builder->build_object({ class => 'Koha::Patron::Categories' }); my $catg2 = $builder->build_object({ class => 'Koha::Patron::Categories' }); - my $rule1 = $builder->build_object({ - class => 'Koha::CirculationRules', - value => { - branchcode => 'MPL', # no worries: no FK - categorycode => '*', - itemtype => $itype1->itemtype, - article_requests => 'bib_only', + my $rule1 = Koha::CirculationRules->set_rule( + { + branchcode => $library->branchcode, + categorycode => undef, + itemtype => $itype1->itemtype, + rule_name => 'article_requests', + rule_value => 'bib_only', }, - }); - my $rule2 = $builder->build_object({ - class => 'Koha::CirculationRules', - value => { - branchcode => '*', + ); + my $rule2 = Koha::CirculationRules->set_rule( + { + branchcode => undef, categorycode => $catg1->categorycode, - itemtype => $itype2->itemtype, - article_requests => 'yes', + itemtype => $itype2->itemtype, + rule_name => 'article_requests', + rule_value => 'yes', }, - }); + ); my $res = Koha::CirculationRules->guess_article_requestable_itemtypes; is( $res->{'*'}, undef, 'Item type * seems not permitted' ); @@ -54,7 +55,7 @@ subtest 'guess_article_requestable_itemtypes' => sub { is( $res->{$itype2->itemtype}, undef, 'Item type 2 seems not permitted' ); # Change the rules - $rule2->itemtype('*')->store; + $rule2->itemtype(undef)->store; $cache->clear_from_cache( Koha::CirculationRules::GUESSED_ITEMTYPES_KEY ); $res = Koha::CirculationRules->guess_article_requestable_itemtypes; is( $res->{'*'}, 1, 'Item type * seems permitted' ); -- 2.39.5