From 375383fb660a3d8566b340534947ce4e0fab12d7 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Sat, 11 Apr 2020 17:49:31 +0000 Subject: [PATCH] Bug 25112: Add a failing test for CirculationRules.t To reproduce the problem, do: 1. prove t/db_dependent/Koha/CirculationRules.t 2. Observe a failing test set_rule cannot set 'holdallowed' for a 'categorycode'! at t/db_dependent/Koha/CirculationRules.t line 304. Sponsored-by: The National Library of Finland --- t/db_dependent/Koha/CirculationRules.t | 68 +++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/CirculationRules.t b/t/db_dependent/Koha/CirculationRules.t index f24542e2b6..6c0f7559d6 100644 --- a/t/db_dependent/Koha/CirculationRules.t +++ b/t/db_dependent/Koha/CirculationRules.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 3; +use Test::More tests => 4; use Test::Exception; use Koha::CirculationRules; @@ -376,3 +376,69 @@ subtest 'get_effective_daysmode' => sub { $schema->storage->txn_rollback; }; + +subtest 'set_rules() tests' => sub { + plan tests => 1; + + subtest 'scope validation' => sub { + plan tests => 6; + + $schema->storage->txn_begin; + + my $categorycode = $builder->build_object( { + class => 'Koha::Patron::Categories' } )->categorycode; + my $itemtype = $builder->build_object( { + class => 'Koha::ItemTypes' } )->itemtype; + my $branchcode = $builder->build_object( { + class => 'Koha::Libraries' } )->branchcode; + + my $rule; + Koha::CirculationRules->delete; + + is( scalar @{Koha::CirculationRules->set_rules( { + branchcode => $branchcode, + categorycode => $categorycode, + itemtype => $itemtype, + rules => { + refund => 1, + patron_maxissueqty => 2, + holdallowed => 3, + article_requests => 4, + maxissueqty => 5, + } + } )}, 5, 'All rules added' ); + + is( Koha::CirculationRules->get_effective_rule( { + branchcode => $branchcode, + rule_name => 'refund' + } )->rule_value, 1, 'Found rule refund' ); + + is( Koha::CirculationRules->get_effective_rule( { + branchcode => $branchcode, + categorycode => $categorycode, + rule_name => 'patron_maxissueqty' + } )->rule_value, 2, 'Found rule patron_maxissueqty' ); + + is( Koha::CirculationRules->get_effective_rule( { + branchcode => $branchcode, + itemtype => $itemtype, + rule_name => 'holdallowed' + } )->rule_value, 3, 'Found rule holdallowed' ); + + is( Koha::CirculationRules->get_effective_rule( { + branchcode => $branchcode, + categorycode => $categorycode, + itemtype => $itemtype, + rule_name => 'article_requests' + } )->rule_value, 4, 'Found rule article_requests' ); + + is( Koha::CirculationRules->get_effective_rule( { + branchcode => $branchcode, + categorycode => $categorycode, + itemtype => $itemtype, + rule_name => 'maxissueqty' + } )->rule_value, 5, 'Found rule maxissueqty' ); + + $schema->storage->txn_rollback; + }; +}; -- 2.17.1