Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 1; |
20 |
use Test::More tests => 2; |
21 |
|
21 |
|
22 |
use Koha::Database; |
22 |
use Koha::Database; |
23 |
use Koha::DateUtils qw(dt_from_string); |
23 |
use Koha::DateUtils qw(dt_from_string); |
Lines 85-87
subtest 'anonymize() tests' => sub {
Link Here
|
85 |
|
85 |
|
86 |
$schema->storage->txn_rollback; |
86 |
$schema->storage->txn_rollback; |
87 |
}; |
87 |
}; |
88 |
- |
88 |
|
|
|
89 |
subtest 'filter_by_anonymizable() tests' => sub { |
90 |
|
91 |
plan tests => 7; |
92 |
|
93 |
$schema->storage->txn_begin; |
94 |
|
95 |
# patron_1 => keep records forever |
96 |
my $patron_1 = $builder->build_object( |
97 |
{ class => 'Koha::Patrons', value => { privacy => 0 } } ); |
98 |
|
99 |
# patron_2 => never keep records |
100 |
my $patron_2 = $builder->build_object( |
101 |
{ class => 'Koha::Patrons', value => { privacy => 1 } } ); |
102 |
|
103 |
is( $patron_1->old_holds->count, 0, 'patron_1 has no old holds' ); |
104 |
is( $patron_2->old_holds->count, 0, 'patron_2 has no old holds' ); |
105 |
|
106 |
my $hold_1 = $builder->build_object( |
107 |
{ |
108 |
class => 'Koha::Holds', |
109 |
value => { |
110 |
borrowernumber => $patron_1->id, |
111 |
} |
112 |
} |
113 |
)->_move_to_old; |
114 |
my $hold_2 = $builder->build_object( |
115 |
{ |
116 |
class => 'Koha::Holds', |
117 |
value => { |
118 |
borrowernumber => $patron_2->id, |
119 |
} |
120 |
} |
121 |
)->_move_to_old; |
122 |
my $hold_3 = $builder->build_object( |
123 |
{ |
124 |
class => 'Koha::Holds', |
125 |
value => { |
126 |
borrowernumber => $patron_1->id, |
127 |
} |
128 |
} |
129 |
)->_move_to_old; |
130 |
my $hold_4 = $builder->build_object( |
131 |
{ |
132 |
class => 'Koha::Holds', |
133 |
value => { |
134 |
borrowernumber => $patron_2->id, |
135 |
} |
136 |
} |
137 |
)->_move_to_old; |
138 |
|
139 |
$hold_1 = Koha::Old::Holds->find( $hold_1->id ) |
140 |
->set( { timestamp => dt_from_string() } )->store; |
141 |
$hold_2 = Koha::Old::Holds->find( $hold_2->id ) |
142 |
->set( { timestamp => dt_from_string()->subtract( days => 1 ) } )->store; |
143 |
$hold_3 = Koha::Old::Holds->find( $hold_3->id ) |
144 |
->set( { timestamp => dt_from_string()->subtract( days => 2 ) } )->store; |
145 |
$hold_4 = Koha::Old::Holds->find( $hold_4->id ) |
146 |
->set( { timestamp => dt_from_string()->subtract( days => 3 ) } )->store; |
147 |
|
148 |
is( $patron_1->old_holds->count, 2, 'patron_1 has 2 completed holds' ); |
149 |
is( $patron_2->old_holds->count, 2, 'patron_2 has 2 completed holds' ); |
150 |
|
151 |
# filter them so only the older two are part of the resultset |
152 |
my $holds = Koha::Old::Holds->search( |
153 |
{ 'me.borrowernumber' => [ $patron_1->id, $patron_2->id ] } ); |
154 |
is( $holds->count, 4, 'Total of 4 holds returned correctly' ); |
155 |
my $rs = $holds->filter_by_anonymizable; |
156 |
is( $rs->count, 2, 'Only 2 can be anonymized' ); |
157 |
|
158 |
$rs = $holds |
159 |
->filter_by_anonymizable |
160 |
->filter_by_last_update( { days => 1 } ); |
161 |
|
162 |
is( $rs->count, 1, 'Only 1 can be anonymized with date filter applied' ); |
163 |
|
164 |
$schema->storage->txn_rollback; |
165 |
}; |