Lines 18-28
Link Here
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 2; |
20 |
use Test::More tests => 2; |
|
|
21 |
use Test::Exception; |
21 |
|
22 |
|
22 |
use Koha::Database; |
23 |
use Koha::Database; |
23 |
use Koha::DateUtils qw(dt_from_string); |
24 |
use Koha::DateUtils qw(dt_from_string); |
24 |
use Koha::Old::Holds; |
25 |
use Koha::Old::Holds; |
25 |
|
26 |
|
|
|
27 |
use t::lib::Mocks; |
26 |
use t::lib::TestBuilder; |
28 |
use t::lib::TestBuilder; |
27 |
|
29 |
|
28 |
my $schema = Koha::Database->new->schema; |
30 |
my $schema = Koha::Database->new->schema; |
Lines 30-42
my $builder = t::lib::TestBuilder->new;
Link Here
|
30 |
|
32 |
|
31 |
subtest 'anonymize() tests' => sub { |
33 |
subtest 'anonymize() tests' => sub { |
32 |
|
34 |
|
33 |
plan tests => 5; |
35 |
plan tests => 10; |
34 |
|
36 |
|
35 |
$schema->storage->txn_begin; |
37 |
$schema->storage->txn_begin; |
36 |
|
38 |
|
37 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
39 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
|
|
40 |
my $anonymous_patron = $builder->build_object({ class => 'Koha::Patrons' }); |
38 |
|
41 |
|
39 |
is( $patron->old_holds->count, 0, 'Patron has no old holds' ); |
42 |
is( $patron->old_holds->count, 0, 'Patron has no old holds' ); |
|
|
43 |
|
44 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', undef ); |
45 |
|
46 |
throws_ok |
47 |
{ $patron->old_holds->anonymize; } |
48 |
'Koha::Exceptions::SysPref::NotSet', |
49 |
'Exception thrown because AnonymousPatron not set'; |
50 |
|
51 |
is( $@->syspref, 'AnonymousPatron', 'syspref parameter is correctly passed' ); |
52 |
|
53 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id ); |
54 |
|
40 |
is( $patron->old_holds->anonymize + 0, 0, 'Anonymizing an empty resultset returns 0' ); |
55 |
is( $patron->old_holds->anonymize + 0, 0, 'Anonymizing an empty resultset returns 0' ); |
41 |
|
56 |
|
42 |
my $hold_1 = $builder->build_object( |
57 |
my $hold_1 = $builder->build_object( |
Lines 78-83
subtest 'anonymize() tests' => sub {
Link Here
|
78 |
# filter them so only the older two are part of the resultset |
93 |
# filter them so only the older two are part of the resultset |
79 |
my $holds = $patron->old_holds->search({ timestamp => { '<=' => dt_from_string()->subtract( days => 2 ) } }); |
94 |
my $holds = $patron->old_holds->search({ timestamp => { '<=' => dt_from_string()->subtract( days => 2 ) } }); |
80 |
# Anonymize them |
95 |
# Anonymize them |
|
|
96 |
|
97 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', undef ); |
98 |
throws_ok |
99 |
{ $holds->anonymize; } |
100 |
'Koha::Exceptions::SysPref::NotSet', |
101 |
'Exception thrown because AnonymousPatron not set'; |
102 |
|
103 |
is( $@->syspref, 'AnonymousPatron', 'syspref parameter is correctly passed' ); |
104 |
is( $patron->old_holds->count, 4, 'Patron has 4 completed holds' ); |
105 |
|
106 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id ); |
107 |
|
81 |
my $anonymized_count = $holds->anonymize(); |
108 |
my $anonymized_count = $holds->anonymize(); |
82 |
is( $anonymized_count, 2, 'update() tells 2 rows were updated' ); |
109 |
is( $anonymized_count, 2, 'update() tells 2 rows were updated' ); |
83 |
|
110 |
|
84 |
- |
|
|