View | Details | Raw Unified | Return to bug 33245
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Patron.t (-2 / +85 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 24;
22
use Test::More tests => 25;
23
use Test::Exception;
23
use Test::Exception;
24
use Test::Warn;
24
use Test::Warn;
25
25
Lines 37-42 use t::lib::Mocks; Link Here
37
my $schema  = Koha::Database->new->schema;
37
my $schema  = Koha::Database->new->schema;
38
my $builder = t::lib::TestBuilder->new;
38
my $builder = t::lib::TestBuilder->new;
39
39
40
subtest 'is_active' => sub {
41
    plan tests => 18;
42
    $schema->storage->txn_begin;
43
44
    # Check expiry
45
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
46
    $patron->dateexpiry( dt_from_string->subtract( days => 1 ) )->store;
47
    is( $patron->is_active, 0, 'Expired patron is not active' );
48
    $patron->dateexpiry(undef)->store;
49
    is( $patron->is_active, 1, 'Expiry date removed' );
50
51
    # Change enrolled date now
52
    $patron->dateenrolled('2020-01-01')->store;
53
54
    # Check lastseen, test days parameter
55
    t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', 1 );
56
    $patron->track_login;
57
    is( $patron->is_active, 1, 'Just logged in' );
58
    my $ago = dt_from_string->subtract( days => 2 );
59
    $patron->lastseen($ago)->store;
60
    is( $patron->is_active( { days => 1 } ), 0, 'Not active since yesterday' );
61
    is( $patron->is_active( { days => 3 } ), 1, 'Active within last 3 days' );
62
    t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', 0 );
63
    is( $patron->is_active( { days => 3 } ), 0, 'Pref disabled' );
64
65
    # Look at holds, test with weeks
66
    $ago = dt_from_string->subtract( weeks => 2 );
67
    my $hold = $builder->build_object(
68
        {
69
            class => 'Koha::Holds',
70
            value => { borrowernumber => $patron->id, timestamp => $ago },
71
        }
72
    );
73
    is( $patron->is_active( { weeks => 1 } ), 0, 'No holds in 1 weeks' );
74
    is( $patron->is_active( { weeks => 3 } ), 1, 'Hold in last 3 weeks' );
75
    $hold->delete;
76
    my $old_hold = $builder->build_object(
77
        {
78
            class => 'Koha::Old::Holds',
79
            value => { borrowernumber => $patron->id, timestamp => $ago },
80
        }
81
    );
82
    is( $patron->is_active( { weeks => 1 } ), 0, 'No old holds in 1 weeks' );
83
    is( $patron->is_active( { weeks => 3 } ), 1, 'Old hold in last 3 weeks' );
84
    $old_hold->delete;
85
86
    # Look at checkouts, test with months
87
    $ago = dt_from_string->subtract( months => 2 );
88
    my $checkout = $builder->build_object(
89
        {
90
            class => 'Koha::Checkouts',
91
            value => { borrowernumber => $patron->id, timestamp => $ago },
92
        }
93
    );
94
    is( $patron->is_active( { months => 1 } ), 0, 'No checkouts in 1 months' );
95
    is( $patron->is_active( { months => 3 } ), 1, 'Checkout in last 3 months' );
96
    $checkout->delete;
97
    my $old_checkout = $builder->build_object(
98
        {
99
            class => 'Koha::Old::Checkouts',
100
            value => { borrowernumber => $patron->id, timestamp => $ago },
101
        }
102
    );
103
    is( $patron->is_active( { months => 1 } ), 0, 'No old checkouts in 1 months' );
104
    is( $patron->is_active( { months => 3 } ), 1, 'Old checkout in last 3 months' );
105
    $old_checkout->delete;
106
107
    # Look at article_requests, test with since
108
    $ago = dt_from_string->subtract( days => 10 );
109
    my $article_request = $builder->build_object(
110
        {
111
            class => 'Koha::ArticleRequests',
112
            value => { borrowernumber => $patron->id, updated_on => $ago },
113
        }
114
    );
115
    is( $patron->is_active( { days  => 9 } ),                      0, 'No article requests in 9 days' );
116
    is( $patron->is_active( { days  => 10 } ),                     1, 'Article requests in 10 days' );
117
    is( $patron->is_active( { since => $ago } ),                   1, 'Article requests since ago' );
118
    is( $patron->is_active( { since => $ago->add( days => 1 ) } ), 0, 'No article requests since ago + 1 day' );
119
    $article_request->delete;
120
121
    $schema->storage->txn_rollback;
122
};
123
40
subtest 'add_guarantor() tests' => sub {
124
subtest 'add_guarantor() tests' => sub {
41
125
42
    plan tests => 6;
126
    plan tests => 6;
43
- 

Return to bug 33245