|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 20; |
22 |
use Test::More tests => 21; |
| 23 |
use Test::Exception; |
23 |
use Test::Exception; |
| 24 |
use Test::Warn; |
24 |
use Test::Warn; |
| 25 |
|
25 |
|
|
Lines 1398-1400
subtest 'get_savings tests' => sub {
Link Here
|
| 1398 |
|
1398 |
|
| 1399 |
$schema->storage->txn_rollback; |
1399 |
$schema->storage->txn_rollback; |
| 1400 |
}; |
1400 |
}; |
| 1401 |
- |
1401 |
|
|
|
1402 |
subtest 'guarantor requirements tests' => sub { |
| 1403 |
|
| 1404 |
plan tests => 6; |
| 1405 |
|
| 1406 |
$schema->storage->txn_begin; |
| 1407 |
|
| 1408 |
my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; |
| 1409 |
my $child_category = $builder->build( |
| 1410 |
{ source => 'Category', value => { category_type => 'C' } } ) |
| 1411 |
->{categorycode}; |
| 1412 |
my $patron_category = $builder->build( |
| 1413 |
{ source => 'Category', value => { category_type => 'A' } } ) |
| 1414 |
->{categorycode}; |
| 1415 |
|
| 1416 |
t::lib::Mocks::mock_preference( 'ChildNeedsGuarantor', 0 ); |
| 1417 |
|
| 1418 |
my $child = Koha::Patron->new( |
| 1419 |
{ |
| 1420 |
branchcode => $branchcode, |
| 1421 |
categorycode => $child_category, |
| 1422 |
contactname => '' |
| 1423 |
} |
| 1424 |
); |
| 1425 |
$child->store(); |
| 1426 |
|
| 1427 |
ok( |
| 1428 |
Koha::Patrons->find( $child->id ), |
| 1429 |
'Child patron can be stored without guarantor when ChildNeedsGuarantor is off.' |
| 1430 |
); |
| 1431 |
|
| 1432 |
t::lib::Mocks::mock_preference( 'ChildNeedsGuarantor', 1 ); |
| 1433 |
|
| 1434 |
my $child2 = Koha::Patron->new( |
| 1435 |
{ |
| 1436 |
branchcode => $branchcode, |
| 1437 |
categorycode => $child_category, |
| 1438 |
contactname => '' |
| 1439 |
} |
| 1440 |
); |
| 1441 |
my $child3 = $builder->build_object( |
| 1442 |
{ |
| 1443 |
class => 'Koha::Patrons', |
| 1444 |
value => { categorycode => $child_category } |
| 1445 |
} |
| 1446 |
); |
| 1447 |
my $patron = $builder->build_object( |
| 1448 |
{ |
| 1449 |
class => 'Koha::Patrons', |
| 1450 |
value => { categorycode => $patron_category } |
| 1451 |
} |
| 1452 |
); |
| 1453 |
|
| 1454 |
throws_ok { $child2->store(); } |
| 1455 |
'Koha::Exceptions::Patron::Relationship::NoGuarantor', |
| 1456 |
'Exception thrown when guarantor is required but not provided.'; |
| 1457 |
|
| 1458 |
my @guarantors = ( $patron, $child3 ); |
| 1459 |
throws_ok { $child2->store( { guarantors => \@guarantors } ); } |
| 1460 |
'Koha::Exceptions::Patron::Relationship::InvalidRelationship', |
| 1461 |
'Exception thrown when child patron is added as guarantor.'; |
| 1462 |
|
| 1463 |
#test ModMember |
| 1464 |
@guarantors = ( $patron ); |
| 1465 |
$child2->store( { guarantors => \@guarantors } ); |
| 1466 |
|
| 1467 |
t::lib::Mocks::mock_preference( 'borrowerRelationship', '' ); |
| 1468 |
|
| 1469 |
my $relationship = Koha::Patron::Relationship->new( |
| 1470 |
{ guarantor_id => $patron->borrowernumber, |
| 1471 |
guarantee_id => $child2->borrowernumber, |
| 1472 |
relationship => '' |
| 1473 |
} |
| 1474 |
); |
| 1475 |
$relationship->store(); |
| 1476 |
|
| 1477 |
ok( $child2->store(), 'Child patron can be modified and stored when guarantor is stored'); |
| 1478 |
|
| 1479 |
@guarantors = ( $child3 ); |
| 1480 |
throws_ok { $child2->store( { guarantors => \@guarantors } ); } |
| 1481 |
'Koha::Exceptions::Patron::Relationship::InvalidRelationship', |
| 1482 |
'Exception thrown when child patron is modified and child patron is added as guarantor.'; |
| 1483 |
|
| 1484 |
$relationship->delete; |
| 1485 |
throws_ok { $child2->store(); } |
| 1486 |
'Koha::Exceptions::Patron::Relationship::NoGuarantor', |
| 1487 |
'Exception thrown when guarantor is deleted.'; |
| 1488 |
}; |