Lines 1549-1551
subtest 'update privacy tests' => sub {
Link Here
|
1549 |
is( $old_checkout->borrowernumber, $anon_patron->id, "Checkout is successfully anonymized"); |
1549 |
is( $old_checkout->borrowernumber, $anon_patron->id, "Checkout is successfully anonymized"); |
1550 |
is( $patron->privacy(), 2, "Patron privacy is successfully updated"); |
1550 |
is( $patron->privacy(), 2, "Patron privacy is successfully updated"); |
1551 |
}; |
1551 |
}; |
1552 |
- |
1552 |
|
|
|
1553 |
subtest 'guarantor requirements tests' => sub { |
1554 |
|
1555 |
plan tests => 6; |
1556 |
|
1557 |
$schema->storage->txn_begin; |
1558 |
|
1559 |
my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; |
1560 |
my $child_category = $builder->build( |
1561 |
{ source => 'Category', value => { category_type => 'C', can_be_guarantee => 1 } } ) |
1562 |
->{categorycode}; |
1563 |
my $patron_category = $builder->build( |
1564 |
{ source => 'Category', value => { category_type => 'A', can_be_guarantee => 0 } } ) |
1565 |
->{categorycode}; |
1566 |
|
1567 |
t::lib::Mocks::mock_preference( 'ChildNeedsGuarantor', 0 ); |
1568 |
|
1569 |
my $child = Koha::Patron->new( |
1570 |
{ |
1571 |
branchcode => $branchcode, |
1572 |
categorycode => $child_category, |
1573 |
contactname => '' |
1574 |
} |
1575 |
); |
1576 |
$child->store(); |
1577 |
|
1578 |
ok( |
1579 |
Koha::Patrons->find( $child->id ), |
1580 |
'Child patron can be stored without guarantor when ChildNeedsGuarantor is off.' |
1581 |
); |
1582 |
|
1583 |
t::lib::Mocks::mock_preference( 'ChildNeedsGuarantor', 1 ); |
1584 |
|
1585 |
my $child2 = Koha::Patron->new( |
1586 |
{ |
1587 |
branchcode => $branchcode, |
1588 |
categorycode => $child_category, |
1589 |
contactname => '' |
1590 |
} |
1591 |
); |
1592 |
my $child3 = $builder->build_object( |
1593 |
{ |
1594 |
class => 'Koha::Patrons', |
1595 |
value => { categorycode => $child_category } |
1596 |
} |
1597 |
); |
1598 |
my $patron = $builder->build_object( |
1599 |
{ |
1600 |
class => 'Koha::Patrons', |
1601 |
value => { categorycode => $patron_category } |
1602 |
} |
1603 |
); |
1604 |
|
1605 |
throws_ok { $child2->store(); } |
1606 |
'Koha::Exceptions::Patron::Relationship::NoGuarantor', |
1607 |
'Exception thrown when guarantor is required but not provided.'; |
1608 |
|
1609 |
my @guarantors = ( $patron, $child3 ); |
1610 |
throws_ok { $child2->store( { guarantors => \@guarantors } ); } |
1611 |
'Koha::Exceptions::Patron::Relationship::InvalidRelationship', |
1612 |
'Exception thrown when child patron is added as guarantor.'; |
1613 |
|
1614 |
#test ModMember |
1615 |
@guarantors = ( $patron ); |
1616 |
$child2->store( { guarantors => \@guarantors } )->discard_changes(); |
1617 |
|
1618 |
t::lib::Mocks::mock_preference( 'borrowerRelationship', '' ); |
1619 |
|
1620 |
my $relationship = Koha::Patron::Relationship->new( |
1621 |
{ guarantor_id => $patron->borrowernumber, |
1622 |
guarantee_id => $child2->borrowernumber, |
1623 |
relationship => '' |
1624 |
} |
1625 |
); |
1626 |
$relationship->store(); |
1627 |
|
1628 |
ok( $child2->store(), 'Child patron can be modified and stored when guarantor is stored'); |
1629 |
|
1630 |
@guarantors = ( $child3 ); |
1631 |
throws_ok { $child2->store( { guarantors => \@guarantors } ); } |
1632 |
'Koha::Exceptions::Patron::Relationship::InvalidRelationship', |
1633 |
'Exception thrown when child patron is modified and child patron is added as guarantor.'; |
1634 |
|
1635 |
$relationship->delete; |
1636 |
throws_ok { $child2->store(); } |
1637 |
'Koha::Exceptions::Patron::Relationship::NoGuarantor', |
1638 |
'Exception thrown when guarantor is deleted.'; |
1639 |
}; |