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

(-)a/Koha/Old/Hold.pm (-2 / +19 lines)
Lines 21-26 use Modern::Perl; Link Here
21
21
22
use base qw(Koha::Hold);
22
use base qw(Koha::Hold);
23
23
24
use C4::Context;
25
24
=head1 NAME
26
=head1 NAME
25
27
26
Koha::Old::Hold - Koha Old Hold object class
28
Koha::Old::Hold - Koha Old Hold object class
Lines 29-40 This object represents a hold that has been filled or canceled Link Here
29
31
30
=head1 API
32
=head1 API
31
33
32
=head2 Class Methods
34
=head2 Class methods
35
36
=head3 anonymize
37
38
    $old_hold->anonymize();
39
40
Anonymize the given I<Koha::Old::Hold> object.
33
41
34
=cut
42
=cut
35
43
44
sub anonymize {
45
    my ($self) = @_;
46
47
    my $anonymous_id = C4::Context->preference('AnonymousPatron') || undef;
48
49
    return $self->update( { borrowernumber => $anonymous_id } );
50
}
51
52
=head2 Internal methods
36
53
37
=head3 type
54
=head3 _type
38
55
39
=cut
56
=cut
40
57
(-)a/t/db_dependent/Koha/Old/Hold.t (-1 / +80 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 1;
21
22
use Koha::Database;
23
24
use t::lib::Mocks;
25
use t::lib::TestBuilder;
26
27
my $schema  = Koha::Database->new->schema;
28
my $builder = t::lib::TestBuilder->new;
29
30
subtest 'anonymize() tests' => sub {
31
32
    plan tests => 6;
33
34
    $schema->storage->txn_begin;
35
36
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
37
38
    is( $patron->old_holds->count, 0, 'Patron has no old holds' );
39
40
    my $hold_1 = $builder->build_object(
41
        {
42
            class => 'Koha::Old::Holds',
43
            value => { borrowernumber => $patron->id }
44
        }
45
    );
46
    my $hold_2 = $builder->build_object(
47
        {
48
            class => 'Koha::Old::Holds',
49
            value => { borrowernumber => $patron->id }
50
        }
51
    );
52
53
    is( $patron->old_holds->count, 2, 'Patron has 2 completed holds' );
54
55
    t::lib::Mocks::mock_preference( 'AnonymousPatron', undef );
56
57
    $hold_1->anonymize;
58
59
    is( $patron->old_holds->count, 1, 'Patron has 1 linked completed holds' );
60
61
    # Reload
62
    $hold_1->discard_changes;
63
    $hold_2->discard_changes;
64
    is( $hold_1->borrowernumber, undef,
65
        'Anonymized hold not linked to patron' );
66
    is( $hold_2->borrowernumber, $patron->id,
67
        'Not anonymized hold still linked to patron' );
68
69
    my $anonymous_patron =
70
      $builder->build_object( { class => 'Koha::Patrons' } );
71
    t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id );
72
73
    # anonymize second hold
74
    $hold_2->anonymize;
75
    $hold_2->discard_changes;
76
    is( $hold_2->borrowernumber, $anonymous_patron->id,
77
        'Anonymized hold linked to anonymouspatron' );
78
79
    $schema->storage->txn_rollback;
80
};

Return to bug 29868