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

(-)a/Koha/ArticleRequest.pm (+14 lines)
Lines 64-69 sub request { Link Here
64
        if $debit;
64
        if $debit;
65
65
66
    $self->store();
66
    $self->store();
67
    $self->patron->update_lastseen('article');
67
    $self->notify();
68
    $self->notify();
68
    return $self;
69
    return $self;
69
}
70
}
Lines 226-231 sub borrower { Link Here
226
    return Koha::Patron->_new_from_dbic($rs);
227
    return Koha::Patron->_new_from_dbic($rs);
227
}
228
}
228
229
230
=head3 patron
231
232
Returns the Koha::Patron object for this article request
233
234
=cut
235
236
sub patron {
237
    my ($self) = @_;
238
    my $rs = $self->_result->borrowernumber;
239
    return unless $rs;
240
    return Koha::Patron->_new_from_dbic($rs);
241
}
242
229
=head3 branch
243
=head3 branch
230
244
231
Returns the Koha::Library object for this article request
245
Returns the Koha::Library object for this article request
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref (+1 lines)
Lines 101-106 Patrons: Link Here
101
               check_out: "Checking out an item"
101
               check_out: "Checking out an item"
102
               renewal: "Renewing an item"
102
               renewal: "Renewing an item"
103
               check_in: "Returning an item"
103
               check_in: "Returning an item"
104
               article: "Places an article request"
104
     -
105
     -
105
         - pref: AutoApprovePatronProfileSettings
106
         - pref: AutoApprovePatronProfileSettings
106
           choices:
107
           choices:
(-)a/t/db_dependent/Koha/ArticleRequest.t (-2 / +8 lines)
Lines 30-36 my $builder = t::lib::TestBuilder->new; Link Here
30
30
31
subtest 'request() tests' => sub {
31
subtest 'request() tests' => sub {
32
32
33
    plan tests => 11;
33
    plan tests => 13;
34
34
35
    $schema->storage->txn_begin;
35
    $schema->storage->txn_begin;
36
36
Lines 39-45 subtest 'request() tests' => sub { Link Here
39
    my $patron_mock = Test::MockModule->new('Koha::Patron');
39
    my $patron_mock = Test::MockModule->new('Koha::Patron');
40
    $patron_mock->mock( 'article_request_fee', sub { return $amount; } );
40
    $patron_mock->mock( 'article_request_fee', sub { return $amount; } );
41
41
42
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
42
    my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { lastseen => undef } } );
43
    my $item   = $builder->build_sample_item;
43
    my $item   = $builder->build_sample_item;
44
44
45
    my $ar_mock = Test::MockModule->new('Koha::ArticleRequest');
45
    my $ar_mock = Test::MockModule->new('Koha::ArticleRequest');
Lines 52-57 subtest 'request() tests' => sub { Link Here
52
        }
52
        }
53
    );
53
    );
54
54
55
    t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', '' );
55
    $ar->request()->discard_changes;
56
    $ar->request()->discard_changes;
56
57
57
    is( $ar->status, Koha::ArticleRequest::Status::Requested );
58
    is( $ar->status, Koha::ArticleRequest::Status::Requested );
Lines 59-64 subtest 'request() tests' => sub { Link Here
59
60
60
    is( $ar->debit_id, undef, 'No fee linked' );
61
    is( $ar->debit_id, undef, 'No fee linked' );
61
    is( $patron->account->balance, 0, 'No outstanding fees' );
62
    is( $patron->account->balance, 0, 'No outstanding fees' );
63
    $patron->discard_changes;
64
    is( $patron->lastseen, undef, 'Patron activity not tracked when article is not a valid trigger' );
62
65
63
    # set a fee amount
66
    # set a fee amount
64
    $amount = 10;
67
    $amount = 10;
Lines 71-76 subtest 'request() tests' => sub { Link Here
71
        }
74
        }
72
    );
75
    );
73
76
77
    t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'article' );
74
    $ar->request()->discard_changes;
78
    $ar->request()->discard_changes;
75
79
76
    is( $ar->status, Koha::ArticleRequest::Status::Requested );
80
    is( $ar->status, Koha::ArticleRequest::Status::Requested );
Lines 79-84 subtest 'request() tests' => sub { Link Here
79
83
80
    ok( defined $ar->debit_id, 'Fee linked' );
84
    ok( defined $ar->debit_id, 'Fee linked' );
81
    is( $patron->account->balance, $amount, 'Outstanding fees with the right value' );
85
    is( $patron->account->balance, $amount, 'Outstanding fees with the right value' );
86
    $patron->discard_changes;
87
    isnt( $patron->lastseen, undef, 'Patron activity tracked when article is a valid trigger' );
82
88
83
    $schema->storage->txn_rollback;
89
    $schema->storage->txn_rollback;
84
};
90
};
(-)a/t/db_dependent/Koha/Patron.t (-4 / +26 lines)
Lines 1954-1960 subtest 'alert_subscriptions tests' => sub { Link Here
1954
1954
1955
subtest 'update_lastseen tests' => sub {
1955
subtest 'update_lastseen tests' => sub {
1956
1956
1957
    plan tests => 18;
1957
    plan tests => 21;
1958
    $schema->storage->txn_begin;
1958
    $schema->storage->txn_begin;
1959
1959
1960
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
1960
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
Lines 1967-1973 subtest 'update_lastseen tests' => sub { Link Here
1967
    my $cache_key = "track_activity_" . $patron->borrowernumber;
1967
    my $cache_key = "track_activity_" . $patron->borrowernumber;
1968
    $cache->clear_from_cache($cache_key);
1968
    $cache->clear_from_cache($cache_key);
1969
1969
1970
    t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'login,connection,check_in,check_out,renewal' );
1970
    t::lib::Mocks::mock_preference(
1971
        'TrackLastPatronActivityTriggers',
1972
        'login,connection,check_in,check_out,renewal,article'
1973
    );
1971
1974
1972
    is( $patron->lastseen, undef, 'Patron should have not last seen when newly created' );
1975
    is( $patron->lastseen, undef, 'Patron should have not last seen when newly created' );
1973
1976
Lines 1997-2002 subtest 'update_lastseen tests' => sub { Link Here
1997
    $patron->update_lastseen('renewal');
2000
    $patron->update_lastseen('renewal');
1998
    $patron->_result()->discard_changes();
2001
    $patron->_result()->discard_changes();
1999
    is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged after a renewal' );
2002
    is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged after a renewal' );
2003
    $patron->update_lastseen('article');
2004
    $patron->_result()->discard_changes();
2005
    is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged after a article' );
2000
2006
2001
    # Check that tracking is disabled when the activity isn't listed
2007
    # Check that tracking is disabled when the activity isn't listed
2002
    t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', '' );
2008
    t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', '' );
Lines 2036-2044 subtest 'update_lastseen tests' => sub { Link Here
2036
        $patron->lastseen, $last_seen,
2042
        $patron->lastseen, $last_seen,
2037
        'Patron last seen should be unchanged after a renewal if renewal is not selected as an option and the cache has been cleared'
2043
        'Patron last seen should be unchanged after a renewal if renewal is not selected as an option and the cache has been cleared'
2038
    );
2044
    );
2045
    $patron->update_lastseen('article');
2046
    $patron->_result()->discard_changes();
2047
    is(
2048
        $patron->lastseen, $last_seen,
2049
        'Patron last seen should be unchanged after an article request if article is not selected as an option and the cache has been cleared'
2050
    );
2039
2051
2040
    # Check tracking for each activity
2052
    # Check tracking for each activity
2041
    t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'login,connection,check_in,check_out,renewal' );
2053
    t::lib::Mocks::mock_preference(
2054
        'TrackLastPatronActivityTriggers',
2055
        'login,connection,check_in,check_out,renewal,article'
2056
    );
2042
2057
2043
    $cache->clear_from_cache($cache_key);
2058
    $cache->clear_from_cache($cache_key);
2044
    $patron->update_lastseen('login');
2059
    $patron->update_lastseen('login');
Lines 2069-2074 subtest 'update_lastseen tests' => sub { Link Here
2069
        'Patron last seen should be changed after a check_in if we cleared the cache'
2084
        'Patron last seen should be changed after a check_in if we cleared the cache'
2070
    );
2085
    );
2071
2086
2087
    $cache->clear_from_cache($cache_key);
2088
    $patron->update_lastseen('article');
2089
    $patron->_result()->discard_changes();
2090
    isnt(
2091
        $patron->lastseen, $last_seen,
2092
        'Patron last seen should be changed after a article if we cleared the cache'
2093
    );
2094
2072
    $cache->clear_from_cache($cache_key);
2095
    $cache->clear_from_cache($cache_key);
2073
    $patron->update_lastseen('renewal');
2096
    $patron->update_lastseen('renewal');
2074
    $patron->_result()->discard_changes();
2097
    $patron->_result()->discard_changes();
2075
- 

Return to bug 35030