|
Lines 2624-2716
subtest 'get_lists_with_patron() tests' => sub {
Link Here
|
| 2624 |
$schema->storage->txn_rollback; |
2624 |
$schema->storage->txn_rollback; |
| 2625 |
}; |
2625 |
}; |
| 2626 |
|
2626 |
|
| 2627 |
subtest 'guarantor requirements tests' => sub { |
2627 |
subtest 'validate_guarantor() tests' => sub { |
| 2628 |
|
2628 |
|
| 2629 |
plan tests => 6; |
2629 |
plan tests => 5; |
| 2630 |
|
2630 |
|
| 2631 |
$schema->storage->txn_begin; |
2631 |
$schema->storage->txn_begin; |
| 2632 |
|
2632 |
|
| 2633 |
my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; |
2633 |
my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; |
| 2634 |
my $child_category = |
2634 |
my $guarantee_category = |
| 2635 |
$builder->build( { source => 'Category', value => { category_type => 'C', can_be_guarantee => 1 } } ) |
2635 |
$builder->build( |
| 2636 |
->{categorycode}; |
2636 |
{ source => 'Category', value => { categorycode => "GUARANTEE", category_type => 'C', can_be_guarantee => 1 } } |
| 2637 |
my $patron_category = |
2637 |
); |
| 2638 |
$builder->build( { source => 'Category', value => { category_type => 'A', can_be_guarantee => 0 } } ) |
2638 |
my $guarantor_category = |
| 2639 |
->{categorycode}; |
2639 |
$builder->build( |
| 2640 |
|
2640 |
{ source => 'Category', value => { categorycode => "GUARANTOR", category_type => 'A', can_be_guarantee => 0 } } |
| 2641 |
t::lib::Mocks::mock_preference( 'ChildNeedsGuarantor', 0 ); |
2641 |
); |
| 2642 |
|
2642 |
|
| 2643 |
my $child = Koha::Patron->new( |
2643 |
my $child = Koha::Patron->new( |
| 2644 |
{ |
2644 |
{ |
| 2645 |
branchcode => $branchcode, |
2645 |
branchcode => $branchcode, |
| 2646 |
categorycode => $child_category, |
2646 |
categorycode => $guarantee_category->{categorycode}, |
| 2647 |
contactname => '' |
|
|
| 2648 |
} |
| 2649 |
); |
| 2650 |
$child->store(); |
| 2651 |
|
| 2652 |
ok( |
| 2653 |
Koha::Patrons->find( $child->id ), |
| 2654 |
'Child patron can be stored without guarantor when ChildNeedsGuarantor is off.' |
| 2655 |
); |
| 2656 |
|
| 2657 |
t::lib::Mocks::mock_preference( 'ChildNeedsGuarantor', 1 ); |
| 2658 |
|
| 2659 |
my $child2 = Koha::Patron->new( |
| 2660 |
{ |
| 2661 |
branchcode => $branchcode, |
| 2662 |
categorycode => $child_category, |
| 2663 |
contactname => '' |
2647 |
contactname => '' |
| 2664 |
} |
2648 |
} |
| 2665 |
); |
2649 |
); |
| 2666 |
my $child3 = $builder->build_object( |
2650 |
my $child2 = $builder->build_object( |
| 2667 |
{ |
2651 |
{ |
| 2668 |
class => 'Koha::Patrons', |
2652 |
class => 'Koha::Patrons', |
| 2669 |
value => { categorycode => $child_category } |
2653 |
value => { categorycode => $guarantee_category->{categorycode} } |
| 2670 |
} |
2654 |
} |
| 2671 |
); |
2655 |
); |
| 2672 |
my $patron = $builder->build_object( |
2656 |
my $patron = $builder->build_object( |
| 2673 |
{ |
2657 |
{ |
| 2674 |
class => 'Koha::Patrons', |
2658 |
class => 'Koha::Patrons', |
| 2675 |
value => { categorycode => $patron_category } |
2659 |
value => { categorycode => $guarantor_category->{categorycode} } |
| 2676 |
} |
2660 |
} |
| 2677 |
); |
2661 |
); |
| 2678 |
|
2662 |
|
| 2679 |
throws_ok { $child2->store(); } |
2663 |
my @guarantors; |
|
|
2664 |
my $contactname = ""; |
| 2665 |
my $category = Koha::Patron::Categories->find( $guarantee_category->{categorycode} ); |
| 2666 |
|
| 2667 |
t::lib::Mocks::mock_preference( 'ChildNeedsGuarantor', 0 ); |
| 2668 |
|
| 2669 |
lives_ok { $child->validate_guarantor( \@guarantors, $contactname, $category ); } |
| 2670 |
'Validation passes when ChildNeedsGuarantor syspref is disabled'; |
| 2671 |
|
| 2672 |
t::lib::Mocks::mock_preference( 'ChildNeedsGuarantor', 1 ); |
| 2673 |
|
| 2674 |
throws_ok { $child->validate_guarantor( \@guarantors, $contactname, $category ); } |
| 2680 |
'Koha::Exceptions::Patron::Relationship::NoGuarantor', |
2675 |
'Koha::Exceptions::Patron::Relationship::NoGuarantor', |
| 2681 |
'Exception thrown when guarantor is required but not provided.'; |
2676 |
'Exception thrown when guarantor is required but not provided.'; |
| 2682 |
|
2677 |
|
| 2683 |
my @guarantors = ( $patron, $child3 ); |
2678 |
@guarantors = ( $patron, $child2 ); |
| 2684 |
throws_ok { $child2->store( { guarantors => \@guarantors } ); } |
2679 |
throws_ok { $child->validate_guarantor( \@guarantors, $contactname, $category ); } |
| 2685 |
'Koha::Exceptions::Patron::Relationship::InvalidRelationship', |
2680 |
'Koha::Exceptions::Patron::Relationship::InvalidRelationship', |
| 2686 |
'Exception thrown when child patron is added as guarantor.'; |
2681 |
'Exception thrown when child patron is added as guarantor.'; |
| 2687 |
|
2682 |
|
| 2688 |
#test ModMember |
|
|
| 2689 |
@guarantors = ($patron); |
2683 |
@guarantors = ($patron); |
| 2690 |
$child2->store( { guarantors => \@guarantors } )->discard_changes(); |
2684 |
lives_ok { $child->validate_guarantor( \@guarantors, undef, $category ); } |
| 2691 |
|
2685 |
'Validation passes when valid guarantors are passed in array'; |
| 2692 |
t::lib::Mocks::mock_preference( 'borrowerRelationship', '' ); |
|
|
| 2693 |
|
2686 |
|
| 2694 |
my $relationship = Koha::Patron::Relationship->new( |
2687 |
@guarantors = (); |
| 2695 |
{ |
2688 |
$contactname = "Guarantor"; |
| 2696 |
guarantor_id => $patron->borrowernumber, |
2689 |
lives_ok { $child->validate_guarantor( \@guarantors, $contactname, $category ); } |
| 2697 |
guarantee_id => $child2->borrowernumber, |
2690 |
'Validation passes when guarantor contanct name is passed'; |
| 2698 |
relationship => '' |
|
|
| 2699 |
} |
| 2700 |
); |
| 2701 |
$relationship->store(); |
| 2702 |
|
| 2703 |
ok( $child2->store(), 'Child patron can be modified and stored when guarantor is stored' ); |
| 2704 |
|
| 2705 |
@guarantors = ($child3); |
| 2706 |
throws_ok { $child2->store( { guarantors => \@guarantors } ); } |
| 2707 |
'Koha::Exceptions::Patron::Relationship::InvalidRelationship', |
| 2708 |
'Exception thrown when child patron is modified and child patron is added as guarantor.'; |
| 2709 |
|
| 2710 |
$relationship->delete; |
| 2711 |
throws_ok { $child2->store(); } |
| 2712 |
'Koha::Exceptions::Patron::Relationship::NoGuarantor', |
| 2713 |
'Exception thrown when guarantor is deleted.'; |
| 2714 |
|
2691 |
|
| 2715 |
$schema->storage->txn_rollback; |
2692 |
$schema->storage->txn_rollback; |
| 2716 |
}; |
2693 |
}; |
| 2717 |
- |
|
|