|
Lines 2429-2521
subtest 'get_lists_with_patron() tests' => sub {
Link Here
|
| 2429 |
$schema->storage->txn_rollback; |
2429 |
$schema->storage->txn_rollback; |
| 2430 |
}; |
2430 |
}; |
| 2431 |
|
2431 |
|
| 2432 |
subtest 'guarantor requirements tests' => sub { |
2432 |
subtest 'validate_guarantor() tests' => sub { |
| 2433 |
|
2433 |
|
| 2434 |
plan tests => 6; |
2434 |
plan tests => 5; |
| 2435 |
|
2435 |
|
| 2436 |
$schema->storage->txn_begin; |
2436 |
$schema->storage->txn_begin; |
| 2437 |
|
2437 |
|
| 2438 |
my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; |
2438 |
my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; |
| 2439 |
my $child_category = |
2439 |
my $guarantee_category = |
| 2440 |
$builder->build( { source => 'Category', value => { category_type => 'C', can_be_guarantee => 1 } } ) |
2440 |
$builder->build( |
| 2441 |
->{categorycode}; |
2441 |
{ source => 'Category', value => { categorycode => "GUARANTEE", category_type => 'C', can_be_guarantee => 1 } } |
| 2442 |
my $patron_category = |
2442 |
); |
| 2443 |
$builder->build( { source => 'Category', value => { category_type => 'A', can_be_guarantee => 0 } } ) |
2443 |
my $guarantor_category = |
| 2444 |
->{categorycode}; |
2444 |
$builder->build( |
| 2445 |
|
2445 |
{ source => 'Category', value => { categorycode => "GUARANTOR", category_type => 'A', can_be_guarantee => 0 } } |
| 2446 |
t::lib::Mocks::mock_preference( 'ChildNeedsGuarantor', 0 ); |
2446 |
); |
| 2447 |
|
2447 |
|
| 2448 |
my $child = Koha::Patron->new( |
2448 |
my $child = Koha::Patron->new( |
| 2449 |
{ |
2449 |
{ |
| 2450 |
branchcode => $branchcode, |
2450 |
branchcode => $branchcode, |
| 2451 |
categorycode => $child_category, |
2451 |
categorycode => $guarantee_category->{categorycode}, |
| 2452 |
contactname => '' |
|
|
| 2453 |
} |
| 2454 |
); |
| 2455 |
$child->store(); |
| 2456 |
|
| 2457 |
ok( |
| 2458 |
Koha::Patrons->find( $child->id ), |
| 2459 |
'Child patron can be stored without guarantor when ChildNeedsGuarantor is off.' |
| 2460 |
); |
| 2461 |
|
| 2462 |
t::lib::Mocks::mock_preference( 'ChildNeedsGuarantor', 1 ); |
| 2463 |
|
| 2464 |
my $child2 = Koha::Patron->new( |
| 2465 |
{ |
| 2466 |
branchcode => $branchcode, |
| 2467 |
categorycode => $child_category, |
| 2468 |
contactname => '' |
2452 |
contactname => '' |
| 2469 |
} |
2453 |
} |
| 2470 |
); |
2454 |
); |
| 2471 |
my $child3 = $builder->build_object( |
2455 |
my $child2 = $builder->build_object( |
| 2472 |
{ |
2456 |
{ |
| 2473 |
class => 'Koha::Patrons', |
2457 |
class => 'Koha::Patrons', |
| 2474 |
value => { categorycode => $child_category } |
2458 |
value => { categorycode => $guarantee_category->{categorycode} } |
| 2475 |
} |
2459 |
} |
| 2476 |
); |
2460 |
); |
| 2477 |
my $patron = $builder->build_object( |
2461 |
my $patron = $builder->build_object( |
| 2478 |
{ |
2462 |
{ |
| 2479 |
class => 'Koha::Patrons', |
2463 |
class => 'Koha::Patrons', |
| 2480 |
value => { categorycode => $patron_category } |
2464 |
value => { categorycode => $guarantor_category->{categorycode} } |
| 2481 |
} |
2465 |
} |
| 2482 |
); |
2466 |
); |
| 2483 |
|
2467 |
|
| 2484 |
throws_ok { $child2->store(); } |
2468 |
my @guarantors; |
|
|
2469 |
my $contactname = ""; |
| 2470 |
my $category = Koha::Patron::Categories->find( $guarantee_category->{categorycode} ); |
| 2471 |
|
| 2472 |
t::lib::Mocks::mock_preference( 'ChildNeedsGuarantor', 0 ); |
| 2473 |
|
| 2474 |
lives_ok { $child->validate_guarantor( \@guarantors, $contactname, $category ); } |
| 2475 |
'Validation passes when ChildNeedsGuarantor syspref is disabled'; |
| 2476 |
|
| 2477 |
t::lib::Mocks::mock_preference( 'ChildNeedsGuarantor', 1 ); |
| 2478 |
|
| 2479 |
throws_ok { $child->validate_guarantor( \@guarantors, $contactname, $category ); } |
| 2485 |
'Koha::Exceptions::Patron::Relationship::NoGuarantor', |
2480 |
'Koha::Exceptions::Patron::Relationship::NoGuarantor', |
| 2486 |
'Exception thrown when guarantor is required but not provided.'; |
2481 |
'Exception thrown when guarantor is required but not provided.'; |
| 2487 |
|
2482 |
|
| 2488 |
my @guarantors = ( $patron, $child3 ); |
2483 |
@guarantors = ( $patron, $child2 ); |
| 2489 |
throws_ok { $child2->store( { guarantors => \@guarantors } ); } |
2484 |
throws_ok { $child->validate_guarantor( \@guarantors, $contactname, $category ); } |
| 2490 |
'Koha::Exceptions::Patron::Relationship::InvalidRelationship', |
2485 |
'Koha::Exceptions::Patron::Relationship::InvalidRelationship', |
| 2491 |
'Exception thrown when child patron is added as guarantor.'; |
2486 |
'Exception thrown when child patron is added as guarantor.'; |
| 2492 |
|
2487 |
|
| 2493 |
#test ModMember |
|
|
| 2494 |
@guarantors = ($patron); |
2488 |
@guarantors = ($patron); |
| 2495 |
$child2->store( { guarantors => \@guarantors } )->discard_changes(); |
2489 |
lives_ok { $child->validate_guarantor( \@guarantors, undef, $category ); } |
| 2496 |
|
2490 |
'Validation passes when valid guarantors are passed in array'; |
| 2497 |
t::lib::Mocks::mock_preference( 'borrowerRelationship', '' ); |
|
|
| 2498 |
|
2491 |
|
| 2499 |
my $relationship = Koha::Patron::Relationship->new( |
2492 |
@guarantors = (); |
| 2500 |
{ |
2493 |
$contactname = "Guarantor"; |
| 2501 |
guarantor_id => $patron->borrowernumber, |
2494 |
lives_ok { $child->validate_guarantor( \@guarantors, $contactname, $category ); } |
| 2502 |
guarantee_id => $child2->borrowernumber, |
2495 |
'Validation passes when guarantor contanct name is passed'; |
| 2503 |
relationship => '' |
|
|
| 2504 |
} |
| 2505 |
); |
| 2506 |
$relationship->store(); |
| 2507 |
|
| 2508 |
ok( $child2->store(), 'Child patron can be modified and stored when guarantor is stored' ); |
| 2509 |
|
| 2510 |
@guarantors = ($child3); |
| 2511 |
throws_ok { $child2->store( { guarantors => \@guarantors } ); } |
| 2512 |
'Koha::Exceptions::Patron::Relationship::InvalidRelationship', |
| 2513 |
'Exception thrown when child patron is modified and child patron is added as guarantor.'; |
| 2514 |
|
| 2515 |
$relationship->delete; |
| 2516 |
throws_ok { $child2->store(); } |
| 2517 |
'Koha::Exceptions::Patron::Relationship::NoGuarantor', |
| 2518 |
'Exception thrown when guarantor is deleted.'; |
| 2519 |
|
2496 |
|
| 2520 |
$schema->storage->txn_rollback; |
2497 |
$schema->storage->txn_rollback; |
| 2521 |
}; |
2498 |
}; |
| 2522 |
- |
|
|