Bugzilla – Attachment 52287 Details for
Bug 14048
Change RefundLostItemFeeOnReturn to be branch specific
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14048: Unit tests
Bug-14048-Unit-tests.patch (text/plain), 10.26 KB, created by
Tomás Cohen Arazi (tcohen)
on 2016-06-12 12:51:52 UTC
(
hide
)
Description:
Bug 14048: Unit tests
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2016-06-12 12:51:52 UTC
Size:
10.26 KB
patch
obsolete
>From ee8e8838cce2b00f8d4e2ac2a456d0d532b8ad41 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 3 Jun 2016 11:25:15 -0300 >Subject: [PATCH] Bug 14048: Unit tests > >This patch introduces unit tests for the feature. >To test: >- Have all patches from this bug applied >- Run: > $ prove -v t/db_dependent/RefundLostItemFeeRule.t >=> SUCCESS: All tests pass! > >Sponsored-by: DoverNet >Sponsored-by: South-East Kansas Library System >Sponsored-by: SWITCH Library Consortium >--- > t/db_dependent/RefundLostItemFeeRule.t | 290 +++++++++++++++++++++++++++++++++ > 1 file changed, 290 insertions(+) > create mode 100755 t/db_dependent/RefundLostItemFeeRule.t > >diff --git a/t/db_dependent/RefundLostItemFeeRule.t b/t/db_dependent/RefundLostItemFeeRule.t >new file mode 100755 >index 0000000..383fea1 >--- /dev/null >+++ b/t/db_dependent/RefundLostItemFeeRule.t >@@ -0,0 +1,290 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 8; >+use t::lib::Mocks; >+use t::lib::TestBuilder; >+ >+use C4::Context; >+use Koha::Database; >+ >+BEGIN { >+ use_ok('Koha::Object'); >+ use_ok('Koha::RefundLostItemFeeRule'); >+ use_ok('Koha::RefundLostItemFeeRules'); >+} >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+subtest 'Koha::RefundLostItemFeeRule::delete() tests' => sub { >+ >+ plan tests => 7; >+ >+ # Start transaction >+ $schema->storage->txn_begin; >+ >+ # Clean the table >+ $schema->resultset('RefundLostItemFeeRule')->search()->delete; >+ >+ my $generated_default_rule = $builder->build({ >+ source => 'RefundLostItemFeeRule', >+ value => { >+ branchcode => '*' >+ } >+ }); >+ my $generated_other_rule = $builder->build({ >+ source => 'RefundLostItemFeeRule' >+ }); >+ >+ my $default_rule = Koha::RefundLostItemFeeRules->find({ >+ branchcode => '*' }); >+ ok( defined $default_rule, 'Default rule created' ); >+ ok( $default_rule->in_storage, 'Default rule actually in storage'); >+ >+ my $other_rule = Koha::RefundLostItemFeeRules->find({ >+ branchcode => $generated_other_rule->{ branchcode } >+ }); >+ ok( defined $other_rule, 'Other rule created' ); >+ ok( $other_rule->in_storage, 'Other rule actually in storage'); >+ >+ # deleting the regular rule >+ $other_rule->delete; >+ ok( !$other_rule->in_storage, 'Other rule deleted from storage' ); >+ >+ # deleting the default rule >+ eval { >+ $default_rule->delete; >+ }; >+ is( ref($@), 'Koha::Exceptions::CannotDeleteDefault', >+ 'Exception on deleting default' ); >+ ok( $default_rule->in_storage, 'Default rule still in storage' ); >+ >+ # Rollback transaction >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'Koha::RefundLostItemFeeRules::_default_rule() tests' => sub { >+ >+ plan tests => 4; >+ >+ # Start transaction >+ $schema->storage->txn_begin; >+ >+ # Clean the table >+ $schema->resultset('RefundLostItemFeeRule')->search()->delete; >+ >+ my $generated_default_rule = $builder->build({ >+ source => 'RefundLostItemFeeRule', >+ value => { >+ branchcode => '*', >+ refund => 1 >+ } >+ }); >+ my $generated_other_rule = $builder->build({ >+ source => 'RefundLostItemFeeRule' >+ }); >+ >+ my $default_rule = Koha::RefundLostItemFeeRules->find({ >+ branchcode => '*' }); >+ ok( defined $default_rule, 'Default rule created' ); >+ ok( $default_rule->in_storage, 'Default rule actually in storage'); >+ ok( Koha::RefundLostItemFeeRules->_default_rule, 'Default rule is set to refund' ); >+ >+ # Change default rule to "Don't refund" >+ $default_rule->refund(0); >+ $default_rule->store; >+ # Re-read from DB, to be sure >+ $default_rule = Koha::RefundLostItemFeeRules->find({ >+ branchcode => '*' }); >+ ok( !Koha::RefundLostItemFeeRules->_default_rule, 'Default rule is set to not refund' ); >+ >+ # Rollback transaction >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'Koha::RefundLostItemFeeRules::_effective_branch_rule() tests' => sub { >+ >+ plan tests => 3; >+ >+ # Start transaction >+ $schema->storage->txn_begin; >+ >+ # Clean the table >+ $schema->resultset('RefundLostItemFeeRule')->search()->delete; >+ >+ my $default_rule = $builder->build({ >+ source => 'RefundLostItemFeeRule', >+ value => { >+ branchcode => '*', >+ refund => 1 >+ } >+ }); >+ my $specific_rule_false = $builder->build({ >+ source => 'RefundLostItemFeeRule', >+ value => { >+ refund => 0 >+ } >+ }); >+ my $specific_rule_true = $builder->build({ >+ source => 'RefundLostItemFeeRule', >+ value => { >+ refund => 1 >+ } >+ }); >+ >+ is( Koha::RefundLostItemFeeRules->_effective_branch_rule( $specific_rule_true->{ branchcode } ), >+ 1,'Specific rule is applied (true)'); >+ is( Koha::RefundLostItemFeeRules->_effective_branch_rule( $specific_rule_false->{ branchcode } ), >+ 0,'Specific rule is applied (false)'); >+ # Delete specific rules >+ Koha::RefundLostItemFeeRules->find({ branchcode => $specific_rule_false->{ branchcode } })->delete; >+ is( Koha::RefundLostItemFeeRules->_effective_branch_rule( $specific_rule_false->{ branchcode } ), >+ 1,'No specific rule defined, fallback to global (true)'); >+ >+ # Rollback transaction >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'Koha::RefundLostItemFeeRules::_choose_branch() tests' => sub { >+ >+ plan tests => 9; >+ >+ # Start transaction >+ $schema->storage->txn_begin; >+ >+ my $params = { >+ current_branch => 'current_branch_code', >+ item_holding_branch => 'item_holding_branch_code', >+ item_home_branch => 'item_home_branch_code' >+ }; >+ >+ my $syspref = Koha::Config::SysPrefs->find_or_create({ >+ variable => 'RefundLostOnReturnControl', >+ value => 'CheckinLibrary' }); >+ >+ is( Koha::RefundLostItemFeeRules->_choose_branch( $params ), >+ 'current_branch_code', 'CheckinLibrary is honoured'); >+ >+ $syspref->value( 'ItemHomeBranch' )->store; >+ is( Koha::RefundLostItemFeeRules->_choose_branch( $params ), >+ 'item_home_branch_code', 'ItemHomeBranch is honoured'); >+ >+ $syspref->value( 'ItemHoldingBranch' )->store; >+ is( Koha::RefundLostItemFeeRules->_choose_branch( $params ), >+ 'item_holding_branch_code', 'ItemHoldingBranch is honoured'); >+ >+ $syspref->value( 'CheckinLibrary' )->store; >+ eval { >+ Koha::RefundLostItemFeeRules->_choose_branch(); >+ }; >+ is( ref($@), 'Koha::Exceptions::MissingParameter', >+ 'Missing parameter exception' ); >+ is( $@->message, 'CheckinLibrary requires the current_branch param', >+ 'Exception message is correct' ); >+ >+ $syspref->value( 'ItemHomeBranch' )->store; >+ eval { >+ Koha::RefundLostItemFeeRules->_choose_branch(); >+ }; >+ is( ref($@), 'Koha::Exceptions::MissingParameter', >+ 'Missing parameter exception' ); >+ is( $@->message, 'ItemHomeBranch requires the item_home_branch param', >+ 'Exception message is correct' ); >+ >+ $syspref->value( 'ItemHoldingBranch' )->store; >+ eval { >+ Koha::RefundLostItemFeeRules->_choose_branch(); >+ }; >+ is( ref($@), 'Koha::Exceptions::MissingParameter', >+ 'Missing parameter exception' ); >+ is( $@->message, 'ItemHoldingBranch requires the item_holding_branch param', >+ 'Exception message is correct' ); >+ >+ # Rollback transaction >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'Koha::RefundLostItemFeeRules::should_refund() tests' => sub { >+ >+ plan tests => 3; >+ >+ # Start transaction >+ $schema->storage->txn_begin; >+ >+ my $syspref = Koha::Config::SysPrefs->find_or_create({ >+ variable => 'RefundLostOnReturnControl', >+ value => 'CheckinLibrary' }); >+ >+ $schema->resultset('RefundLostItemFeeRule')->search()->delete; >+ >+ my $default_rule = $builder->build({ >+ source => 'RefundLostItemFeeRule', >+ value => { >+ branchcode => '*', >+ refund => 1 >+ } >+ }); >+ my $specific_rule_false = $builder->build({ >+ source => 'RefundLostItemFeeRule', >+ value => { >+ refund => 0 >+ } >+ }); >+ my $specific_rule_true = $builder->build({ >+ source => 'RefundLostItemFeeRule', >+ value => { >+ refund => 1 >+ } >+ }); >+ # Make sure we have an unused branchcode >+ my $specific_rule_dummy = $builder->build({ >+ source => 'RefundLostItemFeeRule' >+ }); >+ my $branch_without_rule = $specific_rule_dummy->{ branchcode }; >+ Koha::RefundLostItemFeeRules >+ ->find({ branchcode => $branch_without_rule }) >+ ->delete; >+ >+ my $params = { >+ current_branch => $specific_rule_true->{ branchcode }, >+ # patron_branch => $specific_rule_false->{ branchcode }, >+ item_holding_branch => $branch_without_rule, >+ item_home_branch => $branch_without_rule >+ }; >+ >+ $syspref->value( 'CheckinLibrary' )->store; >+ is( Koha::RefundLostItemFeeRules->should_refund( $params ), >+ 1,'Specific rule is applied (true)'); >+ >+ $syspref->value( 'ItemHomeBranch' )->store; >+ is( Koha::RefundLostItemFeeRules->should_refund( $params ), >+ 1,'No rule for branch, global rule applied (true)'); >+ >+ # Change the default value just to try >+ Koha::RefundLostItemFeeRules->find({ branchcode => '*' })->refund(0)->store; >+ $syspref->value( 'ItemHoldingBranch' )->store; >+ is( Koha::RefundLostItemFeeRules->should_refund( $params ), >+ 0,'No rule for branch, global rule applied (false)'); >+ >+ # Rollback transaction >+ $schema->storage->txn_rollback; >+}; >+ >+1; >-- >2.8.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 14048
:
52016
|
52017
|
52018
|
52019
|
52020
|
52169
|
52170
|
52202
|
52203
|
52286
|
52287
|
52288
|
52289
|
52290
|
52291
|
52292
|
52293
|
52306
|
52444
|
52445
|
52446
|
52447
|
52448
|
52449
|
52450
|
52451
|
52482
|
52658
|
52659
|
52660
|
52661
|
52662
|
52663
|
52664
|
52665
|
52666
|
52667
|
52668
|
52748
|
52749
|
52750
|
52751
|
52752
|
52753
|
52754
|
52755
|
52756
|
52757
|
52835
|
52836
|
52837
|
52838
|
52839
|
52840
|
52841
|
52842
|
52843
|
52844
|
52876
|
52883
|
52894
|
53017
|
53018
|
53019
|
53020
|
53021
|
53022
|
53023
|
53024
|
53025
|
53026
|
53027
|
53028
|
53029