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

(-)a/t/db_dependent/Koha/Old/Holds.t (-1 / +84 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
use Koha::DateUtils qw(dt_from_string);
24
use Koha::Old::Holds;
25
26
use t::lib::TestBuilder;
27
28
my $schema  = Koha::Database->new->schema;
29
my $builder = t::lib::TestBuilder->new;
30
31
subtest 'anonymize() tests' => sub {
32
33
    plan tests => 3;
34
35
    $schema->storage->txn_begin;
36
37
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
38
39
    my $hold_1 = $builder->build_object(
40
        {
41
            class => 'Koha::Old::Holds',
42
            value =>
43
              { borrowernumber => $patron->id, timestamp => dt_from_string() }
44
        }
45
    );
46
    my $hold_2 = $builder->build_object(
47
        {
48
            class => 'Koha::Old::Holds',
49
            value => {
50
                borrowernumber => $patron->id,
51
                timestamp      => dt_from_string()->subtract( days => 1 )
52
            }
53
        }
54
    );
55
    my $hold_3 = $builder->build_object(
56
        {
57
            class => 'Koha::Old::Holds',
58
            value => {
59
                borrowernumber => $patron->id,
60
                timestamp      => dt_from_string()->subtract( days => 2 )
61
            }
62
        }
63
    );
64
    my $hold_4 = $builder->build_object(
65
        {
66
            class => 'Koha::Old::Holds',
67
            value => {
68
                borrowernumber => $patron->id,
69
                timestamp      => dt_from_string()->subtract( days => 3 )
70
            }
71
        }
72
    );
73
74
    is( $patron->old_holds->count, 4, 'Patron has 4 completed holds' );
75
    # filter them so only the older two are part of the resultset
76
    my $holds = $patron->old_holds->search({ timestamp => { '<=' => dt_from_string()->subtract( days => 2 ) } });
77
    # Anonymize them
78
    my $anonymized_count = $holds->anonymize();
79
    is( $anonymized_count, 2, 'update() tells 2 rows were updated' );
80
81
    is( $patron->old_holds->count, 2, 'Patron has 2 completed holds' );
82
83
    $schema->storage->txn_rollback;
84
};

Return to bug 29780