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 2700-2703
subtest 'filter_by_have_permission' => sub {
Link Here
|
2700 |
$schema->storage->txn_rollback; |
2700 |
$schema->storage->txn_rollback; |
2701 |
}; |
2701 |
}; |
2702 |
|
2702 |
|
|
|
2703 |
subtest 'filter_by_expired_opac_registrations' => sub { |
2704 |
plan tests => 8; |
2705 |
|
2706 |
$schema->storage->txn_begin; |
2707 |
|
2708 |
my $category = $builder->build_object( { class => 'Koha::Patron::Categories' } ); |
2709 |
t::lib::Mocks::mock_preference( 'PatronSelfRegistrationDefaultCategory', $category->categorycode ); |
2710 |
my $self_reg = $builder->build_object( |
2711 |
{ |
2712 |
class => 'Koha::Patrons', |
2713 |
value => { |
2714 |
dateenrolled => '2014-01-01 01:02:03', |
2715 |
categorycode => $category->categorycode |
2716 |
} |
2717 |
} |
2718 |
); |
2719 |
|
2720 |
# First test if empty PatronSelfRegistrationExpireTemporaryAccountsDelay returns an exception |
2721 |
t::lib::Mocks::mock_preference( 'PatronSelfRegistrationExpireTemporaryAccountsDelay', q{} ); |
2722 |
throws_ok { Koha::Patrons->filter_by_expired_opac_registrations } |
2723 |
'Koha::Exceptions::SysPref::NotSet', |
2724 |
'Attempt to filter with empty PatronSelfRegistrationExpireTemporaryAccountsDelay throws exception.'; |
2725 |
|
2726 |
# Test zero too |
2727 |
t::lib::Mocks::mock_preference( 'PatronSelfRegistrationExpireTemporaryAccountsDelay', 0 ); |
2728 |
throws_ok { Koha::Patrons->filter_by_expired_opac_registrations } |
2729 |
'Koha::Exceptions::SysPref::NotSet', |
2730 |
'Attempt to filter with PatronSelfRegistrationExpireTemporaryAccountsDelay set to 0 throws exception.'; |
2731 |
|
2732 |
# Also check empty category |
2733 |
t::lib::Mocks::mock_preference( 'PatronSelfRegistrationDefaultCategory', q{} ); |
2734 |
throws_ok { Koha::Patrons->filter_by_expired_opac_registrations } |
2735 |
'Koha::Exceptions::SysPref::NotSet', |
2736 |
'Attempt to filter with empty PatronSelfRegistrationDefaultCategory throws exception.'; |
2737 |
|
2738 |
t::lib::Mocks::mock_preference( 'PatronSelfRegistrationExpireTemporaryAccountsDelay', 360 ); |
2739 |
throws_ok { Koha::Patrons->filter_by_expired_opac_registrations } |
2740 |
'Koha::Exceptions::SysPref::NotSet', |
2741 |
'Attempt to filter with empty PatronSelfRegistrationDefaultCategory throws exception, even if PatronSelfRegistrationExpireTemporaryAccountsDelay is set.'; |
2742 |
|
2743 |
t::lib::Mocks::mock_preference( 'PatronSelfRegistrationDefaultCategory', $category->categorycode ); |
2744 |
|
2745 |
my $checkout = $builder->build_object( |
2746 |
{ |
2747 |
class => 'Koha::Checkouts', |
2748 |
value => { borrowernumber => $self_reg->borrowernumber } |
2749 |
} |
2750 |
); |
2751 |
is( |
2752 |
Koha::Patrons->filter_by_expired_opac_registrations->filter_by_safe_to_delete->count, 0, |
2753 |
"filter_by_safe_to_delete doesn't delete borrower with checkout" |
2754 |
); |
2755 |
|
2756 |
my $account_line = $builder->build_object( |
2757 |
{ |
2758 |
class => 'Koha::Account::Lines', |
2759 |
value => { |
2760 |
borrowernumber => $self_reg->borrowernumber, |
2761 |
amountoutstanding => 5, |
2762 |
} |
2763 |
} |
2764 |
); |
2765 |
is( |
2766 |
Koha::Patrons->filter_by_expired_opac_registrations->filter_by_safe_to_delete->count, 0, |
2767 |
"filter_by_safe_to_delete doesn't delete borrower with checkout and fine" |
2768 |
); |
2769 |
|
2770 |
$checkout->delete; |
2771 |
is( |
2772 |
Koha::Patrons->filter_by_expired_opac_registrations->filter_by_safe_to_delete->count, 0, |
2773 |
"filter_by_safe_to_delete doesn't delete borrower with fine and no checkout" |
2774 |
); |
2775 |
|
2776 |
$account_line->delete; |
2777 |
is( |
2778 |
Koha::Patrons->filter_by_expired_opac_registrations->filter_by_safe_to_delete->count, 1, |
2779 |
"filter_by_safe_to_delete does delete borrower with no fines and no checkouts" |
2780 |
); |
2781 |
|
2782 |
$schema->storage->txn_rollback; |
2783 |
}; |
2784 |
|
2703 |
$schema->storage->txn_rollback; |
2785 |
$schema->storage->txn_rollback; |