From e4846d2b28d1ebbc9b015584eb22bb60f8b3e3dc 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. Signed-off-by: Andrew Fuerste-Henry --- t/db_dependent/Circulation.t | 8 ++-- t/db_dependent/Koha/CirculationRules.t | 60 ++++++++++++++++---------- t/db_dependent/Koha/IssuingRules.t | 12 +++--- 3 files changed, 48 insertions(+), 32 deletions(-) diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index f26f2f3255..9dfc5b4de9 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -3658,8 +3658,8 @@ subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddReturn' => sub { branchcode => undef, categorycode => undef, itemtype => undef, - rule_name => 'refund', - rule_value => 1 + rule_name => 'lostreturn', + rule_value => 'refund' } } ); @@ -3851,8 +3851,8 @@ subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddIssue' => sub { branchcode => undef, categorycode => undef, itemtype => undef, - rule_name => 'refund', - rule_value => 1 + rule_name => 'lostreturn', + rule_value => 'refund' } } ); diff --git a/t/db_dependent/Koha/CirculationRules.t b/t/db_dependent/Koha/CirculationRules.t index 708168a048..93faa7bf05 100755 --- a/t/db_dependent/Koha/CirculationRules.t +++ b/t/db_dependent/Koha/CirculationRules.t @@ -279,15 +279,15 @@ subtest 'get_lostreturn_policy() tests' => sub { $schema->resultset('CirculationRule')->search()->delete; - my $default_rule = $builder->build( + my $default_rule_charge = $builder->build( { source => 'CirculationRule', value => { branchcode => undef, categorycode => undef, itemtype => undef, - rule_name => 'refund', - rule_value => 1 + rule_name => 'lostreturn', + rule_value => 'charge' } } ); @@ -299,34 +299,49 @@ 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_refund = $builder->build( { source => 'CirculationRule', value => { branchcode => $branchcode2, categorycode => undef, itemtype => undef, - rule_name => 'refund', - rule_value => 1 + rule_name => 'lostreturn', + rule_value => 'refund' } } ); - # Make sure we have an unused branchcode my $branchcode3 = $builder->build( { source => 'Branch' } )->{branchcode}; - my $specific_rule_dummy = $builder->build( + my $specific_rule_restore = $builder->build( { source => 'CirculationRule', value => { branchcode => $branchcode3, categorycode => undef, itemtype => undef, - rule_name => 'refund', + rule_name => 'lostreturn', + rule_value => 'restore' + } + } + ); + + # Make sure we have an unused branchcode + my $branchcode4 = $builder->build( { source => 'Branch' } )->{branchcode}; + my $specific_rule_dummy = $builder->build( + { + source => 'CirculationRule', + value => { + branchcode => $branchcode4, + categorycode => undef, + itemtype => undef, + rule_name => 'lostreturn', + rule_value => 'refund' } } ); @@ -337,7 +352,8 @@ subtest 'get_lostreturn_policy() tests' => sub { branchcode => $branch_without_rule, categorycode => undef, itemtype => undef, - rule_name => 'refund' + rule_name => 'lostreturn', + rule_value => 'refund' } ) ->next @@ -345,36 +361,36 @@ subtest 'get_lostreturn_policy() tests' => sub { my $item = $builder->build_sample_item( { - homebranch => $specific_rule_false->{branchcode}, - holdingbranch => $specific_rule_true->{branchcode} + homebranch => $specific_rule_restore->{branchcode}, + holdingbranch => $specific_rule_false->{branchcode} } ); my $params = { - return_branch => $specific_rule_true->{ branchcode }, + return_branch => $specific_rule_refund->{ 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 ), - 0,'Specific rule for home branch is applied (false)'); + 'restore','Specific rule for home branch is applied (restore)'); t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHoldingBranch' ); is( Koha::CirculationRules->get_lostreturn_policy( $params ), - 1,'Specific rule for holding branch is applied (true)'); + 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)'); @@ -385,18 +401,18 @@ 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)'); # Fallback to ItemHoldBranch if CheckinLibrary is undefined $params->{return_branch} = undef; is( Koha::CirculationRules->get_lostreturn_policy( $params ), - 0,'return_branch undefined, fallback to ItemHomeBranch rule (false)'); + 'restore','return_branch undefined, fallback to ItemHomeBranch rule (restore)'); $schema->storage->txn_rollback; }; diff --git a/t/db_dependent/Koha/IssuingRules.t b/t/db_dependent/Koha/IssuingRules.t index 31abe27c4c..afcb2867b7 100755 --- a/t/db_dependent/Koha/IssuingRules.t +++ b/t/db_dependent/Koha/IssuingRules.t @@ -163,10 +163,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( { @@ -204,10 +204,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( { @@ -244,10 +244,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