Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
2 |
|
3 |
# This file is part of Koha. |
4 |
# |
5 |
# Koha is free software; you can redistribute it and/or modify it under the |
6 |
# terms of the GNU General Public License as published by the Free Software |
7 |
# Foundation; either version 3 of the License, or (at your option) any later |
8 |
# version. |
9 |
# |
10 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
11 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
12 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
13 |
# |
14 |
# You should have received a copy of the GNU General Public License along |
15 |
# with Koha; if not, see <http://www.gnu.org/licenses>. |
16 |
|
17 |
use Modern::Perl; |
18 |
|
19 |
use Test::NoWarnings; |
20 |
use Test::More tests => 6; |
21 |
|
22 |
use C4::Overdues qw(CalcFine); |
23 |
|
24 |
use File::Basename; |
25 |
|
26 |
use t::lib::Mocks; |
27 |
use t::lib::TestBuilder; |
28 |
|
29 |
BEGIN { |
30 |
# Mock pluginsdir before loading Plugins module |
31 |
my $path = dirname(__FILE__) . '/../../../lib/plugins'; |
32 |
t::lib::Mocks::mock_config( 'pluginsdir', $path ); |
33 |
|
34 |
use_ok('C4::Overdues'); |
35 |
use_ok('Koha::Plugins'); |
36 |
use_ok('Koha::Plugins::Handler'); |
37 |
use_ok('Koha::Plugin::Test'); |
38 |
} |
39 |
|
40 |
t::lib::Mocks::mock_config( 'enable_plugins', 1 ); |
41 |
|
42 |
my $builder = t::lib::TestBuilder->new; |
43 |
|
44 |
my $branch = $builder->build( |
45 |
{ |
46 |
source => 'Branch', |
47 |
} |
48 |
); |
49 |
|
50 |
my $category = $builder->build( |
51 |
{ |
52 |
source => 'Category', |
53 |
} |
54 |
); |
55 |
|
56 |
my $item = $builder->build_sample_item; |
57 |
|
58 |
subtest 'overwrite_calc_fine hook tests' => sub { |
59 |
plan tests => 6; |
60 |
|
61 |
my $schema = Koha::Database->new->schema; |
62 |
$schema->storage->txn_begin; |
63 |
|
64 |
my $plugins = Koha::Plugins->new; |
65 |
$plugins->InstallPlugins; |
66 |
Koha::Plugin::Test->new->enable; |
67 |
|
68 |
Koha::CirculationRules->set_rules( |
69 |
{ |
70 |
branchcode => undef, |
71 |
categorycode => undef, |
72 |
itemtype => undef, |
73 |
rules => { |
74 |
fine => '2.00', |
75 |
lengthunit => 'days', |
76 |
finedays => 0, |
77 |
firstremind => 0, |
78 |
chargeperiod => 1, |
79 |
overduefinescap => '0', |
80 |
cap_fine_to_replacement_price => 0, |
81 |
} |
82 |
}, |
83 |
); |
84 |
|
85 |
my $due_date = DateTime->new( |
86 |
year => 2000, |
87 |
month => 1, |
88 |
day => 1, |
89 |
); |
90 |
my $end_date = DateTime->new( |
91 |
year => 2000, |
92 |
month => 1, |
93 |
day => 30, |
94 |
); |
95 |
|
96 |
my ( $amount, $units, $chargable_units ) = CalcFine( $item->unblessed, undef, undef, $due_date, $end_date ); |
97 |
|
98 |
is( $amount, 87, 'Amount is calculated correctly with custom function' ); |
99 |
is( $units, 29, 'Units are calculated correctly with custom function' ); |
100 |
is( $chargable_units, 27, 'Chargable units are calculated correctly with custom function' ); |
101 |
|
102 |
( $amount, $units, $chargable_units ) = |
103 |
CalcFine( $item->unblessed, $category->{categorycode}, $branch->{branchcode}, $due_date, $end_date ); |
104 |
|
105 |
is( $amount, 58, 'Amount is calculated correctly with original function' ); |
106 |
is( $units, 29, 'Units are calculated correctly with original function' ); |
107 |
is( $chargable_units, 29, 'Chargable units are calculated correctly with original function' ); |
108 |
|
109 |
Koha::Plugins->RemovePlugins; |
110 |
$schema->storage->txn_rollback; |
111 |
}; |