From 53a77a9f2d07071a6fdcd26a7118d080233e8f27 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 3 Jun 2020 16:25:31 +0100 Subject: [PATCH] Bug 23091: Update unit test This patch updates the unit test for get_lostreturn_policy to reflect the rule_name and return code changes. Test plan: 1/ Read the code changes in t/db_dependant/Koha/CirculationRules and t/db_dependant/Koha/IssuingRules and confirm they make sense. 2/ Run the updated tests and ensure they pass. --- t/db_dependent/Koha/CirculationRules.t | 36 ++++++++++++++------------ t/db_dependent/Koha/IssuingRules.t | 12 ++++----- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/t/db_dependent/Koha/CirculationRules.t b/t/db_dependent/Koha/CirculationRules.t index 1473c235d7..8880e8fe5a 100644 --- a/t/db_dependent/Koha/CirculationRules.t +++ b/t/db_dependent/Koha/CirculationRules.t @@ -392,8 +392,8 @@ subtest 'get_lostreturn_policy() tests' => sub { branchcode => undef, categorycode => undef, itemtype => undef, - rule_name => 'refund', - rule_value => 1 + rule_name => 'lostreturn', + rule_value => 'charge' } } ); @@ -405,21 +405,21 @@ subtest 'get_lostreturn_policy() tests' => sub { branchcode => $branchcode, categorycode => undef, itemtype => undef, - rule_name => 'refund', + rule_name => 'lostreturn', rule_value => 0 } } ); my $branchcode2 = $builder->build( { source => 'Branch' } )->{branchcode}; - my $specific_rule_true = $builder->build( + my $specific_rule_lostreturn = $builder->build( { source => 'CirculationRule', value => { branchcode => $branchcode2, categorycode => undef, itemtype => undef, - rule_name => 'refund', - rule_value => 1 + rule_name => 'lostreturn', + rule_value => 'refund' } } ); @@ -432,7 +432,8 @@ subtest 'get_lostreturn_policy() tests' => sub { branchcode => $branchcode3, categorycode => undef, itemtype => undef, - rule_name => 'refund', + rule_name => 'lostreturn', + rule_value => 'restore' } } ); @@ -443,7 +444,8 @@ subtest 'get_lostreturn_policy() tests' => sub { branchcode => $branch_without_rule, categorycode => undef, itemtype => undef, - rule_name => 'refund' + rule_name => 'lostreturn', + rule_value => 'restore' } ) ->next @@ -451,36 +453,36 @@ subtest 'get_lostreturn_policy() tests' => sub { my $item = $builder->build_sample_item( { - homebranch => $specific_rule_true->{branchcode}, + homebranch => $specific_rule_lostreturn->{branchcode}, holdingbranch => $specific_rule_false->{branchcode} } ); my $params = { - return_branch => $specific_rule_true->{ branchcode }, + return_branch => $specific_rule_lostreturn->{ branchcode }, item => $item }; # Specific rules t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' ); is( Koha::CirculationRules->get_lostreturn_policy( $params ), - 1,'Specific rule for checkin branch is applied (true)'); + 'refund','Specific rule for checkin branch is applied (refund)'); t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHomeBranch' ); is( Koha::CirculationRules->get_lostreturn_policy( $params ), - 1,'Specific rule for home branch is applied (true)'); + 'refund','Specific rule for home branch is applied (refund)'); t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHoldingBranch' ); is( Koha::CirculationRules->get_lostreturn_policy( $params ), - 0,'Specific rule for holoding branch is applied (false)'); + 0,'Specific rule for holding branch is applied (false)'); # Default rule check t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' ); $params->{return_branch} = $branch_without_rule; is( Koha::CirculationRules->get_lostreturn_policy( $params ), - 1,'No rule for branch, global rule applied (true)'); + 'charge','No rule for branch, global rule applied (charge)'); # Change the default value just to try - Koha::CirculationRules->search({ branchcode => undef, rule_name => 'refund' })->next->rule_value(0)->store; + Koha::CirculationRules->search({ branchcode => undef, rule_name => 'lostreturn' })->next->rule_value(0)->store; is( Koha::CirculationRules->get_lostreturn_policy( $params ), 0,'No rule for branch, global rule applied (false)'); @@ -491,13 +493,13 @@ subtest 'get_lostreturn_policy() tests' => sub { branchcode => undef, categorycode => undef, itemtype => undef, - rule_name => 'refund' + rule_name => 'lostreturn' } ) ->next ->delete; is( Koha::CirculationRules->get_lostreturn_policy( $params ), - 1,'No rule for branch, no default rule, fallback default (true)'); + 'refund','No rule for branch, no default rule, fallback default (refund)'); $schema->storage->txn_rollback; }; diff --git a/t/db_dependent/Koha/IssuingRules.t b/t/db_dependent/Koha/IssuingRules.t index 4d37fcfebc..aa12196d16 100644 --- a/t/db_dependent/Koha/IssuingRules.t +++ b/t/db_dependent/Koha/IssuingRules.t @@ -458,10 +458,10 @@ subtest 'set_rule' => sub { lives_ok( sub { Koha::CirculationRules->set_rule( { branchcode => $branchcode, - rule_name => 'refund', + rule_name => 'lostreturn', rule_value => '', } ); - }, 'setting refund with branch' ); + }, 'setting lostreturn with branch' ); lives_ok( sub { Koha::CirculationRules->set_rule( { @@ -499,10 +499,10 @@ subtest 'set_rule' => sub { throws_ok( sub { Koha::CirculationRules->set_rule( { - rule_name => 'refund', + rule_name => 'lostreturn', rule_value => '', } ); - }, qr/branchcode/, 'setting refund without branch fails' ); + }, qr/branchcode/, 'setting lostreturn without branch fails' ); throws_ok( sub { Koha::CirculationRules->set_rule( { @@ -539,10 +539,10 @@ subtest 'set_rule' => sub { Koha::CirculationRules->set_rule( { branchcode => $branchcode, categorycode => $categorycode, - rule_name => 'refund', + rule_name => 'lostreturn', rule_value => '', } ); - }, qr/categorycode/, 'setting refund with categorycode fails' ); + }, qr/categorycode/, 'setting lostreturn with categorycode fails' ); throws_ok( sub { Koha::CirculationRules->set_rule( { -- 2.20.1