Lines 2351-2443
subtest 'get_lists_with_patron() tests' => sub {
Link Here
|
2351 |
$schema->storage->txn_rollback; |
2351 |
$schema->storage->txn_rollback; |
2352 |
}; |
2352 |
}; |
2353 |
|
2353 |
|
2354 |
subtest 'guarantor requirements tests' => sub { |
2354 |
subtest 'validate_guarantor() tests' => sub { |
2355 |
|
2355 |
|
2356 |
plan tests => 6; |
2356 |
plan tests => 5; |
2357 |
|
2357 |
|
2358 |
$schema->storage->txn_begin; |
2358 |
$schema->storage->txn_begin; |
2359 |
|
2359 |
|
2360 |
my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; |
2360 |
my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; |
2361 |
my $child_category = |
2361 |
my $guarantee_category = |
2362 |
$builder->build( { source => 'Category', value => { category_type => 'C', can_be_guarantee => 1 } } ) |
2362 |
$builder->build( |
2363 |
->{categorycode}; |
2363 |
{ source => 'Category', value => { categorycode => "GUARANTEE", category_type => 'C', can_be_guarantee => 1 } } |
2364 |
my $patron_category = |
2364 |
); |
2365 |
$builder->build( { source => 'Category', value => { category_type => 'A', can_be_guarantee => 0 } } ) |
2365 |
my $guarantor_category = |
2366 |
->{categorycode}; |
2366 |
$builder->build( |
2367 |
|
2367 |
{ source => 'Category', value => { categorycode => "GUARANTOR", category_type => 'A', can_be_guarantee => 0 } } |
2368 |
t::lib::Mocks::mock_preference( 'ChildNeedsGuarantor', 0 ); |
2368 |
); |
2369 |
|
2369 |
|
2370 |
my $child = Koha::Patron->new( |
2370 |
my $child = Koha::Patron->new( |
2371 |
{ |
2371 |
{ |
2372 |
branchcode => $branchcode, |
2372 |
branchcode => $branchcode, |
2373 |
categorycode => $child_category, |
2373 |
categorycode => $guarantee_category->{categorycode}, |
2374 |
contactname => '' |
|
|
2375 |
} |
2376 |
); |
2377 |
$child->store(); |
2378 |
|
2379 |
ok( |
2380 |
Koha::Patrons->find( $child->id ), |
2381 |
'Child patron can be stored without guarantor when ChildNeedsGuarantor is off.' |
2382 |
); |
2383 |
|
2384 |
t::lib::Mocks::mock_preference( 'ChildNeedsGuarantor', 1 ); |
2385 |
|
2386 |
my $child2 = Koha::Patron->new( |
2387 |
{ |
2388 |
branchcode => $branchcode, |
2389 |
categorycode => $child_category, |
2390 |
contactname => '' |
2374 |
contactname => '' |
2391 |
} |
2375 |
} |
2392 |
); |
2376 |
); |
2393 |
my $child3 = $builder->build_object( |
2377 |
my $child2 = $builder->build_object( |
2394 |
{ |
2378 |
{ |
2395 |
class => 'Koha::Patrons', |
2379 |
class => 'Koha::Patrons', |
2396 |
value => { categorycode => $child_category } |
2380 |
value => { categorycode => $guarantee_category->{categorycode} } |
2397 |
} |
2381 |
} |
2398 |
); |
2382 |
); |
2399 |
my $patron = $builder->build_object( |
2383 |
my $patron = $builder->build_object( |
2400 |
{ |
2384 |
{ |
2401 |
class => 'Koha::Patrons', |
2385 |
class => 'Koha::Patrons', |
2402 |
value => { categorycode => $patron_category } |
2386 |
value => { categorycode => $guarantor_category->{categorycode} } |
2403 |
} |
2387 |
} |
2404 |
); |
2388 |
); |
2405 |
|
2389 |
|
2406 |
throws_ok { $child2->store(); } |
2390 |
my @guarantors; |
|
|
2391 |
my $contactname = ""; |
2392 |
my $category = Koha::Patron::Categories->find( $guarantee_category->{categorycode} ); |
2393 |
|
2394 |
t::lib::Mocks::mock_preference( 'ChildNeedsGuarantor', 0 ); |
2395 |
|
2396 |
lives_ok { $child->validate_guarantor( \@guarantors, $contactname, $category ); } |
2397 |
'Validation passes when ChildNeedsGuarantor syspref is disabled'; |
2398 |
|
2399 |
t::lib::Mocks::mock_preference( 'ChildNeedsGuarantor', 1 ); |
2400 |
|
2401 |
throws_ok { $child->validate_guarantor( \@guarantors, $contactname, $category ); } |
2407 |
'Koha::Exceptions::Patron::Relationship::NoGuarantor', |
2402 |
'Koha::Exceptions::Patron::Relationship::NoGuarantor', |
2408 |
'Exception thrown when guarantor is required but not provided.'; |
2403 |
'Exception thrown when guarantor is required but not provided.'; |
2409 |
|
2404 |
|
2410 |
my @guarantors = ( $patron, $child3 ); |
2405 |
@guarantors = ( $patron, $child2 ); |
2411 |
throws_ok { $child2->store( { guarantors => \@guarantors } ); } |
2406 |
throws_ok { $child->validate_guarantor( \@guarantors, $contactname, $category ); } |
2412 |
'Koha::Exceptions::Patron::Relationship::InvalidRelationship', |
2407 |
'Koha::Exceptions::Patron::Relationship::InvalidRelationship', |
2413 |
'Exception thrown when child patron is added as guarantor.'; |
2408 |
'Exception thrown when child patron is added as guarantor.'; |
2414 |
|
2409 |
|
2415 |
#test ModMember |
|
|
2416 |
@guarantors = ($patron); |
2410 |
@guarantors = ($patron); |
2417 |
$child2->store( { guarantors => \@guarantors } )->discard_changes(); |
2411 |
lives_ok { $child->validate_guarantor( \@guarantors, undef, $category ); } |
2418 |
|
2412 |
'Validation passes when valid guarantors are passed in array'; |
2419 |
t::lib::Mocks::mock_preference( 'borrowerRelationship', '' ); |
|
|
2420 |
|
2413 |
|
2421 |
my $relationship = Koha::Patron::Relationship->new( |
2414 |
@guarantors = (); |
2422 |
{ |
2415 |
$contactname = "Guarantor"; |
2423 |
guarantor_id => $patron->borrowernumber, |
2416 |
lives_ok { $child->validate_guarantor( \@guarantors, $contactname, $category ); } |
2424 |
guarantee_id => $child2->borrowernumber, |
2417 |
'Validation passes when guarantor contanct name is passed'; |
2425 |
relationship => '' |
|
|
2426 |
} |
2427 |
); |
2428 |
$relationship->store(); |
2429 |
|
2430 |
ok( $child2->store(), 'Child patron can be modified and stored when guarantor is stored' ); |
2431 |
|
2432 |
@guarantors = ($child3); |
2433 |
throws_ok { $child2->store( { guarantors => \@guarantors } ); } |
2434 |
'Koha::Exceptions::Patron::Relationship::InvalidRelationship', |
2435 |
'Exception thrown when child patron is modified and child patron is added as guarantor.'; |
2436 |
|
2437 |
$relationship->delete; |
2438 |
throws_ok { $child2->store(); } |
2439 |
'Koha::Exceptions::Patron::Relationship::NoGuarantor', |
2440 |
'Exception thrown when guarantor is deleted.'; |
2441 |
|
2418 |
|
2442 |
$schema->storage->txn_rollback; |
2419 |
$schema->storage->txn_rollback; |
2443 |
}; |
2420 |
}; |
2444 |
- |
|
|