|
Lines 19-31
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 2; |
22 |
use Test::More tests => 8; |
|
|
23 |
use Test::Exception; |
| 24 |
use Test::Warn; |
| 23 |
|
25 |
|
| 24 |
use t::lib::Mocks; |
26 |
use t::lib::Mocks; |
| 25 |
use t::lib::TestBuilder; |
27 |
use t::lib::TestBuilder; |
| 26 |
|
28 |
|
| 27 |
use Data::Dumper; |
29 |
use Time::Fake; |
| 28 |
|
|
|
| 29 |
use C4::Calendar; |
30 |
use C4::Calendar; |
| 30 |
use Koha::DateUtils qw(dt_from_string); |
31 |
use Koha::DateUtils qw(dt_from_string); |
| 31 |
|
32 |
|
|
Lines 59-67
my $itemtype = $builder->build_object(
Link Here
|
| 59 |
class => 'Koha::ItemTypes', |
60 |
class => 'Koha::ItemTypes', |
| 60 |
value => { |
61 |
value => { |
| 61 |
rentalcharge_daily => '0.00', |
62 |
rentalcharge_daily => '0.00', |
| 62 |
rentalcharge => '0.00', |
63 |
rentalcharge => '0.00', |
| 63 |
processfee => '0.00', |
64 |
processfee => '0.00', |
| 64 |
defaultreplacecost => '0.00', |
65 |
defaultreplacecost => '0.00', |
| 65 |
}, |
66 |
}, |
| 66 |
} |
67 |
} |
| 67 |
); |
68 |
); |
|
Lines 86-107
my $patron = $builder->build_object(
Link Here
|
| 86 |
} |
87 |
} |
| 87 |
); |
88 |
); |
| 88 |
|
89 |
|
| 89 |
my $dt_from = dt_from_string(); |
90 |
my $dt = dt_from_string(); |
| 90 |
my $dt_to = dt_from_string()->add( days => 6 ); |
91 |
Time::Fake->offset( $dt->epoch ); |
| 91 |
|
92 |
|
| 92 |
my $fees = Koha::Charges::Fees->new( |
93 |
my $dt_from = dt_from_string()->subtract( days => 2 ); |
| 93 |
{ |
94 |
my $dt_to = dt_from_string()->add( days => 4 ); |
| 94 |
patron => $patron, |
95 |
|
| 95 |
library => $library, |
96 |
subtest 'new' => sub { |
| 96 |
item => $item, |
97 |
plan tests => 9; |
| 97 |
to_date => $dt_to, |
98 |
|
| 98 |
from_date => $dt_from, |
99 |
# Mandatory parameters missing |
|
|
100 |
throws_ok { |
| 101 |
Koha::Charges::Fees->new( |
| 102 |
{ |
| 103 |
library => $library, |
| 104 |
item => $item, |
| 105 |
to_date => $dt_to, |
| 106 |
} |
| 107 |
) |
| 99 |
} |
108 |
} |
| 100 |
); |
109 |
'Koha::Exceptions::MissingParameter', 'MissingParameter thrown for patron'; |
|
|
110 |
throws_ok { |
| 111 |
Koha::Charges::Fees->new( |
| 112 |
{ |
| 113 |
patron => $patron, |
| 114 |
item => $item, |
| 115 |
to_date => $dt_to, |
| 116 |
} |
| 117 |
) |
| 118 |
} |
| 119 |
'Koha::Exceptions::MissingParameter', 'MissingParameter thrown for library'; |
| 120 |
throws_ok { |
| 121 |
Koha::Charges::Fees->new( |
| 122 |
{ |
| 123 |
patron => $patron, |
| 124 |
library => $library, |
| 125 |
to_date => $dt_to, |
| 126 |
} |
| 127 |
) |
| 128 |
} |
| 129 |
'Koha::Exceptions::MissingParameter', 'MissingParameter thrown for item'; |
| 130 |
throws_ok { |
| 131 |
Koha::Charges::Fees->new( |
| 132 |
{ |
| 133 |
patron => $patron, |
| 134 |
library => $library, |
| 135 |
item => $item, |
| 136 |
} |
| 137 |
) |
| 138 |
} |
| 139 |
'Koha::Exceptions::MissingParameter', 'MissingParameter thrown for to_date'; |
| 140 |
|
| 141 |
# Mandatory parameter bad |
| 142 |
dies_ok { |
| 143 |
Koha::Charges::Fees->new( |
| 144 |
{ |
| 145 |
patron => '12345', |
| 146 |
library => $library, |
| 147 |
item => $item, |
| 148 |
to_date => $dt_to, |
| 149 |
} |
| 150 |
) |
| 151 |
} |
| 152 |
'dies for bad patron'; |
| 153 |
dies_ok { |
| 154 |
Koha::Charges::Fees->new( |
| 155 |
{ |
| 156 |
patron => $patron, |
| 157 |
library => '12345', |
| 158 |
item => $item, |
| 159 |
to_date => $dt_to, |
| 160 |
} |
| 161 |
) |
| 162 |
} |
| 163 |
'dies for bad library'; |
| 164 |
dies_ok { |
| 165 |
Koha::Charges::Fees->new( |
| 166 |
{ |
| 167 |
patron => $patron, |
| 168 |
library => $library, |
| 169 |
item => '12345', |
| 170 |
to_date => $dt_to, |
| 171 |
} |
| 172 |
) |
| 173 |
} |
| 174 |
'dies for bad item'; |
| 175 |
dies_ok { |
| 176 |
Koha::Charges::Fees->new( |
| 177 |
{ |
| 178 |
patron => $patron, |
| 179 |
library => $library, |
| 180 |
item => $item, |
| 181 |
to_date => 12345 |
| 182 |
} |
| 183 |
) |
| 184 |
} |
| 185 |
'dies for bad to_date'; |
| 186 |
|
| 187 |
# Defaults |
| 188 |
my $fees = Koha::Charges::Fees->new( |
| 189 |
{ |
| 190 |
patron => $patron, |
| 191 |
library => $library, |
| 192 |
item => $item, |
| 193 |
to_date => $dt_to, |
| 194 |
} |
| 195 |
); |
| 196 |
is( $fees->from_date, dt_from_string(), |
| 197 |
'from_date default set correctly to today' ); |
| 198 |
}; |
| 199 |
|
| 200 |
subtest 'patron accessor' => sub { |
| 201 |
plan tests => 2; |
| 202 |
|
| 203 |
my $fees = Koha::Charges::Fees->new( |
| 204 |
{ |
| 205 |
patron => $patron, |
| 206 |
library => $library, |
| 207 |
item => $item, |
| 208 |
to_date => $dt_to, |
| 209 |
} |
| 210 |
); |
| 211 |
|
| 212 |
ok( |
| 213 |
$fees->patron->isa('Koha::Patron'), |
| 214 |
'patron accessor returns a Koha::Patron' |
| 215 |
); |
| 216 |
warning_is { $fees->patron('12345') } |
| 217 |
{ carped => |
| 218 |
"Setting 'patron' to something other than a Koha::Patron is not supported!" |
| 219 |
}, "Warning thrown when attempting to set patron to string"; |
| 220 |
|
| 221 |
}; |
| 222 |
|
| 223 |
subtest 'library accessor' => sub { |
| 224 |
plan tests => 2; |
| 225 |
|
| 226 |
my $fees = Koha::Charges::Fees->new( |
| 227 |
{ |
| 228 |
patron => $patron, |
| 229 |
library => $library, |
| 230 |
item => $item, |
| 231 |
to_date => $dt_to, |
| 232 |
} |
| 233 |
); |
| 234 |
|
| 235 |
ok( |
| 236 |
$fees->library->isa('Koha::Library'), |
| 237 |
'library accessor returns a Koha::Library' |
| 238 |
); |
| 239 |
warning_is { $fees->library('12345') } |
| 240 |
{ carped => |
| 241 |
"Setting 'library' to something other than a Koha::Library is not supported!" |
| 242 |
}, "Warning thrown when attempting to set library to string"; |
| 243 |
}; |
| 244 |
|
| 245 |
subtest 'item accessor' => sub { |
| 246 |
plan tests => 2; |
| 247 |
|
| 248 |
my $fees = Koha::Charges::Fees->new( |
| 249 |
{ |
| 250 |
patron => $patron, |
| 251 |
library => $library, |
| 252 |
item => $item, |
| 253 |
to_date => $dt_to, |
| 254 |
} |
| 255 |
); |
| 256 |
|
| 257 |
ok( $fees->item->isa('Koha::Item'), 'item accessor returns a Koha::Item' ); |
| 258 |
warning_is { $fees->item('12345') } |
| 259 |
{ carped => |
| 260 |
"Setting 'item' to something other than a Koha::Item is not supported!" |
| 261 |
}, "Warning thrown when attempting to set item to string"; |
| 262 |
}; |
| 263 |
|
| 264 |
subtest 'to_date accessor' => sub { |
| 265 |
plan tests => 2; |
| 266 |
|
| 267 |
my $fees = Koha::Charges::Fees->new( |
| 268 |
{ |
| 269 |
patron => $patron, |
| 270 |
library => $library, |
| 271 |
item => $item, |
| 272 |
to_date => $dt_to, |
| 273 |
} |
| 274 |
); |
| 275 |
|
| 276 |
ok( $fees->to_date->isa('DateTime'), |
| 277 |
'to_date accessor returns a DateTime' ); |
| 278 |
warning_is { $fees->to_date(12345) } |
| 279 |
{ carped => |
| 280 |
"Setting 'to_date' to something other than a DateTime is not supported!" |
| 281 |
}, "Warning thrown when attempting to set to_date to integer"; |
| 282 |
}; |
| 283 |
|
| 284 |
subtest 'from_date accessor' => sub { |
| 285 |
plan tests => 2; |
| 286 |
|
| 287 |
my $fees = Koha::Charges::Fees->new( |
| 288 |
{ |
| 289 |
patron => $patron, |
| 290 |
library => $library, |
| 291 |
item => $item, |
| 292 |
to_date => $dt_to, |
| 293 |
} |
| 294 |
); |
| 295 |
|
| 296 |
ok( |
| 297 |
$fees->from_date->isa('DateTime'), |
| 298 |
'from_date accessor returns a DateTime' |
| 299 |
); |
| 300 |
warning_is { $fees->from_date(12345) } |
| 301 |
{ carped => |
| 302 |
"Setting 'from_date' to something other than a DateTime is not supported!" |
| 303 |
}, "Warning thrown when attempting to set from_date to integer"; |
| 304 |
}; |
| 101 |
|
305 |
|
| 102 |
subtest 'accumulate_rentalcharge tests' => sub { |
306 |
subtest 'accumulate_rentalcharge tests' => sub { |
| 103 |
plan tests => 4; |
307 |
plan tests => 4; |
| 104 |
|
308 |
|
|
|
309 |
my $fees = Koha::Charges::Fees->new( |
| 310 |
{ |
| 311 |
patron => $patron, |
| 312 |
library => $library, |
| 313 |
item => $item, |
| 314 |
to_date => $dt_to, |
| 315 |
from_date => $dt_from, |
| 316 |
} |
| 317 |
); |
| 318 |
|
| 105 |
$itemtype->rentalcharge_daily(1.00); |
319 |
$itemtype->rentalcharge_daily(1.00); |
| 106 |
$itemtype->store(); |
320 |
$itemtype->store(); |
| 107 |
is( $itemtype->rentalcharge_daily, |
321 |
is( $itemtype->rentalcharge_daily, |
|
Lines 109-119
subtest 'accumulate_rentalcharge tests' => sub {
Link Here
|
| 109 |
|
323 |
|
| 110 |
t::lib::Mocks::mock_preference( 'finesCalendar', 'ignoreCalendar' ); |
324 |
t::lib::Mocks::mock_preference( 'finesCalendar', 'ignoreCalendar' ); |
| 111 |
my $charge = $fees->accumulate_rentalcharge(); |
325 |
my $charge = $fees->accumulate_rentalcharge(); |
| 112 |
is( $charge, 6.00, 'Daily rental charge calculated correctly with finesCalendar = ignoreCalendar' ); |
326 |
is( $charge, 6.00, |
|
|
327 |
'Daily rental charge calculated correctly with finesCalendar = ignoreCalendar' |
| 328 |
); |
| 113 |
|
329 |
|
| 114 |
t::lib::Mocks::mock_preference( 'finesCalendar', 'noFinesWhenClosed' ); |
330 |
t::lib::Mocks::mock_preference( 'finesCalendar', 'noFinesWhenClosed' ); |
| 115 |
$charge = $fees->accumulate_rentalcharge(); |
331 |
$charge = $fees->accumulate_rentalcharge(); |
| 116 |
is( $charge, 6.00, 'Daily rental charge calculated correctly with finesCalendar = noFinesWhenClosed' ); |
332 |
is( $charge, 6.00, |
|
|
333 |
'Daily rental charge calculated correctly with finesCalendar = noFinesWhenClosed' |
| 334 |
); |
| 117 |
|
335 |
|
| 118 |
my $calendar = C4::Calendar->new( branchcode => $library->id ); |
336 |
my $calendar = C4::Calendar->new( branchcode => $library->id ); |
| 119 |
$calendar->insert_week_day_holiday( |
337 |
$calendar->insert_week_day_holiday( |
|
Lines 122-126
subtest 'accumulate_rentalcharge tests' => sub {
Link Here
|
| 122 |
description => 'Test holiday' |
340 |
description => 'Test holiday' |
| 123 |
); |
341 |
); |
| 124 |
$charge = $fees->accumulate_rentalcharge(); |
342 |
$charge = $fees->accumulate_rentalcharge(); |
| 125 |
is( $charge, 5.00, 'Daily rental charge calculated correctly with finesCalendar = noFinesWhenClosed and closed Wednesdays' ); |
343 |
is( $charge, 5.00, |
|
|
344 |
'Daily rental charge calculated correctly with finesCalendar = noFinesWhenClosed and closed Wednesdays' |
| 345 |
); |
| 126 |
}; |
346 |
}; |
| 127 |
- |
347 |
|
|
|
348 |
Time::Fake->reset; |