|
Lines 1764-1770
subtest
Link Here
|
| 1764 |
}; |
1764 |
}; |
| 1765 |
|
1765 |
|
| 1766 |
subtest 'account_locked' => sub { |
1766 |
subtest 'account_locked' => sub { |
| 1767 |
plan tests => 13; |
1767 |
plan tests => 14; |
| 1768 |
my $patron = $builder->build( { source => 'Borrower', value => { login_attempts => 0 } } ); |
1768 |
my $patron = $builder->build( { source => 'Borrower', value => { login_attempts => 0 } } ); |
| 1769 |
$patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
1769 |
$patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
| 1770 |
for my $value ( undef, '', 0 ) { |
1770 |
for my $value ( undef, '', 0 ) { |
|
Lines 1777-1784
subtest 'account_locked' => sub {
Link Here
|
| 1777 |
is( $patron->account_locked, 1, 'Feature is disabled but administrative lockout has been triggered' ); |
1777 |
is( $patron->account_locked, 1, 'Feature is disabled but administrative lockout has been triggered' ); |
| 1778 |
} |
1778 |
} |
| 1779 |
|
1779 |
|
| 1780 |
t::lib::Mocks::mock_preference( 'FailedloginAttempts', 3 ); |
|
|
| 1781 |
$patron->login_attempts(2)->store; |
1780 |
$patron->login_attempts(2)->store; |
|
|
1781 |
t::lib::Mocks::mock_preference( 'FailedloginAttempts', -3 ); |
| 1782 |
is( $patron->account_locked, 0, 'Bad pref value tested' ); |
| 1783 |
t::lib::Mocks::mock_preference( 'FailedloginAttempts', 3 ); |
| 1782 |
is( $patron->account_locked, 0, 'Patron has 2 failed attempts, account should not be considered locked yet' ); |
1784 |
is( $patron->account_locked, 0, 'Patron has 2 failed attempts, account should not be considered locked yet' ); |
| 1783 |
$patron->login_attempts(3)->store; |
1785 |
$patron->login_attempts(3)->store; |
| 1784 |
is( $patron->account_locked, 1, 'Patron has 3 failed attempts, account should be considered locked yet' ); |
1786 |
is( $patron->account_locked, 1, 'Patron has 3 failed attempts, account should be considered locked yet' ); |
|
Lines 2559-2565
subtest 'search_unsubscribed' => sub {
Link Here
|
| 2559 |
}; |
2561 |
}; |
| 2560 |
|
2562 |
|
| 2561 |
subtest 'search_anonymize_candidates' => sub { |
2563 |
subtest 'search_anonymize_candidates' => sub { |
| 2562 |
plan tests => 7; |
2564 |
plan tests => 10; |
|
|
2565 |
|
| 2566 |
my $cnt; |
| 2563 |
my $patron1 = $builder->build_object( { class => 'Koha::Patrons' } ); |
2567 |
my $patron1 = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 2564 |
my $patron2 = $builder->build_object( { class => 'Koha::Patrons' } ); |
2568 |
my $patron2 = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 2565 |
$patron1->anonymized(0); |
2569 |
$patron1->anonymized(0); |
|
Lines 2567-2577
subtest 'search_anonymize_candidates' => sub {
Link Here
|
| 2567 |
$patron2->anonymized(0); |
2571 |
$patron2->anonymized(0); |
| 2568 |
$patron2->dateexpiry( dt_from_string->add( days => 1 ) )->store; |
2572 |
$patron2->dateexpiry( dt_from_string->add( days => 1 ) )->store; |
| 2569 |
|
2573 |
|
|
|
2574 |
t::lib::Mocks::mock_preference( 'PatronAnonymizeDelay', undef ); |
| 2575 |
is( Koha::Patrons->search_anonymize_candidates->count, 0, 'Empty set expected (undef)' ); |
| 2570 |
t::lib::Mocks::mock_preference( 'PatronAnonymizeDelay', q{} ); |
2576 |
t::lib::Mocks::mock_preference( 'PatronAnonymizeDelay', q{} ); |
| 2571 |
is( Koha::Patrons->search_anonymize_candidates->count, 0, 'Empty set' ); |
2577 |
is( Koha::Patrons->search_anonymize_candidates->count, 0, 'Empty set expected (empty string)' ); |
| 2572 |
|
2578 |
|
| 2573 |
t::lib::Mocks::mock_preference( 'PatronAnonymizeDelay', 0 ); |
2579 |
t::lib::Mocks::mock_preference( 'PatronAnonymizeDelay', 0 ); |
| 2574 |
my $cnt = Koha::Patrons->search_anonymize_candidates->count; |
2580 |
$cnt = Koha::Patrons->search_anonymize_candidates->count; |
| 2575 |
$patron1->dateexpiry( dt_from_string->subtract( days => 1 ) )->store; |
2581 |
$patron1->dateexpiry( dt_from_string->subtract( days => 1 ) )->store; |
| 2576 |
$patron2->dateexpiry( dt_from_string->subtract( days => 3 ) )->store; |
2582 |
$patron2->dateexpiry( dt_from_string->subtract( days => 3 ) )->store; |
| 2577 |
is( Koha::Patrons->search_anonymize_candidates->count, $cnt + 2, 'Delay 0' ); |
2583 |
is( Koha::Patrons->search_anonymize_candidates->count, $cnt + 2, 'Delay 0' ); |
|
Lines 2592-2623
subtest 'search_anonymize_candidates' => sub {
Link Here
|
| 2592 |
$patron2->dateexpiry( dt_from_string->subtract( days => 3 ) )->store; |
2598 |
$patron2->dateexpiry( dt_from_string->subtract( days => 3 ) )->store; |
| 2593 |
is( Koha::Patrons->search_anonymize_candidates->count, $cnt, 'Delay 4' ); |
2599 |
is( Koha::Patrons->search_anonymize_candidates->count, $cnt, 'Delay 4' ); |
| 2594 |
|
2600 |
|
|
|
2601 |
t::lib::Mocks::mock_preference( 'FailedLoginAttempts', -2 ); # This is a bad value btw |
| 2602 |
$patron1->dateexpiry( dt_from_string->subtract( days => 5 ) )->login_attempts(0)->store; |
| 2603 |
$patron2->dateexpiry( dt_from_string->subtract( days => 5 ) )->login_attempts(0)->store; |
| 2604 |
$cnt = Koha::Patrons->search_anonymize_candidates( { locked => 1 } )->count; |
| 2605 |
$patron1->login_attempts(10)->store; |
| 2606 |
$patron2->login_attempts(-1)->store; |
| 2607 |
is( Koha::Patrons->search_anonymize_candidates( { locked => 1 } )->count, $cnt + 1, 'One admin lock higher' ); |
| 2608 |
t::lib::Mocks::mock_preference( 'FailedLoginAttempts', q{} ); |
| 2609 |
is( Koha::Patrons->search_anonymize_candidates( { locked => 1 } )->count, $cnt + 1, 'Still one up (empty)' ); |
| 2610 |
t::lib::Mocks::mock_preference( 'FailedLoginAttempts', 0 ); |
| 2611 |
is( Koha::Patrons->search_anonymize_candidates( { locked => 1 } )->count, $cnt + 1, 'Still one up (zero)' ); |
| 2612 |
|
| 2595 |
t::lib::Mocks::mock_preference( 'FailedLoginAttempts', 3 ); |
2613 |
t::lib::Mocks::mock_preference( 'FailedLoginAttempts', 3 ); |
| 2596 |
$patron1->dateexpiry( dt_from_string->subtract( days => 5 ) )->store; |
2614 |
$patron1->login_attempts(2)->store; |
| 2597 |
$patron1->login_attempts(0)->store; |
|
|
| 2598 |
$patron2->dateexpiry( dt_from_string->subtract( days => 5 ) )->store; |
| 2599 |
$patron2->login_attempts(0)->store; |
2615 |
$patron2->login_attempts(0)->store; |
| 2600 |
$cnt = Koha::Patrons->search_anonymize_candidates( { locked => 1 } )->count; |
2616 |
$cnt = Koha::Patrons->search_anonymize_candidates( { locked => 1 } )->count; |
| 2601 |
$patron1->login_attempts(3)->store; |
2617 |
$patron1->login_attempts(3)->store; |
| 2602 |
is( |
2618 |
is( Koha::Patrons->search_anonymize_candidates( { locked => 1 } )->count, $cnt + 1, 'Patron 1 included' ); |
| 2603 |
Koha::Patrons->search_anonymize_candidates( { locked => 1 } )->count, |
2619 |
$patron2->login_attempts(-1)->store; |
| 2604 |
$cnt + 1, 'Locked flag' |
2620 |
is( Koha::Patrons->search_anonymize_candidates( { locked => 1 } )->count, $cnt + 2, 'Patron 1 and 2 included' ); |
| 2605 |
); |
|
|
| 2606 |
|
2621 |
|
| 2607 |
t::lib::Mocks::mock_preference( 'FailedLoginAttempts', q{} ); |
2622 |
t::lib::Mocks::mock_preference( 'FailedLoginAttempts', q{} ); |
| 2608 |
|
|
|
| 2609 |
# Patron 1 still on 3 == locked |
| 2610 |
is( |
| 2611 |
Koha::Patrons->search_anonymize_candidates( { locked => 1 } )->count, |
| 2612 |
$cnt + 1, 'Still expect same number for FailedLoginAttempts empty' |
| 2613 |
); |
| 2614 |
$patron1->login_attempts(0)->store; |
| 2615 |
|
| 2616 |
# Patron 1 unlocked |
| 2617 |
is( |
| 2618 |
Koha::Patrons->search_anonymize_candidates( { locked => 1 } )->count, |
| 2619 |
$cnt, 'Patron 1 unlocked' |
| 2620 |
); |
| 2621 |
}; |
2623 |
}; |
| 2622 |
|
2624 |
|
| 2623 |
subtest 'search_anonymized' => sub { |
2625 |
subtest 'search_anonymized' => sub { |
| 2624 |
- |
|
|