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

(-)a/t/db_dependent/Koha/Old/Checkouts.t (-1 / +26 lines)
Lines 18-23 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);
Lines 31-43 my $builder = t::lib::TestBuilder->new; Link Here
31
32
32
subtest 'anonymize() tests' => sub {
33
subtest 'anonymize() tests' => sub {
33
34
34
    plan tests => 5;
35
    plan tests => 10;
35
36
36
    $schema->storage->txn_begin;
37
    $schema->storage->txn_begin;
37
38
38
    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' });
39
41
40
    is( $patron->old_checkouts->count, 0, 'Patron has no old checkouts' );
42
    is( $patron->old_checkouts->count, 0, 'Patron has no old checkouts' );
43
44
    t::lib::Mocks::mock_preference( 'AnonymousPatron', undef );
45
46
    throws_ok
47
        { $patron->old_checkouts->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
41
    is( $patron->old_checkouts->anonymize + 0,
55
    is( $patron->old_checkouts->anonymize + 0,
42
        0, 'Anonymizing an empty resultset returns 0' );
56
        0, 'Anonymizing an empty resultset returns 0' );
43
57
Lines 82-87 subtest 'anonymize() tests' => sub { Link Here
82
    my $checkouts = $patron->old_checkouts->filter_by_last_update(
96
    my $checkouts = $patron->old_checkouts->filter_by_last_update(
83
        { days => 1, days_inclusive => 1 } );
97
        { days => 1, days_inclusive => 1 } );
84
98
99
    t::lib::Mocks::mock_preference( 'AnonymousPatron', undef );
100
    throws_ok
101
        { $checkouts->anonymize; }
102
        'Koha::Exceptions::SysPref::NotSet',
103
        'Exception thrown because AnonymousPatron not set';
104
105
    is( $@->syspref, 'AnonymousPatron', 'syspref parameter is correctly passed' );
106
    is( $patron->old_checkouts->count, 4, 'Patron has 4 completed checkouts' );
107
108
    t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id );
109
85
    # Anonymize them
110
    # Anonymize them
86
    my $anonymized_count = $checkouts->anonymize();
111
    my $anonymized_count = $checkouts->anonymize();
87
    is( $anonymized_count, 2, 'update() tells 2 rows were updated' );
112
    is( $anonymized_count, 2, 'update() tells 2 rows were updated' );
(-)a/t/db_dependent/Koha/Old/Hold.t (-7 / +9 lines)
Lines 18-23 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 1;
20
use Test::More tests => 1;
21
use Test::Exception;
21
22
22
use Koha::Database;
23
use Koha::Database;
23
24
Lines 29-35 my $builder = t::lib::TestBuilder->new; Link Here
29
30
30
subtest 'anonymize() tests' => sub {
31
subtest 'anonymize() tests' => sub {
31
32
32
    plan tests => 6;
33
    plan tests => 8;
33
34
34
    $schema->storage->txn_begin;
35
    $schema->storage->txn_begin;
35
36
Lines 54-67 subtest 'anonymize() tests' => sub { Link Here
54
55
55
    t::lib::Mocks::mock_preference( 'AnonymousPatron', undef );
56
    t::lib::Mocks::mock_preference( 'AnonymousPatron', undef );
56
57
57
    $hold_1->anonymize;
58
    throws_ok
59
        { $hold_1->anonymize; }
60
        'Koha::Exceptions::SysPref::NotSet',
61
        'Exception thrown because AnonymousPatron not set';
58
62
59
    is( $patron->old_holds->count, 1, 'Patron has 1 linked completed holds' );
63
    is( $@->syspref, 'AnonymousPatron', 'syspref parameter is correctly passed' );
64
    is( $patron->old_holds->count, 2, 'No changes, patron has 2 linked completed holds' );
60
65
61
    # Reload
66
    is( $hold_1->borrowernumber, $patron->id,
62
    $hold_1->discard_changes;
63
    $hold_2->discard_changes;
64
    is( $hold_1->borrowernumber, undef,
65
        'Anonymized hold not linked to patron' );
67
        'Anonymized hold not linked to patron' );
66
    is( $hold_2->borrowernumber, $patron->id,
68
    is( $hold_2->borrowernumber, $patron->id,
67
        'Not anonymized hold still linked to patron' );
69
        'Not anonymized hold still linked to patron' );
(-)a/t/db_dependent/Koha/Old/Holds.t (-2 / +28 lines)
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
- 

Return to bug 3007