|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 43; |
22 |
use Test::More tests => 44; |
| 23 |
use Test::Warn; |
23 |
use Test::Warn; |
| 24 |
use Test::Exception; |
24 |
use Test::Exception; |
| 25 |
use Test::MockModule; |
25 |
use Test::MockModule; |
|
Lines 2678-2681
subtest 'filter_by_have_permission' => sub {
Link Here
|
| 2678 |
$schema->storage->txn_rollback; |
2678 |
$schema->storage->txn_rollback; |
| 2679 |
}; |
2679 |
}; |
| 2680 |
|
2680 |
|
|
|
2681 |
subtest 'filter_by_expired_opac_registrations' => sub { |
| 2682 |
plan tests => 8; |
| 2683 |
|
| 2684 |
$schema->storage->txn_begin; |
| 2685 |
|
| 2686 |
my $category = $builder->build_object( { class => 'Koha::Patron::Categories' } ); |
| 2687 |
t::lib::Mocks::mock_preference( 'PatronSelfRegistrationDefaultCategory', $category->categorycode ); |
| 2688 |
my $self_reg = $builder->build_object( |
| 2689 |
{ |
| 2690 |
class => 'Koha::Patrons', |
| 2691 |
value => { |
| 2692 |
dateenrolled => '2014-01-01 01:02:03', |
| 2693 |
categorycode => $category->categorycode |
| 2694 |
} |
| 2695 |
} |
| 2696 |
); |
| 2697 |
|
| 2698 |
# First test if empty PatronSelfRegistrationExpireTemporaryAccountsDelay returns an exception |
| 2699 |
t::lib::Mocks::mock_preference( 'PatronSelfRegistrationExpireTemporaryAccountsDelay', q{} ); |
| 2700 |
throws_ok { Koha::Patrons->filter_by_expired_opac_registrations } |
| 2701 |
'Koha::Exceptions::SysPref::NotSet', |
| 2702 |
'Attempt to filter with empty PatronSelfRegistrationExpireTemporaryAccountsDelay throws exception.'; |
| 2703 |
|
| 2704 |
# Test zero too |
| 2705 |
t::lib::Mocks::mock_preference( 'PatronSelfRegistrationExpireTemporaryAccountsDelay', 0); |
| 2706 |
throws_ok { Koha::Patrons->filter_by_expired_opac_registrations } |
| 2707 |
'Koha::Exceptions::SysPref::NotSet', |
| 2708 |
'Attempt to filter with PatronSelfRegistrationExpireTemporaryAccountsDelay set to 0 throws exception.'; |
| 2709 |
|
| 2710 |
# Also check empty category |
| 2711 |
t::lib::Mocks::mock_preference( 'PatronSelfRegistrationDefaultCategory', q{} ); |
| 2712 |
throws_ok { Koha::Patrons->filter_by_expired_opac_registrations } |
| 2713 |
'Koha::Exceptions::SysPref::NotSet', |
| 2714 |
'Attempt to filter with empty PatronSelfRegistrationDefaultCategory throws exception.'; |
| 2715 |
|
| 2716 |
t::lib::Mocks::mock_preference( 'PatronSelfRegistrationExpireTemporaryAccountsDelay', 360 ); |
| 2717 |
throws_ok { Koha::Patrons->filter_by_expired_opac_registrations } |
| 2718 |
'Koha::Exceptions::SysPref::NotSet', |
| 2719 |
'Attempt to filter with empty PatronSelfRegistrationDefaultCategory throws exception, even if PatronSelfRegistrationExpireTemporaryAccountsDelay is set.'; |
| 2720 |
|
| 2721 |
t::lib::Mocks::mock_preference( 'PatronSelfRegistrationDefaultCategory', $category->categorycode ); |
| 2722 |
|
| 2723 |
my $checkout = $builder->build_object( |
| 2724 |
{ |
| 2725 |
class => 'Koha::Checkouts', |
| 2726 |
value => { borrowernumber => $self_reg->borrowernumber } |
| 2727 |
} |
| 2728 |
); |
| 2729 |
is( |
| 2730 |
Koha::Patrons->filter_by_expired_opac_registrations->filter_by_safe_to_delete->count, 0, |
| 2731 |
"filter_by_safe_to_delete doesn't delete borrower with checkout" |
| 2732 |
); |
| 2733 |
|
| 2734 |
my $account_line = $builder->build_object( |
| 2735 |
{ |
| 2736 |
class => 'Koha::Account::Lines', |
| 2737 |
value => { |
| 2738 |
borrowernumber => $self_reg->borrowernumber, |
| 2739 |
amountoutstanding => 5, |
| 2740 |
} |
| 2741 |
} |
| 2742 |
); |
| 2743 |
is( |
| 2744 |
Koha::Patrons->filter_by_expired_opac_registrations->filter_by_safe_to_delete->count, 0, |
| 2745 |
"filter_by_safe_to_delete doesn't delete borrower with checkout and fine" |
| 2746 |
); |
| 2747 |
|
| 2748 |
$checkout->delete; |
| 2749 |
is( |
| 2750 |
Koha::Patrons->filter_by_expired_opac_registrations->filter_by_safe_to_delete->count, 0, |
| 2751 |
"filter_by_safe_to_delete doesn't delete borrower with fine and no checkout" |
| 2752 |
); |
| 2753 |
|
| 2754 |
$account_line->delete; |
| 2755 |
is( |
| 2756 |
Koha::Patrons->filter_by_expired_opac_registrations->filter_by_safe_to_delete->count, 1, |
| 2757 |
"filter_by_safe_to_delete does delete borrower with no fines and no checkouts" |
| 2758 |
); |
| 2759 |
|
| 2760 |
$schema->storage->txn_rollback; |
| 2761 |
}; |
| 2762 |
|
| 2681 |
$schema->storage->txn_rollback; |
2763 |
$schema->storage->txn_rollback; |