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