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

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

Return to bug 33245