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

(-)a/t/db_dependent/Koha/Old/Checkout.t (-8 / +29 lines)
Lines 30-36 my $builder = t::lib::TestBuilder->new; Link Here
30
30
31
subtest 'anonymize() tests' => sub {
31
subtest 'anonymize() tests' => sub {
32
32
33
    plan tests => 8;
33
    plan tests => 9;
34
34
35
    $schema->storage->txn_begin;
35
    $schema->storage->txn_begin;
36
36
Lines 50-55 subtest 'anonymize() tests' => sub { Link Here
50
            value => { borrowernumber => $patron->id }
50
            value => { borrowernumber => $patron->id }
51
        }
51
        }
52
    );
52
    );
53
    my $renewal_1 = $builder->build_object(
54
        {
55
            class => 'Koha::Checkouts::Renewals',
56
            value => {
57
                checkout_id => $checkout_2->id,
58
                interface   => 'opac',
59
                renewer_id  => $patron->id
60
            }
61
        }
62
    );
63
    my $renewal_2 = $builder->build_object(
64
        {
65
            class => 'Koha::Checkouts::Renewals',
66
            value => {
67
                checkout_id => $checkout_2->id,
68
                interface   => 'intranet'
69
            }
70
        }
71
    );
53
72
54
    is( $patron->old_checkouts->count, 2, 'Patron has 2 completed checkouts' );
73
    is( $patron->old_checkouts->count, 2, 'Patron has 2 completed checkouts' );
55
74
Lines 62-85 subtest 'anonymize() tests' => sub { Link Here
62
    is( $@->syspref,                   'AnonymousPatron', 'syspref parameter is correctly passed' );
81
    is( $@->syspref,                   'AnonymousPatron', 'syspref parameter is correctly passed' );
63
    is( $patron->old_checkouts->count, 2,                 'No changes, patron has 2 linked completed checkouts' );
82
    is( $patron->old_checkouts->count, 2,                 'No changes, patron has 2 linked completed checkouts' );
64
83
65
    is(
66
        $checkout_1->borrowernumber, $patron->id,
67
        'Anonymized hold not linked to patron'
68
    );
69
    is(
84
    is(
70
        $checkout_2->borrowernumber, $patron->id,
85
        $checkout_2->borrowernumber, $patron->id,
71
        'Not anonymized hold still linked to patron'
86
        'Checkout to anonymize still linked to patron'
72
    );
87
    );
88
    is( $checkout_2->renewals->count, 2, 'Checkout 2 has 2 renewals' );
73
89
74
    my $anonymous_patron = $builder->build_object( { class => 'Koha::Patrons' } );
90
    my $anonymous_patron = $builder->build_object( { class => 'Koha::Patrons' } );
75
    t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id );
91
    t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id );
76
92
77
    # anonymize second hold
93
    # anonymize second checkout
78
    $checkout_2->anonymize;
94
    $checkout_2->anonymize;
79
    $checkout_2->discard_changes;
95
    $checkout_2->discard_changes;
80
    is(
96
    is(
81
        $checkout_2->borrowernumber, $anonymous_patron->id,
97
        $checkout_2->borrowernumber, $anonymous_patron->id,
82
        'Anonymized hold linked to anonymouspatron'
98
        'Anonymized checkout linked to anonymouspatron'
99
    );
100
    is(
101
        $checkout_2->renewals->search( { renewer_id => $anonymous_patron->id } )->count,
102
        1,
103
        'OPAC renewal was anonymized'
83
    );
104
    );
84
105
85
    $schema->storage->txn_rollback;
106
    $schema->storage->txn_rollback;
(-)a/t/db_dependent/Koha/Old/Checkouts.t (-2 / +27 lines)
Lines 32-38 my $builder = t::lib::TestBuilder->new; Link Here
32
32
33
subtest 'anonymize() tests' => sub {
33
subtest 'anonymize() tests' => sub {
34
34
35
    plan tests => 10;
35
    plan tests => 13;
36
36
37
    $schema->storage->txn_begin;
37
    $schema->storage->txn_begin;
38
38
Lines 89-96 subtest 'anonymize() tests' => sub { Link Here
89
            }
89
            }
90
        }
90
        }
91
    );
91
    );
92
    my $renewal_1 = $builder->build_object(
93
        {
94
            class => 'Koha::Checkouts::Renewals',
95
            value => {
96
                checkout_id => $checkout_4->id,
97
                interface   => 'opac',
98
                renewer_id  => $patron->id
99
            }
100
        }
101
    );
102
    my $renewal_2 = $builder->build_object(
103
        {
104
            class => 'Koha::Checkouts::Renewals',
105
            value => {
106
                checkout_id => $checkout_4->id,
107
                interface   => 'intranet'
108
            }
109
        }
110
    );
92
111
93
    is( $patron->old_checkouts->count, 4, 'Patron has 4 completed checkouts' );
112
    is( $patron->old_checkouts->count, 4, 'Patron has 4 completed checkouts' );
113
    is( $checkout_4->renewals->count,  2, 'Checkout 4 has 2 renewals' );
94
114
95
    # filter them so only the older two are part of the resultset
115
    # filter them so only the older two are part of the resultset
96
    my $checkouts = $patron->old_checkouts->filter_by_last_update( { min_days => 1 } );
116
    my $checkouts = $patron->old_checkouts->filter_by_last_update( { min_days => 1 } );
Lines 110-115 subtest 'anonymize() tests' => sub { Link Here
110
    is( $anonymized_count, 2, 'update() tells 2 rows were updated' );
130
    is( $anonymized_count, 2, 'update() tells 2 rows were updated' );
111
131
112
    is( $patron->old_checkouts->count, 2, 'Patron has 2 completed checkouts' );
132
    is( $patron->old_checkouts->count, 2, 'Patron has 2 completed checkouts' );
133
    is( $checkout_4->renewals->count,  2, 'Checkout 4 still has 2 renewals' );
134
    is(
135
        $checkout_4->renewals->search( { renewer_id => $anonymous_patron->id } )->count,
136
        1,
137
        'OPAC renewal was anonymized'
138
    );
113
139
114
    $schema->storage->txn_rollback;
140
    $schema->storage->txn_rollback;
115
};
141
};
116
- 

Return to bug 33284