|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 24; |
22 |
use Test::More tests => 25; |
| 23 |
use Test::Exception; |
23 |
use Test::Exception; |
| 24 |
use Test::Warn; |
24 |
use Test::Warn; |
| 25 |
|
25 |
|
|
Lines 1115-1121
subtest 'safe_to_delete() tests' => sub {
Link Here
|
| 1115 |
is( $message->type, 'error', 'Type is error' ); |
1115 |
is( $message->type, 'error', 'Type is error' ); |
| 1116 |
is( $message->message, 'has_debt', 'Cannot delete, has debt' ); |
1116 |
is( $message->message, 'has_debt', 'Cannot delete, has debt' ); |
| 1117 |
# cleanup |
1117 |
# cleanup |
| 1118 |
$patron->account->pay({ amount => 10, debits => [ $debit ] }); |
1118 |
#$patron->account->pay({ amount => 10, debits => [ $debit ] }); |
| 1119 |
|
1119 |
|
| 1120 |
## Happy case :-D |
1120 |
## Happy case :-D |
| 1121 |
ok( $patron->safe_to_delete, 'Can delete, all conditions met' ); |
1121 |
ok( $patron->safe_to_delete, 'Can delete, all conditions met' ); |
|
Lines 1498-1500
subtest 'update privacy tests' => sub {
Link Here
|
| 1498 |
is( $old_checkout->borrowernumber, $anon_patron->id, "Checkout is successfully anonymized"); |
1498 |
is( $old_checkout->borrowernumber, $anon_patron->id, "Checkout is successfully anonymized"); |
| 1499 |
is( $patron->privacy(), 2, "Patron privacy is successfully updated"); |
1499 |
is( $patron->privacy(), 2, "Patron privacy is successfully updated"); |
| 1500 |
}; |
1500 |
}; |
| 1501 |
- |
1501 |
|
|
|
1502 |
subtest 'guarantor requirements tests' => sub { |
| 1503 |
|
| 1504 |
plan tests => 6; |
| 1505 |
|
| 1506 |
$schema->storage->txn_begin; |
| 1507 |
|
| 1508 |
my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; |
| 1509 |
my $child_category = $builder->build( |
| 1510 |
{ source => 'Category', value => { category_type => 'C', can_be_guarantee => 1 } } ) |
| 1511 |
->{categorycode}; |
| 1512 |
my $patron_category = $builder->build( |
| 1513 |
{ source => 'Category', value => { category_type => 'A', can_be_guarantee => 0 } } ) |
| 1514 |
->{categorycode}; |
| 1515 |
|
| 1516 |
t::lib::Mocks::mock_preference( 'ChildNeedsGuarantor', 0 ); |
| 1517 |
|
| 1518 |
my $child = Koha::Patron->new( |
| 1519 |
{ |
| 1520 |
branchcode => $branchcode, |
| 1521 |
categorycode => $child_category, |
| 1522 |
contactname => '' |
| 1523 |
} |
| 1524 |
); |
| 1525 |
$child->store(); |
| 1526 |
|
| 1527 |
ok( |
| 1528 |
Koha::Patrons->find( $child->id ), |
| 1529 |
'Child patron can be stored without guarantor when ChildNeedsGuarantor is off.' |
| 1530 |
); |
| 1531 |
|
| 1532 |
t::lib::Mocks::mock_preference( 'ChildNeedsGuarantor', 1 ); |
| 1533 |
|
| 1534 |
my $child2 = Koha::Patron->new( |
| 1535 |
{ |
| 1536 |
branchcode => $branchcode, |
| 1537 |
categorycode => $child_category, |
| 1538 |
contactname => '' |
| 1539 |
} |
| 1540 |
); |
| 1541 |
my $child3 = $builder->build_object( |
| 1542 |
{ |
| 1543 |
class => 'Koha::Patrons', |
| 1544 |
value => { categorycode => $child_category } |
| 1545 |
} |
| 1546 |
); |
| 1547 |
my $patron = $builder->build_object( |
| 1548 |
{ |
| 1549 |
class => 'Koha::Patrons', |
| 1550 |
value => { categorycode => $patron_category } |
| 1551 |
} |
| 1552 |
); |
| 1553 |
|
| 1554 |
throws_ok { $child2->store(); } |
| 1555 |
'Koha::Exceptions::Patron::Relationship::NoGuarantor', |
| 1556 |
'Exception thrown when guarantor is required but not provided.'; |
| 1557 |
|
| 1558 |
my @guarantors = ( $patron, $child3 ); |
| 1559 |
throws_ok { $child2->store( { guarantors => \@guarantors } ); } |
| 1560 |
'Koha::Exceptions::Patron::Relationship::InvalidRelationship', |
| 1561 |
'Exception thrown when child patron is added as guarantor.'; |
| 1562 |
|
| 1563 |
#test ModMember |
| 1564 |
@guarantors = ( $patron ); |
| 1565 |
$child2->store( { guarantors => \@guarantors } )->discard_changes(); |
| 1566 |
|
| 1567 |
t::lib::Mocks::mock_preference( 'borrowerRelationship', '' ); |
| 1568 |
|
| 1569 |
my $relationship = Koha::Patron::Relationship->new( |
| 1570 |
{ guarantor_id => $patron->borrowernumber, |
| 1571 |
guarantee_id => $child2->borrowernumber, |
| 1572 |
relationship => '' |
| 1573 |
} |
| 1574 |
); |
| 1575 |
$relationship->store(); |
| 1576 |
|
| 1577 |
ok( $child2->store(), 'Child patron can be modified and stored when guarantor is stored'); |
| 1578 |
|
| 1579 |
@guarantors = ( $child3 ); |
| 1580 |
throws_ok { $child2->store( { guarantors => \@guarantors } ); } |
| 1581 |
'Koha::Exceptions::Patron::Relationship::InvalidRelationship', |
| 1582 |
'Exception thrown when child patron is modified and child patron is added as guarantor.'; |
| 1583 |
|
| 1584 |
$relationship->delete; |
| 1585 |
throws_ok { $child2->store(); } |
| 1586 |
'Koha::Exceptions::Patron::Relationship::NoGuarantor', |
| 1587 |
'Exception thrown when guarantor is deleted.'; |
| 1588 |
}; |