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

(-)a/t/db_dependent/Koha/Patron.t (-2 / +70 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({ class => 'Koha::Holds',
68
        value => { borrowernumber => $patron->id, timestamp => $ago },
69
    });
70
    is( $patron->is_active({ weeks => 1 }), 0, 'No holds in 1 weeks' );
71
    is( $patron->is_active({ weeks => 3 }), 1, 'Hold in last 3 weeks' );
72
    $hold->delete;
73
    my $old_hold = $builder->build_object({ class => 'Koha::Old::Holds',
74
        value => { borrowernumber => $patron->id, timestamp => $ago },
75
    });
76
    is( $patron->is_active({ weeks => 1 }), 0, 'No old holds in 1 weeks' );
77
    is( $patron->is_active({ weeks => 3 }), 1, 'Old hold in last 3 weeks' );
78
    $old_hold->delete;
79
80
    # Look at checkouts, test with months
81
    $ago = dt_from_string->subtract(months => 2);
82
    my $checkout = $builder->build_object({ class => 'Koha::Checkouts',
83
        value => { borrowernumber => $patron->id, timestamp => $ago },
84
    });
85
    is( $patron->is_active({ months => 1 }), 0, 'No checkouts in 1 months' );
86
    is( $patron->is_active({ months => 3 }), 1, 'Checkout in last 3 months' );
87
    $checkout->delete;
88
    my $old_checkout = $builder->build_object({ class => 'Koha::Old::Checkouts',
89
        value => { borrowernumber => $patron->id, timestamp => $ago },
90
    });
91
    is( $patron->is_active({ months => 1 }), 0, 'No old checkouts in 1 months' );
92
    is( $patron->is_active({ months => 3 }), 1, 'Old checkout in last 3 months' );
93
    $old_checkout->delete;
94
95
    # Look at article_requests, test with since
96
    $ago = dt_from_string->subtract(days => 10);
97
    my $article_request = $builder->build_object({ class => 'Koha::ArticleRequests',
98
        value => { borrowernumber => $patron->id, updated_on => $ago },
99
    });
100
    is( $patron->is_active({ days => 9 }), 0, 'No article requests in 9 days' );
101
    is( $patron->is_active({ days => 10 }), 1, 'Article requests in 10 days' );
102
    is( $patron->is_active({ since => $ago }), 1, 'Article requests since ago' );
103
    is( $patron->is_active({ since => $ago->add(days=>1) }), 0, 'No article requests since ago + 1 day' );
104
    $article_request->delete;
105
106
    $schema->storage->txn_rollback;
107
};
108
40
subtest 'add_guarantor() tests' => sub {
109
subtest 'add_guarantor() tests' => sub {
41
110
42
    plan tests => 6;
111
    plan tests => 6;
43
- 

Return to bug 33245