|
Lines 20-26
Link Here
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Benchmark; |
22 |
use Benchmark; |
| 23 |
use Test::More tests => 7; |
23 |
use Test::More tests => 8; |
| 24 |
use Test::Deep qw( cmp_methods ); |
24 |
use Test::Deep qw( cmp_methods ); |
| 25 |
use Test::Exception; |
25 |
use Test::Exception; |
| 26 |
|
26 |
|
|
Lines 161-167
subtest 'set_rule' => sub {
Link Here
|
| 161 |
my $itemtype = $builder->build({ source => 'Itemtype' })->{'itemtype'}; |
161 |
my $itemtype = $builder->build({ source => 'Itemtype' })->{'itemtype'}; |
| 162 |
|
162 |
|
| 163 |
subtest 'Correct call' => sub { |
163 |
subtest 'Correct call' => sub { |
| 164 |
plan tests => 4; |
164 |
plan tests => 5; |
| 165 |
|
165 |
|
| 166 |
Koha::CirculationRules->delete; |
166 |
Koha::CirculationRules->delete; |
| 167 |
|
167 |
|
|
Lines 173-178
subtest 'set_rule' => sub {
Link Here
|
| 173 |
} ); |
173 |
} ); |
| 174 |
}, 'setting lostreturn with branch' ); |
174 |
}, 'setting lostreturn with branch' ); |
| 175 |
|
175 |
|
|
|
176 |
lives_ok( sub { |
| 177 |
Koha::CirculationRules->set_rule( { |
| 178 |
branchcode => $branchcode, |
| 179 |
rule_name => 'processingreturn', |
| 180 |
rule_value => '', |
| 181 |
} ); |
| 182 |
}, 'setting processingreturn with branch' ); |
| 183 |
|
| 176 |
lives_ok( sub { |
184 |
lives_ok( sub { |
| 177 |
Koha::CirculationRules->set_rule( { |
185 |
Koha::CirculationRules->set_rule( { |
| 178 |
branchcode => $branchcode, |
186 |
branchcode => $branchcode, |
|
Lines 203-209
subtest 'set_rule' => sub {
Link Here
|
| 203 |
}; |
211 |
}; |
| 204 |
|
212 |
|
| 205 |
subtest 'Call with missing params' => sub { |
213 |
subtest 'Call with missing params' => sub { |
| 206 |
plan tests => 4; |
214 |
plan tests => 5; |
| 207 |
|
215 |
|
| 208 |
Koha::CirculationRules->delete; |
216 |
Koha::CirculationRules->delete; |
| 209 |
|
217 |
|
|
Lines 214-219
subtest 'set_rule' => sub {
Link Here
|
| 214 |
} ); |
222 |
} ); |
| 215 |
}, qr/branchcode/, 'setting lostreturn without branch fails' ); |
223 |
}, qr/branchcode/, 'setting lostreturn without branch fails' ); |
| 216 |
|
224 |
|
|
|
225 |
throws_ok( sub { |
| 226 |
Koha::CirculationRules->set_rule( { |
| 227 |
rule_name => 'processingreturn', |
| 228 |
rule_value => '', |
| 229 |
} ); |
| 230 |
}, qr/branchcode/, 'setting processingreturn without branch fails' ); |
| 231 |
|
| 217 |
throws_ok( sub { |
232 |
throws_ok( sub { |
| 218 |
Koha::CirculationRules->set_rule( { |
233 |
Koha::CirculationRules->set_rule( { |
| 219 |
branchcode => $branchcode, |
234 |
branchcode => $branchcode, |
|
Lines 241-247
subtest 'set_rule' => sub {
Link Here
|
| 241 |
}; |
256 |
}; |
| 242 |
|
257 |
|
| 243 |
subtest 'Call with extra params' => sub { |
258 |
subtest 'Call with extra params' => sub { |
| 244 |
plan tests => 3; |
259 |
plan tests => 4; |
| 245 |
|
260 |
|
| 246 |
Koha::CirculationRules->delete; |
261 |
Koha::CirculationRules->delete; |
| 247 |
|
262 |
|
|
Lines 254-259
subtest 'set_rule' => sub {
Link Here
|
| 254 |
} ); |
269 |
} ); |
| 255 |
}, qr/categorycode/, 'setting lostreturn with categorycode fails' ); |
270 |
}, qr/categorycode/, 'setting lostreturn with categorycode fails' ); |
| 256 |
|
271 |
|
|
|
272 |
throws_ok( sub { |
| 273 |
Koha::CirculationRules->set_rule( { |
| 274 |
branchcode => $branchcode, |
| 275 |
categorycode => $categorycode, |
| 276 |
rule_name => 'processingreturn', |
| 277 |
rule_value => '', |
| 278 |
} ); |
| 279 |
}, qr/categorycode/, 'setting processingreturn with categorycode fails' ); |
| 280 |
|
| 257 |
throws_ok( sub { |
281 |
throws_ok( sub { |
| 258 |
Koha::CirculationRules->set_rule( { |
282 |
Koha::CirculationRules->set_rule( { |
| 259 |
branchcode => $branchcode, |
283 |
branchcode => $branchcode, |
|
Lines 801-806
subtest 'get_lostreturn_policy() tests' => sub {
Link Here
|
| 801 |
$schema->storage->txn_rollback; |
825 |
$schema->storage->txn_rollback; |
| 802 |
}; |
826 |
}; |
| 803 |
|
827 |
|
|
|
828 |
subtest 'get_processingreturn_policy() tests' => sub { |
| 829 |
plan tests => 7; |
| 830 |
|
| 831 |
$schema->storage->txn_begin; |
| 832 |
|
| 833 |
$schema->resultset('CirculationRule')->search()->delete; |
| 834 |
|
| 835 |
my $default_rule_charge = $builder->build( |
| 836 |
{ |
| 837 |
source => 'CirculationRule', |
| 838 |
value => { |
| 839 |
branchcode => undef, |
| 840 |
categorycode => undef, |
| 841 |
itemtype => undef, |
| 842 |
rule_name => 'processingreturn', |
| 843 |
rule_value => 'charge' |
| 844 |
} |
| 845 |
} |
| 846 |
); |
| 847 |
my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; |
| 848 |
my $specific_rule_false = $builder->build( |
| 849 |
{ |
| 850 |
source => 'CirculationRule', |
| 851 |
value => { |
| 852 |
branchcode => $branchcode, |
| 853 |
categorycode => undef, |
| 854 |
itemtype => undef, |
| 855 |
rule_name => 'processingreturn', |
| 856 |
rule_value => 0 |
| 857 |
} |
| 858 |
} |
| 859 |
); |
| 860 |
my $branchcode2 = $builder->build( { source => 'Branch' } )->{branchcode}; |
| 861 |
my $specific_rule_refund = $builder->build( |
| 862 |
{ |
| 863 |
source => 'CirculationRule', |
| 864 |
value => { |
| 865 |
branchcode => $branchcode2, |
| 866 |
categorycode => undef, |
| 867 |
itemtype => undef, |
| 868 |
rule_name => 'processingreturn', |
| 869 |
rule_value => 'refund' |
| 870 |
} |
| 871 |
} |
| 872 |
); |
| 873 |
my $branchcode3 = $builder->build( { source => 'Branch' } )->{branchcode}; |
| 874 |
my $specific_rule_restore = $builder->build( |
| 875 |
{ |
| 876 |
source => 'CirculationRule', |
| 877 |
value => { |
| 878 |
branchcode => $branchcode3, |
| 879 |
categorycode => undef, |
| 880 |
itemtype => undef, |
| 881 |
rule_name => 'processingreturn', |
| 882 |
rule_value => 'restore' |
| 883 |
} |
| 884 |
} |
| 885 |
); |
| 886 |
|
| 887 |
# Make sure we have an unused branchcode |
| 888 |
my $branchcode4 = $builder->build( { source => 'Branch' } )->{branchcode}; |
| 889 |
my $specific_rule_dummy = $builder->build( |
| 890 |
{ |
| 891 |
source => 'CirculationRule', |
| 892 |
value => { |
| 893 |
branchcode => $branchcode4, |
| 894 |
categorycode => undef, |
| 895 |
itemtype => undef, |
| 896 |
rule_name => 'processingreturn', |
| 897 |
rule_value => 'refund' |
| 898 |
} |
| 899 |
} |
| 900 |
); |
| 901 |
my $branch_without_rule = $specific_rule_dummy->{ branchcode }; |
| 902 |
Koha::CirculationRules |
| 903 |
->search( |
| 904 |
{ |
| 905 |
branchcode => $branch_without_rule, |
| 906 |
categorycode => undef, |
| 907 |
itemtype => undef, |
| 908 |
rule_name => 'processingreturn', |
| 909 |
rule_value => 'refund' |
| 910 |
} |
| 911 |
) |
| 912 |
->next |
| 913 |
->delete; |
| 914 |
|
| 915 |
my $item = $builder->build_sample_item( |
| 916 |
{ |
| 917 |
homebranch => $specific_rule_restore->{branchcode}, |
| 918 |
holdingbranch => $specific_rule_false->{branchcode} |
| 919 |
} |
| 920 |
); |
| 921 |
my $params = { |
| 922 |
return_branch => $specific_rule_refund->{ branchcode }, |
| 923 |
item => $item |
| 924 |
}; |
| 925 |
|
| 926 |
# Specific rules |
| 927 |
t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' ); |
| 928 |
is( Koha::CirculationRules->get_processingreturn_policy( $params ), |
| 929 |
'refund','Specific rule for checkin branch is applied (refund)'); |
| 930 |
|
| 931 |
t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHomeBranch' ); |
| 932 |
is( Koha::CirculationRules->get_processingreturn_policy( $params ), |
| 933 |
'restore','Specific rule for home branch is applied (restore)'); |
| 934 |
|
| 935 |
t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHoldingBranch' ); |
| 936 |
is( Koha::CirculationRules->get_processingreturn_policy( $params ), |
| 937 |
0,'Specific rule for holding branch is applied (false)'); |
| 938 |
|
| 939 |
# Default rule check |
| 940 |
t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' ); |
| 941 |
$params->{return_branch} = $branch_without_rule; |
| 942 |
is( Koha::CirculationRules->get_processingreturn_policy( $params ), |
| 943 |
'charge','No rule for branch, global rule applied (charge)'); |
| 944 |
|
| 945 |
# Change the default value just to try |
| 946 |
Koha::CirculationRules->search({ branchcode => undef, rule_name => 'processingreturn' })->next->rule_value(0)->store; |
| 947 |
is( Koha::CirculationRules->get_processingreturn_policy( $params ), |
| 948 |
0,'No rule for branch, global rule applied (false)'); |
| 949 |
|
| 950 |
# No default rule defined check |
| 951 |
Koha::CirculationRules |
| 952 |
->search( |
| 953 |
{ |
| 954 |
branchcode => undef, |
| 955 |
categorycode => undef, |
| 956 |
itemtype => undef, |
| 957 |
rule_name => 'processingreturn' |
| 958 |
} |
| 959 |
) |
| 960 |
->next |
| 961 |
->delete; |
| 962 |
is( Koha::CirculationRules->get_processingreturn_policy( $params ), |
| 963 |
'refund','No rule for branch, no default rule, fallback default (refund)'); |
| 964 |
|
| 965 |
# Fallback to ItemHoldBranch if CheckinLibrary is undefined |
| 966 |
$params->{return_branch} = undef; |
| 967 |
is( Koha::CirculationRules->get_processingreturn_policy( $params ), |
| 968 |
'restore','return_branch undefined, fallback to ItemHomeBranch rule (restore)'); |
| 969 |
|
| 970 |
$schema->storage->txn_rollback; |
| 971 |
}; |
| 972 |
|
| 804 |
sub _is_row_match { |
973 |
sub _is_row_match { |
| 805 |
my ( $rule, $expected, $message ) = @_; |
974 |
my ( $rule, $expected, $message ) = @_; |
| 806 |
|
975 |
|
| 807 |
- |
|
|