Lines 16-23
Link Here
|
16 |
|
16 |
|
17 |
use Modern::Perl; |
17 |
use Modern::Perl; |
18 |
|
18 |
|
19 |
use Test::NoWarnings; |
19 |
use Test::More tests => 8; |
20 |
use Test::More tests => 6; |
20 |
use Test::Warn; |
21 |
|
21 |
|
22 |
use C4::Overdues qw(CalcFine); |
22 |
use C4::Overdues qw(CalcFine); |
23 |
|
23 |
|
Lines 34-69
BEGIN {
Link Here
|
34 |
use_ok('C4::Overdues'); |
34 |
use_ok('C4::Overdues'); |
35 |
use_ok('Koha::Plugins'); |
35 |
use_ok('Koha::Plugins'); |
36 |
use_ok('Koha::Plugins::Handler'); |
36 |
use_ok('Koha::Plugins::Handler'); |
|
|
37 |
use_ok('Koha::Plugin::1_CalcFineEmpty'); |
38 |
use_ok('Koha::Plugin::2_CalcFineNotEmpty'); |
39 |
use_ok('Koha::Plugin::3_CalcFineBadValue'); |
37 |
use_ok('Koha::Plugin::Test'); |
40 |
use_ok('Koha::Plugin::Test'); |
38 |
} |
41 |
} |
39 |
|
42 |
|
40 |
t::lib::Mocks::mock_config( 'enable_plugins', 1 ); |
43 |
t::lib::Mocks::mock_config( 'enable_plugins', 1 ); |
41 |
|
44 |
|
42 |
my $builder = t::lib::TestBuilder->new; |
45 |
my $builder = t::lib::TestBuilder->new; |
43 |
|
46 |
my $schema = Koha::Database->new->schema; |
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 |
|
47 |
|
58 |
subtest 'overwrite_calc_fine hook tests' => sub { |
48 |
subtest 'overwrite_calc_fine hook tests' => sub { |
59 |
plan tests => 6; |
|
|
60 |
|
49 |
|
61 |
my $schema = Koha::Database->new->schema; |
50 |
plan tests => 13; |
|
|
51 |
|
62 |
$schema->storage->txn_begin; |
52 |
$schema->storage->txn_begin; |
63 |
|
53 |
|
64 |
my $plugins = Koha::Plugins->new; |
54 |
my $library = $builder->build_object( { class => 'Koha::Libraries', } ); |
65 |
$plugins->InstallPlugins; |
55 |
my $category = $builder->build_object( { class => 'Koha::Patron::Categories', } ); |
66 |
Koha::Plugin::Test->new->enable; |
56 |
my $item = $builder->build_sample_item; |
|
|
57 |
|
58 |
Koha::Plugins->new->InstallPlugins(); |
59 |
my $test_plugin = Koha::Plugin::Test->new->disable(); |
67 |
|
60 |
|
68 |
Koha::CirculationRules->set_rules( |
61 |
Koha::CirculationRules->set_rules( |
69 |
{ |
62 |
{ |
Lines 93-111
subtest 'overwrite_calc_fine hook tests' => sub {
Link Here
|
93 |
day => 30, |
86 |
day => 30, |
94 |
); |
87 |
); |
95 |
|
88 |
|
96 |
my ( $amount, $units, $chargable_units ) = CalcFine( $item->{itemnumber}, undef, undef, $due_date, $end_date ); |
89 |
my ( $amount, $units, $chargable_units ) = |
97 |
|
90 |
CalcFine( $item->unblessed, $category->categorycode, $library->branchcode, $due_date, $end_date ); |
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->{itemnumber}, $category->{categorycode}, $branch->{branchcode}, $due_date, $end_date ); |
104 |
|
91 |
|
105 |
is( $amount, 58, 'Amount is calculated correctly with original function' ); |
92 |
is( $amount, 58, 'Amount is calculated correctly with original function' ); |
106 |
is( $units, 29, 'Units are calculated correctly with original function' ); |
93 |
is( $units, 29, 'Units are calculated correctly with original function' ); |
107 |
is( $chargable_units, 29, 'Chargable units are calculated correctly with original function' ); |
94 |
is( $chargable_units, 29, 'Chargable units are calculated correctly with original function' ); |
108 |
|
95 |
|
109 |
Koha::Plugins->RemovePlugins; |
96 |
# initialize undef value plugin |
|
|
97 |
my $empty_value_plugin = Koha::Plugin::1_CalcFineEmpty->new->enable(); |
98 |
( $amount, $units, $chargable_units ) = |
99 |
CalcFine( $item->unblessed, $category->categorycode, $library->branchcode, $due_date, $end_date ); |
100 |
|
101 |
is( $amount, 58, 'Amount is calculated correctly with original function, undef plugin skipped' ); |
102 |
is( $units, 29, 'Units are calculated correctly with original function, undef plugin skipped' ); |
103 |
is( $chargable_units, 29, 'Chargable units are calculated correctly with original function, undef plugin skipped' ); |
104 |
|
105 |
# initialize valid value plugin |
106 |
my $not_empty_value_plugin = Koha::Plugin::2_CalcFineNotEmpty->new->enable(); |
107 |
|
108 |
( $amount, $units, $chargable_units ) = CalcFine( $item->unblessed, undef, undef, $due_date, $end_date ); |
109 |
|
110 |
is( $amount, 1, 'Amount is calculated correctly with custom function' ); |
111 |
is( $units, 2, 'Units are calculated correctly with custom function' ); |
112 |
is( $chargable_units, 3, 'Chargable units are calculated correctly with custom function' ); |
113 |
|
114 |
# initialize bad value plugin |
115 |
my $bad_value_plugin = Koha::Plugin::3_CalcFineBadValue->new->enable(); |
116 |
$not_empty_value_plugin->disable(); |
117 |
|
118 |
( $amount, $units, $chargable_units ) = CalcFine( $item->unblessed, undef, undef, $due_date, $end_date ); |
119 |
|
120 |
is( $amount, 'a', 'Amount is calculated correctly with custom function, bad value returned anyway' ); |
121 |
is( $units, 'b', 'Units are calculated correctly with custom function, bad value returned anyway' ); |
122 |
is( |
123 |
$chargable_units, undef, |
124 |
'Chargable units are calculated correctly with custom function, bad value returned anyway' |
125 |
); |
126 |
|
127 |
Koha::Plugin::Test->new->enable(); |
128 |
|
129 |
$empty_value_plugin->disable(); |
130 |
$bad_value_plugin->disable(); |
131 |
|
132 |
my $itemnumber = $item->itemnumber; |
133 |
my $branchcode = $library->branchcode; |
134 |
my $categorycode = $category->categorycode; |
135 |
|
136 |
warnings_like { CalcFine( $item->unblessed, $category->categorycode, $library->branchcode, $due_date, $end_date ); } |
137 |
[ |
138 |
qr/itemnumber:$itemnumber/, |
139 |
qr/branchcode:$branchcode/, |
140 |
qr/categorycode:$categorycode/, |
141 |
qr/due_date_type:DateTime/, |
142 |
qr/end_date_type:DateTime/ |
143 |
], |
144 |
'Parameters are correct'; |
145 |
|
146 |
Koha::Plugins->RemovePlugins(); |
147 |
|
110 |
$schema->storage->txn_rollback; |
148 |
$schema->storage->txn_rollback; |
111 |
}; |
149 |
}; |