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

(-)a/t/db_dependent/Koha/Old/Checkout.t (-6 / +31 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 63-82 subtest 'anonymize() tests' => sub { Link Here
63
    is( $@->syspref, 'AnonymousPatron', 'syspref parameter is correctly passed' );
82
    is( $@->syspref, 'AnonymousPatron', 'syspref parameter is correctly passed' );
64
    is( $patron->old_checkouts->count, 2, 'No changes, patron has 2 linked completed checkouts' );
83
    is( $patron->old_checkouts->count, 2, 'No changes, patron has 2 linked completed checkouts' );
65
84
66
    is( $checkout_1->borrowernumber, $patron->id,
67
        'Anonymized hold not linked to patron' );
68
    is( $checkout_2->borrowernumber, $patron->id,
85
    is( $checkout_2->borrowernumber, $patron->id,
69
        'Not anonymized hold still linked to patron' );
86
        'Checkout to anonymize still linked to patron' );
87
    is( $checkout_2->renewals->count, 2, 'Checkout 2 has 2 renewals' );
70
88
71
    my $anonymous_patron =
89
    my $anonymous_patron =
72
      $builder->build_object( { class => 'Koha::Patrons' } );
90
      $builder->build_object( { class => 'Koha::Patrons' } );
73
    t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id );
91
    t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id );
74
92
75
    # anonymize second hold
93
    # anonymize second checkout
76
    $checkout_2->anonymize;
94
    $checkout_2->anonymize;
77
    $checkout_2->discard_changes;
95
    $checkout_2->discard_changes;
78
    is( $checkout_2->borrowernumber, $anonymous_patron->id,
96
    is( $checkout_2->borrowernumber, $anonymous_patron->id,
79
        'Anonymized hold linked to anonymouspatron' );
97
        'Anonymized checkout linked to anonymouspatron' );
98
    is(
99
        $checkout_2->renewals->search(
100
            { renewer_id => $anonymous_patron->id }
101
        )->count,
102
        1,
103
        'OPAC renewal was anonymized'
104
    );
80
105
81
    $schema->storage->txn_rollback;
106
    $schema->storage->txn_rollback;
82
};
107
};
(-)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(
116
    my $checkouts = $patron->old_checkouts->filter_by_last_update(
Lines 112-117 subtest 'anonymize() tests' => sub { Link Here
112
    is( $anonymized_count, 2, 'update() tells 2 rows were updated' );
132
    is( $anonymized_count, 2, 'update() tells 2 rows were updated' );
113
133
114
    is( $patron->old_checkouts->count, 2, 'Patron has 2 completed checkouts' );
134
    is( $patron->old_checkouts->count, 2, 'Patron has 2 completed checkouts' );
135
    is( $checkout_4->renewals->count, 2, 'Checkout 4 still has 2 renewals' );
136
    is(
137
        $checkout_4->renewals->search( { renewer_id => $anonymous_patron->id } )->count,
138
        1,
139
        'OPAC renewal was anonymized'
140
    );
115
141
116
    $schema->storage->txn_rollback;
142
    $schema->storage->txn_rollback;
117
};
143
};
118
- 

Return to bug 33284