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 102-107 Patrons: Link Here
102
               renewal: "Renewing an item"
102
               renewal: "Renewing an item"
103
               check_in: "Returning an item"
103
               check_in: "Returning an item"
104
               hold: "Placing a hold on an item"
104
               hold: "Placing a hold on an item"
105
               article: "Places an article request"
105
     -
106
     -
106
         - pref: AutoApprovePatronProfileSettings
107
         - pref: AutoApprovePatronProfileSettings
107
           choices:
108
           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 / +18 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 => 21;
1957
    plan tests => 24;
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 1969-1975 subtest 'update_lastseen tests' => sub { Link Here
1969
1969
1970
    t::lib::Mocks::mock_preference(
1970
    t::lib::Mocks::mock_preference(
1971
        'TrackLastPatronActivityTriggers',
1971
        'TrackLastPatronActivityTriggers',
1972
        'login,connection,check_in,check_out,renewal,hold'
1972
        'login,connection,check_in,check_out,renewal,hold,article'
1973
    );
1973
    );
1974
1974
1975
    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' );
Lines 2003-2008 subtest 'update_lastseen tests' => sub { Link Here
2003
    $patron->update_lastseen('hold');
2003
    $patron->update_lastseen('hold');
2004
    $patron->_result()->discard_changes();
2004
    $patron->_result()->discard_changes();
2005
    is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged after a hold' );
2005
    is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged after a hold' );
2006
    $patron->update_lastseen('article');
2007
    $patron->_result()->discard_changes();
2008
    is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged after a article' );
2006
2009
2007
    # Check that tracking is disabled when the activity isn't listed
2010
    # Check that tracking is disabled when the activity isn't listed
2008
    t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', '' );
2011
    t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', '' );
Lines 2048-2058 subtest 'update_lastseen tests' => sub { Link Here
2048
        $patron->lastseen, $last_seen,
2051
        $patron->lastseen, $last_seen,
2049
        'Patron last seen should be unchanged after a hold if hold is not selected as an option and the cache has been cleared'
2052
        'Patron last seen should be unchanged after a hold if hold is not selected as an option and the cache has been cleared'
2050
    );
2053
    );
2054
    $patron->update_lastseen('article');
2055
    $patron->_result()->discard_changes();
2056
    is(
2057
        $patron->lastseen, $last_seen,
2058
        'Patron last seen should be unchanged after an article request if article is not selected as an option and the cache has been cleared'
2059
    );
2051
2060
2052
    # Check tracking for each activity
2061
    # Check tracking for each activity
2053
    t::lib::Mocks::mock_preference(
2062
    t::lib::Mocks::mock_preference(
2054
        'TrackLastPatronActivityTriggers',
2063
        'TrackLastPatronActivityTriggers',
2055
        'login,connection,check_in,check_out,renewal,hold'
2064
        'login,connection,check_in,check_out,renewal,hold,article'
2056
    );
2065
    );
2057
2066
2058
    $cache->clear_from_cache($cache_key);
2067
    $cache->clear_from_cache($cache_key);
Lines 2091-2096 subtest 'update_lastseen tests' => sub { Link Here
2091
        $patron->lastseen, $last_seen,
2100
        $patron->lastseen, $last_seen,
2092
        'Patron last seen should be changed after a hold if we cleared the cache'
2101
        'Patron last seen should be changed after a hold if we cleared the cache'
2093
    );
2102
    );
2103
    $patron->update_lastseen('article');
2104
    $patron->_result()->discard_changes();
2105
    isnt(
2106
        $patron->lastseen, $last_seen,
2107
        'Patron last seen should be changed after a article if we cleared the cache'
2108
    );
2094
2109
2095
    $cache->clear_from_cache($cache_key);
2110
    $cache->clear_from_cache($cache_key);
2096
    $patron->update_lastseen('renewal');
2111
    $patron->update_lastseen('renewal');
2097
- 

Return to bug 35030