From d3aa8e303747e790800017c62f46bcac3602f26f Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 6 Feb 2020 11:09:12 -0300 Subject: [PATCH] Bug 24602: Tests for get_onshlefholds_policy Ths patch introduces tests for get_onshelf_policy. To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/Koha/CirculationRules.t => FAIL: Tests fail because the current code returns undef instead of 0 --- t/db_dependent/Koha/CirculationRules.t | 38 ++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/t/db_dependent/Koha/CirculationRules.t b/t/db_dependent/Koha/CirculationRules.t index 460868f671..7e27b59feb 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 => 1; +use Test::More tests => 2; use Test::Exception; use Koha::CirculationRules; @@ -28,13 +28,13 @@ use Koha::Database; use t::lib::TestBuilder; my $schema = Koha::Database->new->schema; -$schema->storage->txn_begin; - my $builder = t::lib::TestBuilder->new; subtest 'set_rule + get_effective_rule' => sub { plan tests => 14; + $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; @@ -250,7 +250,35 @@ subtest 'set_rule + get_effective_rule' => sub { $our_branch_rules->delete; is( $our_branch_rules->count, 0, "We deleted 8 rules"); - + $schema->storage->txn_rollback; }; -$schema->storage->txn_rollback; +subtest 'get_onshelfholds_policy() tests' => sub { + + plan tests => 2; + + $schema->storage->txn_begin; + + my $item = $builder->build_sample_item(); + + my $circ_rules = Koha::CirculationRules->new; + # Cleanup + $circ_rules->search({ rule_name => 'onshelfholds' })->delete; + + $circ_rules->set_rule( + { + branchcode => '*', + categorycode => '*', + itemtype => '*', + rule_name => 'onshelfholds', + rule_value => 1, + } + ); + + is( $circ_rules->get_onshelfholds_policy({ item => $item }), 1, 'If rule_value is set on a matching rule, return it' ); + # Delete the rule (i.e. get_effective_rule returns undef) + $circ_rules->delete; + is( $circ_rules->get_onshelfholds_policy({ item => $item }), 0, 'If no matching rule, fallback to 0' ); + + $schema->storage->txn_rollback; +}; -- 2.25.0