Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 33; |
22 |
use Test::More tests => 35; |
23 |
use Test::Exception; |
23 |
use Test::Exception; |
24 |
use Test::Warn; |
24 |
use Test::Warn; |
25 |
use Time::Fake; |
25 |
use Time::Fake; |
Lines 2246-2251
subtest 'guarantor requirements tests' => sub {
Link Here
|
2246 |
throws_ok { $child2->store(); } |
2246 |
throws_ok { $child2->store(); } |
2247 |
'Koha::Exceptions::Patron::Relationship::NoGuarantor', |
2247 |
'Koha::Exceptions::Patron::Relationship::NoGuarantor', |
2248 |
'Exception thrown when guarantor is deleted.'; |
2248 |
'Exception thrown when guarantor is deleted.'; |
|
|
2249 |
|
2250 |
$schema->storage->txn_rollback; |
2251 |
}; |
2252 |
|
2253 |
subtest 'can_borrow() tests' => sub { |
2254 |
plan tests => 11; |
2255 |
$schema->storage->txn_begin; |
2256 |
|
2257 |
t::lib::Mocks::mock_preference( 'borrowerRelationship', 'parent' ); |
2258 |
|
2259 |
my $patron_category = $builder->build( |
2260 |
{ |
2261 |
source => 'Category', |
2262 |
value => { |
2263 |
categorycode => 'NOT_X', category_type => 'P', enrolmentfee => 0, noissueschargeguarantees => 0, |
2264 |
noissuescharge => 10, noissueschargeguarantorswithguarantees => 0 |
2265 |
} |
2266 |
} |
2267 |
); |
2268 |
|
2269 |
my $patron = $builder->build_object( |
2270 |
{ |
2271 |
class => 'Koha::Patrons', |
2272 |
value => { |
2273 |
categorycode => $patron_category->{categorycode}, |
2274 |
} |
2275 |
} |
2276 |
); |
2277 |
my $patron_borrowing_status; |
2278 |
|
2279 |
$patron->debarred(1); |
2280 |
$patron_borrowing_status = $patron->can_borrow( { patron => $patron } ); |
2281 |
is( $patron_borrowing_status->{can_borrow}, 0, 'Debarred patron blocked from borrowing' ); |
2282 |
is( $patron_borrowing_status->{debarred}, 1, 'Blocker correctly identified and returned' ); |
2283 |
$patron->debarred(0); |
2284 |
|
2285 |
$patron->dateexpiry( dt_from_string->subtract( days => 1 ) ); |
2286 |
$patron_borrowing_status = $patron->can_borrow( { patron => $patron } ); |
2287 |
is( $patron_borrowing_status->{can_borrow}, 0, 'Expired patron blocked from borrowing' ); |
2288 |
is( $patron_borrowing_status->{expired}, 1, 'Blocker correctly identified and returned' ); |
2289 |
$patron->dateexpiry(undef); |
2290 |
|
2291 |
my $child = $builder->build_object( { class => 'Koha::Patrons' } ); |
2292 |
my $sibling = $builder->build_object( { class => 'Koha::Patrons' } ); |
2293 |
$child->add_guarantor( { guarantor_id => $patron->borrowernumber, relationship => 'parent' } ); |
2294 |
$sibling->add_guarantor( { guarantor_id => $patron->borrowernumber, relationship => 'parent' } ); |
2295 |
|
2296 |
t::lib::Mocks::mock_preference( 'noissuescharge', 50 ); |
2297 |
|
2298 |
my $fee1 = $builder->build_object( |
2299 |
{ |
2300 |
class => 'Koha::Account::Lines', |
2301 |
value => { |
2302 |
borrowernumber => $patron->borrowernumber, |
2303 |
amountoutstanding => 11, |
2304 |
debit_type_code => 'OVERDUE', |
2305 |
} |
2306 |
} |
2307 |
)->store; |
2308 |
|
2309 |
my $fee2 = $builder->build_object( |
2310 |
{ |
2311 |
class => 'Koha::Account::Lines', |
2312 |
value => { |
2313 |
borrowernumber => $child->borrowernumber, |
2314 |
amountoutstanding => 0.11, |
2315 |
debit_type_code => 'OVERDUE', |
2316 |
} |
2317 |
} |
2318 |
)->store; |
2319 |
|
2320 |
my $fee3 = $builder->build_object( |
2321 |
{ |
2322 |
class => 'Koha::Account::Lines', |
2323 |
value => { |
2324 |
borrowernumber => $sibling->borrowernumber, |
2325 |
amountoutstanding => 11.11, |
2326 |
debit_type_code => 'OVERDUE', |
2327 |
} |
2328 |
} |
2329 |
)->store; |
2330 |
|
2331 |
$patron_borrowing_status = $patron->can_borrow( { patron => $patron } ); |
2332 |
|
2333 |
is( $patron_borrowing_status->{noissuescharge}->{charge}, 11, "Only patron's fines are reported in total" ); |
2334 |
is( $patron_borrowing_status->{noissuescharge}->{limit}, 10, "Limit correctly identified at category level" ); |
2335 |
is( $patron_borrowing_status->{noissuescharge}->{overlimit}, 1, "Patron is over the charge limit" ); |
2336 |
is( $patron_borrowing_status->{can_borrow}, 0, "Patron is over the charge limit and is blocked from borrowing" ); |
2337 |
$patron->category->noissuescharge(undef); |
2338 |
|
2339 |
$patron_borrowing_status = $patron->can_borrow( { patron => $patron } ); |
2340 |
is( $patron_borrowing_status->{noissuescharge}->{limit}, 50, "Limit correctly identified at global syspref level" ); |
2341 |
is( $patron_borrowing_status->{noissuescharge}->{overlimit}, 0, "Patron is within the charge limit" ); |
2342 |
is( $patron_borrowing_status->{can_borrow}, 1, "Patron is within the charge limit and can borrow" ); |
2343 |
|
2344 |
$schema->storage->txn_rollback; |
2345 |
}; |
2346 |
|
2347 |
subtest 'is_patron_inside_charge_limits() tests' => sub { |
2348 |
plan tests => 21; |
2349 |
$schema->storage->txn_begin; |
2350 |
|
2351 |
t::lib::Mocks::mock_preference( 'borrowerRelationship', 'parent' ); |
2352 |
|
2353 |
my $patron_category = $builder->build( |
2354 |
{ |
2355 |
source => 'Category', |
2356 |
value => { |
2357 |
categorycode => 'NOT_X', category_type => 'P', enrolmentfee => 0, noissueschargeguarantees => 0, |
2358 |
noissuescharge => 10, noissueschargeguarantorswithguarantees => 0 |
2359 |
} |
2360 |
} |
2361 |
); |
2362 |
|
2363 |
my $patron = $builder->build_object( |
2364 |
{ |
2365 |
class => 'Koha::Patrons', |
2366 |
value => { |
2367 |
categorycode => $patron_category->{categorycode}, |
2368 |
} |
2369 |
} |
2370 |
); |
2371 |
|
2372 |
my $child = $builder->build_object( { class => 'Koha::Patrons' } ); |
2373 |
my $sibling = $builder->build_object( { class => 'Koha::Patrons' } ); |
2374 |
$child->add_guarantor( { guarantor_id => $patron->borrowernumber, relationship => 'parent' } ); |
2375 |
$sibling->add_guarantor( { guarantor_id => $patron->borrowernumber, relationship => 'parent' } ); |
2376 |
|
2377 |
t::lib::Mocks::mock_preference( 'noissuescharge', 50 ); |
2378 |
t::lib::Mocks::mock_preference( 'NoIssuesChargeGuarantees', 11.01 ); |
2379 |
t::lib::Mocks::mock_preference( 'NoIssuesChargeGuarantorsWithGuarantees', undef ); |
2380 |
|
2381 |
my $fee1 = $builder->build_object( |
2382 |
{ |
2383 |
class => 'Koha::Account::Lines', |
2384 |
value => { |
2385 |
borrowernumber => $patron->borrowernumber, |
2386 |
amountoutstanding => 11, |
2387 |
debit_type_code => 'OVERDUE', |
2388 |
} |
2389 |
} |
2390 |
)->store; |
2391 |
|
2392 |
my $fee2 = $builder->build_object( |
2393 |
{ |
2394 |
class => 'Koha::Account::Lines', |
2395 |
value => { |
2396 |
borrowernumber => $child->borrowernumber, |
2397 |
amountoutstanding => 0.11, |
2398 |
debit_type_code => 'OVERDUE', |
2399 |
} |
2400 |
} |
2401 |
)->store; |
2402 |
|
2403 |
my $fee3 = $builder->build_object( |
2404 |
{ |
2405 |
class => 'Koha::Account::Lines', |
2406 |
value => { |
2407 |
borrowernumber => $sibling->borrowernumber, |
2408 |
amountoutstanding => 11.11, |
2409 |
debit_type_code => 'OVERDUE', |
2410 |
} |
2411 |
} |
2412 |
)->store; |
2413 |
|
2414 |
my $patron_borrowing_status; |
2415 |
$patron_borrowing_status = $patron->is_patron_inside_charge_limits( { patron => $patron } ); |
2416 |
|
2417 |
is( $patron_borrowing_status->{noissuescharge}->{charge}, 11, "Only patron's fines are reported in total" ); |
2418 |
is( $patron_borrowing_status->{noissuescharge}->{limit}, 10, "Limit correctly identified at category level" ); |
2419 |
is( $patron_borrowing_status->{noissuescharge}->{overlimit}, 1, "Patron is over the charge limit" ); |
2420 |
|
2421 |
$patron->category->noissuescharge(undef); |
2422 |
$patron_borrowing_status = $patron->is_patron_inside_charge_limits( { patron => $patron } ); |
2423 |
is( $patron_borrowing_status->{noissuescharge}->{limit}, 50, "Limit correctly identified at global syspref level" ); |
2424 |
is( $patron_borrowing_status->{noissuescharge}->{charge}, 11, "Charges correctly identified" ); |
2425 |
is( $patron_borrowing_status->{noissuescharge}->{overlimit}, 0, "Patron is within the charge limit" ); |
2426 |
|
2427 |
is( |
2428 |
$patron_borrowing_status->{NoIssuesChargeGuarantees}->{limit}, 11.01, |
2429 |
"Limit correctly identified at global syspref level" |
2430 |
); |
2431 |
is( $patron_borrowing_status->{NoIssuesChargeGuarantees}->{charge}, 11.22, "Charges correctly identified" ); |
2432 |
is( $patron_borrowing_status->{NoIssuesChargeGuarantees}->{overlimit}, 1, "Patron is over the charge limit" ); |
2433 |
|
2434 |
$patron->category->noissueschargeguarantees(12); |
2435 |
$patron_borrowing_status = $patron->is_patron_inside_charge_limits( { patron => $patron } ); |
2436 |
is( |
2437 |
$patron_borrowing_status->{NoIssuesChargeGuarantees}->{limit}, 12, |
2438 |
"Limit correctly identified at patron category level" |
2439 |
); |
2440 |
is( $patron_borrowing_status->{NoIssuesChargeGuarantees}->{charge}, 11.22, "Charges correctly identified" ); |
2441 |
is( $patron_borrowing_status->{NoIssuesChargeGuarantees}->{overlimit}, 0, "Patron is inside the charge limit" ); |
2442 |
|
2443 |
is( |
2444 |
$patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{limit}, 0, |
2445 |
"Limit correctly identified as not set at either patron category or global syspref level" |
2446 |
); |
2447 |
is( |
2448 |
$patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{charge}, 22.22, |
2449 |
"Charges correctly identified" |
2450 |
); |
2451 |
is( |
2452 |
$patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{overlimit}, 0, |
2453 |
"Patron is inside the charge limit as no limit has been set" |
2454 |
); |
2455 |
|
2456 |
$patron->category->noissueschargeguarantorswithguarantees(23); |
2457 |
t::lib::Mocks::mock_preference( 'NoIssuesChargeGuarantorsWithGuarantees', 20 ); |
2458 |
$patron_borrowing_status = $patron->is_patron_inside_charge_limits( { patron => $patron } ); |
2459 |
is( |
2460 |
$patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{limit}, 23, |
2461 |
"Limit correctly identified at patron category level" |
2462 |
); |
2463 |
is( |
2464 |
$patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{charge}, 22.22, |
2465 |
"Charges correctly identified" |
2466 |
); |
2467 |
is( |
2468 |
$patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{overlimit}, 0, |
2469 |
"Patron is inside the charge limit" |
2470 |
); |
2471 |
|
2472 |
$patron->category->noissueschargeguarantorswithguarantees(undef); |
2473 |
t::lib::Mocks::mock_preference( 'NoIssuesChargeGuarantorsWithGuarantees', 20 ); |
2474 |
$patron_borrowing_status = $patron->is_patron_inside_charge_limits( { patron => $patron } ); |
2475 |
is( |
2476 |
$patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{limit}, 20, |
2477 |
"Limit correctly defaults to global syspref" |
2478 |
); |
2479 |
is( |
2480 |
$patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{charge}, 22.22, |
2481 |
"Charges correctly identified" |
2482 |
); |
2483 |
is( |
2484 |
$patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{overlimit}, 1, |
2485 |
"Patron is inside the charge limit" |
2486 |
); |
2487 |
|
2488 |
$schema->storage->txn_rollback; |
2249 |
}; |
2489 |
}; |
2250 |
|
2490 |
|
2251 |
subtest 'Scrub the note fields' => sub { |
2491 |
subtest 'Scrub the note fields' => sub { |