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

(-)a/t/db_dependent/Circulation/AnonymiseIssueHistory.t (-313 lines)
Lines 1-313 Link Here
1
2
#!/usr/bin/perl
3
4
# This file is part of Koha.
5
#
6
# Koha is free software; you can redistribute it and/or modify it
7
# under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 3 of the License, or
9
# (at your option) any later version.
10
#
11
# Koha is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
19
use Modern::Perl;
20
21
use Test::More tests => 5;
22
23
use C4::Context;
24
use C4::Circulation;
25
26
use Koha::Database;
27
use Koha::Items;
28
29
use t::lib::Mocks;
30
use t::lib::TestBuilder;
31
32
my $schema  = Koha::Database->new->schema;
33
$schema->storage->txn_begin;
34
35
my $builder = t::lib::TestBuilder->new;
36
37
# TODO create a subroutine in t::lib::Mocks
38
my $branch = $builder->build({ source => 'Branch' });
39
my $userenv_patron = $builder->build({
40
    source => 'Borrower',
41
    value  => { branchcode => $branch->{branchcode} },
42
});
43
C4::Context->_new_userenv('DUMMY SESSION');
44
C4::Context->set_userenv(
45
    $userenv_patron->{borrowernumber},
46
    $userenv_patron->{userid},
47
    'usercnum', 'First name', 'Surname',
48
    $branch->{branchcode},
49
    $branch->{branchname},
50
    0,
51
);
52
53
my $anonymous = $builder->build( { source => 'Borrower', }, );
54
55
t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous->{borrowernumber} );
56
57
subtest 'patron privacy is 1 (default)' => sub {
58
    plan tests => 4;
59
    t::lib::Mocks::mock_preference('IndependentBranches', 0);
60
    my $patron = $builder->build(
61
        {   source => 'Borrower',
62
            value  => { privacy => 1, branchcode => $userenv_patron->{branchcode} }
63
        }
64
    );
65
    my $item = $builder->build(
66
        {   source => 'Item',
67
            value  => {
68
                itemlost  => 0,
69
                withdrawn => 0,
70
            },
71
        }
72
    );
73
    my $issue = $builder->build(
74
        {   source => 'Issue',
75
            value  => {
76
                borrowernumber => $patron->{borrowernumber},
77
                itemnumber     => $item->{itemnumber},
78
            },
79
        }
80
    );
81
82
    my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' );
83
    is( $returned, 1, 'The item should have been returned' );
84
    my ( $rows_affected, $err ) = C4::Circulation::AnonymiseIssueHistory('2010-10-11');
85
    ok( $rows_affected > 0, 'AnonymiseIssueHistory should affect at least 1 row' );
86
    is( $err, undef, 'AnonymiseIssueHistory should not return any error if success' );
87
88
    my $dbh = C4::Context->dbh;
89
    my ($borrowernumber_used_to_anonymised) = $dbh->selectrow_array(q|
90
        SELECT borrowernumber FROM old_issues where itemnumber = ?
91
    |, undef, $item->{itemnumber});
92
    is( $borrowernumber_used_to_anonymised, $anonymous->{borrowernumber}, 'With privacy=1, the issue should have been anonymised' );
93
94
};
95
96
subtest 'patron privacy is 0 (forever)' => sub {
97
    plan tests => 3;
98
    t::lib::Mocks::mock_preference('IndependentBranches', 0);
99
100
    my $patron = $builder->build(
101
        {   source => 'Borrower',
102
            value  => { privacy => 0, branchcode => $userenv_patron->{branchcode} }
103
        }
104
    );
105
    my $item = $builder->build(
106
        {   source => 'Item',
107
            value  => {
108
                itemlost  => 0,
109
                withdrawn => 0,
110
            },
111
        }
112
    );
113
    my $issue = $builder->build(
114
        {   source => 'Issue',
115
            value  => {
116
                borrowernumber => $patron->{borrowernumber},
117
                itemnumber     => $item->{itemnumber},
118
            },
119
        }
120
    );
121
122
    my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' );
123
    is( $returned, 1, 'The item should have been returned' );
124
    my ( $rows_affected, $err ) = C4::Circulation::AnonymiseIssueHistory('2010-10-11');
125
    is( $err, undef, 'AnonymiseIssueHistory should not return any error if success' );
126
127
    my $dbh = C4::Context->dbh;
128
    my ($borrowernumber_used_to_anonymised) = $dbh->selectrow_array(q|
129
        SELECT borrowernumber FROM old_issues where itemnumber = ?
130
    |, undef, $item->{itemnumber});
131
    is( $borrowernumber_used_to_anonymised, $patron->{borrowernumber}, 'With privacy=0, the issue should not be anonymised' );
132
};
133
134
t::lib::Mocks::mock_preference( 'AnonymousPatron', '' );
135
136
subtest 'AnonymousPatron is not defined' => sub {
137
    plan tests => 4;
138
    t::lib::Mocks::mock_preference('IndependentBranches', 0);
139
    my $patron = $builder->build(
140
        {   source => 'Borrower',
141
            value  => { privacy => 1, branchcode => $userenv_patron->{branchcode} }
142
        }
143
    );
144
    my $item = $builder->build(
145
        {   source => 'Item',
146
            value  => {
147
                itemlost  => 0,
148
                withdrawn => 0,
149
            },
150
        }
151
    );
152
    my $issue = $builder->build(
153
        {   source => 'Issue',
154
            value  => {
155
                borrowernumber => $patron->{borrowernumber},
156
                itemnumber     => $item->{itemnumber},
157
            },
158
        }
159
    );
160
161
    my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' );
162
    is( $returned, 1, 'The item should have been returned' );
163
    my ( $rows_affected, $err ) = C4::Circulation::AnonymiseIssueHistory('2010-10-11');
164
    ok( $rows_affected > 0, 'AnonymiseIssueHistory should affect at least 1 row' );
165
    is( $err, undef, 'AnonymiseIssueHistory should not return any error if success' );
166
167
    my $dbh = C4::Context->dbh;
168
    my ($borrowernumber_used_to_anonymised) = $dbh->selectrow_array(q|
169
        SELECT borrowernumber FROM old_issues where itemnumber = ?
170
    |, undef, $item->{itemnumber});
171
    is( $borrowernumber_used_to_anonymised, undef, 'With AnonymousPatron is not defined, the issue should have been anonymised anyway' );
172
};
173
174
subtest 'Logged in librarian is not superlibrarian & IndependentBranches' => sub {
175
    plan tests => 1;
176
    t::lib::Mocks::mock_preference('IndependentBranches', 1);
177
    my $patron = $builder->build(
178
        {   source => 'Borrower',
179
            value  => { privacy => 1 } # Another branchcode than the logged in librarian
180
        }
181
    );
182
    my $item = $builder->build(
183
        {   source => 'Item',
184
            value  => {
185
                itemlost  => 0,
186
                withdrawn => 0,
187
            },
188
        }
189
    );
190
    my $issue = $builder->build(
191
        {   source => 'Issue',
192
            value  => {
193
                borrowernumber => $patron->{borrowernumber},
194
                itemnumber     => $item->{itemnumber},
195
            },
196
        }
197
    );
198
199
    my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' );
200
    my $patrons_to_anonymise = C4::Members::GetBorrowersWithIssuesHistoryOlderThan( '2010-10-11' );
201
    my ( $rows_affected, $err ) = C4::Circulation::AnonymiseIssueHistory('2010-10-11');
202
    is( scalar(@$patrons_to_anonymise), $rows_affected, , 'AnonymiseIssueHistory should affect at least 1 row' );
203
};
204
205
subtest 'Test StoreLastBorrower' => sub {
206
    plan tests => 6;
207
208
    t::lib::Mocks::mock_preference( 'StoreLastBorrower', '1' );
209
210
    my $patron = $builder->build(
211
        {
212
            source => 'Borrower',
213
            value  => { privacy => 1, }
214
        }
215
    );
216
217
    my $item = $builder->build(
218
        {
219
            source => 'Item',
220
            value  => {
221
                itemlost  => 0,
222
                withdrawn => 0,
223
            },
224
        }
225
    );
226
227
    my $issue = $builder->build(
228
        {
229
            source => 'Issue',
230
            value  => {
231
                borrowernumber => $patron->{borrowernumber},
232
                itemnumber     => $item->{itemnumber},
233
            },
234
        }
235
    );
236
237
    my $item_object   = Koha::Items->find( $item->{itemnumber} );
238
    my $patron_object = $item_object->last_returned_by();
239
    is( $patron_object, undef, 'Koha::Item::last_returned_by returned undef' );
240
241
    my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' );
242
243
    $item_object   = Koha::Items->find( $item->{itemnumber} );
244
    $patron_object = $item_object->last_returned_by();
245
    is( ref($patron_object), 'Koha::Patron', 'Koha::Item::last_returned_by returned Koha::Patron' );
246
247
    $patron = $builder->build(
248
        {
249
            source => 'Borrower',
250
            value  => { privacy => 1, }
251
        }
252
    );
253
254
    $issue = $builder->build(
255
        {
256
            source => 'Issue',
257
            value  => {
258
                borrowernumber => $patron->{borrowernumber},
259
                itemnumber     => $item->{itemnumber},
260
            },
261
        }
262
    );
263
264
    ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' );
265
266
    $item_object   = Koha::Items->find( $item->{itemnumber} );
267
    $patron_object = $item_object->last_returned_by();
268
    is( $patron_object->id, $patron->{borrowernumber}, 'Second patron to return item replaces the first' );
269
270
    $patron = $builder->build(
271
        {
272
            source => 'Borrower',
273
            value  => { privacy => 1, }
274
        }
275
    );
276
    $patron_object = Koha::Patrons->find( $patron->{borrowernumber} );
277
278
    $item_object->last_returned_by($patron_object);
279
    $item_object = Koha::Items->find( $item->{itemnumber} );
280
    my $patron_object2 = $item_object->last_returned_by();
281
    is( $patron_object->id, $patron_object2->id,
282
        'Calling last_returned_by with Borrower object sets last_returned_by to that borrower' );
283
284
    $patron_object->delete;
285
    $item_object = Koha::Items->find( $item->{itemnumber} );
286
    is( $item_object->last_returned_by, undef, 'last_returned_by should return undef if the last patron to return the item has been deleted' );
287
288
    t::lib::Mocks::mock_preference( 'StoreLastBorrower', '0' );
289
    $patron = $builder->build(
290
        {
291
            source => 'Borrower',
292
            value  => { privacy => 1, }
293
        }
294
    );
295
296
    $issue = $builder->build(
297
        {
298
            source => 'Issue',
299
            value  => {
300
                borrowernumber => $patron->{borrowernumber},
301
                itemnumber     => $item->{itemnumber},
302
            },
303
        }
304
    );
305
    ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' );
306
307
    $item_object   = Koha::Items->find( $item->{itemnumber} );
308
    is( $item_object->last_returned_by, undef, 'Last patron to return item should not be stored if StoreLastBorrower if off' );
309
};
310
311
$schema->storage->txn_rollback;
312
313
1;
(-)a/t/db_dependent/Circulation/StoreLastBorrower.t (+144 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 1;
21
22
use C4::Context;
23
use C4::Circulation;
24
25
use Koha::Database;
26
use Koha::Items;
27
28
use t::lib::Mocks;
29
use t::lib::TestBuilder;
30
31
my $schema  = Koha::Database->new->schema;
32
$schema->storage->txn_begin;
33
34
my $builder = t::lib::TestBuilder->new;
35
36
subtest 'Test StoreLastBorrower' => sub {
37
    plan tests => 6;
38
39
    t::lib::Mocks::mock_preference( 'StoreLastBorrower', '1' );
40
41
    my $patron = $builder->build(
42
        {
43
            source => 'Borrower',
44
            value  => { privacy => 1, }
45
        }
46
    );
47
48
    my $item = $builder->build(
49
        {
50
            source => 'Item',
51
            value  => {
52
                itemlost  => 0,
53
                withdrawn => 0,
54
            },
55
        }
56
    );
57
58
    my $issue = $builder->build(
59
        {
60
            source => 'Issue',
61
            value  => {
62
                borrowernumber => $patron->{borrowernumber},
63
                itemnumber     => $item->{itemnumber},
64
            },
65
        }
66
    );
67
68
    my $item_object   = Koha::Items->find( $item->{itemnumber} );
69
    my $patron_object = $item_object->last_returned_by();
70
    is( $patron_object, undef, 'Koha::Item::last_returned_by returned undef' );
71
72
    my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, $patron->{branchcode}, undef, undef, '2010-10-10' );
73
74
    $item_object   = Koha::Items->find( $item->{itemnumber} );
75
    $patron_object = $item_object->last_returned_by();
76
    is( ref($patron_object), 'Koha::Patron', 'Koha::Item::last_returned_by returned Koha::Patron' );
77
78
    $patron = $builder->build(
79
        {
80
            source => 'Borrower',
81
            value  => { privacy => 1, }
82
        }
83
    );
84
85
    $issue = $builder->build(
86
        {
87
            source => 'Issue',
88
            value  => {
89
                borrowernumber => $patron->{borrowernumber},
90
                itemnumber     => $item->{itemnumber},
91
            },
92
        }
93
    );
94
95
    ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, $patron->{branchcode}, undef, undef, '2010-10-10' );
96
97
    $item_object   = Koha::Items->find( $item->{itemnumber} );
98
    $patron_object = $item_object->last_returned_by();
99
    is( $patron_object->id, $patron->{borrowernumber}, 'Second patron to return item replaces the first' );
100
101
    $patron = $builder->build(
102
        {
103
            source => 'Borrower',
104
            value  => { privacy => 1, }
105
        }
106
    );
107
    $patron_object = Koha::Patrons->find( $patron->{borrowernumber} );
108
109
    $item_object->last_returned_by($patron_object);
110
    $item_object = Koha::Items->find( $item->{itemnumber} );
111
    my $patron_object2 = $item_object->last_returned_by();
112
    is( $patron_object->id, $patron_object2->id,
113
        'Calling last_returned_by with Borrower object sets last_returned_by to that borrower' );
114
115
    $patron_object->delete;
116
    $item_object = Koha::Items->find( $item->{itemnumber} );
117
    is( $item_object->last_returned_by, undef, 'last_returned_by should return undef if the last patron to return the item has been deleted' );
118
119
    t::lib::Mocks::mock_preference( 'StoreLastBorrower', '0' );
120
    $patron = $builder->build(
121
        {
122
            source => 'Borrower',
123
            value  => { privacy => 1, }
124
        }
125
    );
126
127
    $issue = $builder->build(
128
        {
129
            source => 'Issue',
130
            value  => {
131
                borrowernumber => $patron->{borrowernumber},
132
                itemnumber     => $item->{itemnumber},
133
            },
134
        }
135
    );
136
    ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, $patron->{branchcode}, undef, undef, '2010-10-10' );
137
138
    $item_object   = Koha::Items->find( $item->{itemnumber} );
139
    is( $item_object->last_returned_by, undef, 'Last patron to return item should not be stored if StoreLastBorrower if off' );
140
};
141
142
$schema->storage->txn_rollback;
143
144
1;
(-)a/t/db_dependent/Koha/Patrons.t (-2 / +182 lines)
Lines 19-27 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 6;
22
use Test::More tests => 7;
23
use Test::Warn;
23
use Test::Warn;
24
24
25
use C4::Circulation;
26
27
use C4::Circulation;
25
use Koha::Patron;
28
use Koha::Patron;
26
use Koha::Patrons;
29
use Koha::Patrons;
27
use Koha::Database;
30
use Koha::Database;
Lines 55-60 my $new_patron_2 = Koha::Patron->new( Link Here
55
    }
58
    }
56
)->store;
59
)->store;
57
60
61
C4::Context->_new_userenv('xxx');
62
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, 'Midway Public Library', '', '', '');
63
58
is( Koha::Patrons->search->count, $nb_of_patrons + 2, 'The 2 patrons should have been added' );
64
is( Koha::Patrons->search->count, $nb_of_patrons + 2, 'The 2 patrons should have been added' );
59
65
60
my $retrieved_patron_1 = Koha::Patrons->find( $new_patron_1->borrowernumber );
66
my $retrieved_patron_1 = Koha::Patrons->find( $new_patron_1->borrowernumber );
Lines 127-132 subtest 'update_password' => sub { Link Here
127
    is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->update_password should not have logged' );
133
    is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->update_password should not have logged' );
128
};
134
};
129
135
136
subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub {
137
    plan tests => 4;
138
139
    # TODO create a subroutine in t::lib::Mocks
140
    my $branch = $builder->build({ source => 'Branch' });
141
    my $userenv_patron = $builder->build({
142
        source => 'Borrower',
143
        value  => { branchcode => $branch->{branchcode} },
144
    });
145
    C4::Context->_new_userenv('DUMMY SESSION');
146
    C4::Context->set_userenv(
147
        $userenv_patron->{borrowernumber},
148
        $userenv_patron->{userid},
149
        'usercnum', 'First name', 'Surname',
150
        $branch->{branchcode},
151
        $branch->{branchname},
152
        0,
153
    );
154
    my $anonymous = $builder->build( { source => 'Borrower', }, );
155
156
    t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous->{borrowernumber} );
157
158
    subtest 'patron privacy is 1 (default)' => sub {
159
        plan tests => 3;
160
161
        t::lib::Mocks::mock_preference('IndependentBranches', 0);
162
        my $patron = $builder->build(
163
            {   source => 'Borrower',
164
                value  => { privacy => 1, }
165
            }
166
        );
167
        my $item = $builder->build(
168
            {   source => 'Item',
169
                value  => {
170
                    itemlost  => 0,
171
                    withdrawn => 0,
172
                },
173
            }
174
        );
175
        my $issue = $builder->build(
176
            {   source => 'Issue',
177
                value  => {
178
                    borrowernumber => $patron->{borrowernumber},
179
                    itemnumber     => $item->{itemnumber},
180
                },
181
            }
182
        );
183
184
        my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' );
185
        is( $returned, 1, 'The item should have been returned' );
186
        my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( '2010-10-11')->anonymise_issue_history('2010-10-11');
187
        ok( $rows_affected > 0, 'AnonymiseIssueHistory should affect at least 1 row' );
188
189
        my $dbh = C4::Context->dbh;
190
        my ($borrowernumber_used_to_anonymised) = $dbh->selectrow_array(q|
191
            SELECT borrowernumber FROM old_issues where itemnumber = ?
192
        |, undef, $item->{itemnumber});
193
        is( $borrowernumber_used_to_anonymised, $anonymous->{borrowernumber}, 'With privacy=1, the issue should have been anonymised' );
194
        Koha::Patrons->find( $patron->{borrowernumber})->delete;
195
    };
196
197
    subtest 'patron privacy is 0 (forever)' => sub {
198
        plan tests => 3;
199
200
        t::lib::Mocks::mock_preference('IndependentBranches', 0);
201
        my $patron = $builder->build(
202
            {   source => 'Borrower',
203
                value  => { privacy => 0, }
204
            }
205
        );
206
        my $item = $builder->build(
207
            {   source => 'Item',
208
                value  => {
209
                    itemlost  => 0,
210
                    withdrawn => 0,
211
                },
212
            }
213
        );
214
        my $issue = $builder->build(
215
            {   source => 'Issue',
216
                value  => {
217
                    borrowernumber => $patron->{borrowernumber},
218
                    itemnumber     => $item->{itemnumber},
219
                },
220
            }
221
        );
222
223
        my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' );
224
        is( $returned, 1, 'The item should have been returned' );
225
        my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( '2010-10-11')->anonymise_issue_history('2010-10-11');
226
        ok( $rows_affected > 0, 'AnonymiseIssueHistory should not return any error if success' );
227
228
        my $dbh = C4::Context->dbh;
229
        my ($borrowernumber_used_to_anonymised) = $dbh->selectrow_array(q|
230
            SELECT borrowernumber FROM old_issues where itemnumber = ?
231
        |, undef, $item->{itemnumber});
232
        is( $borrowernumber_used_to_anonymised, $patron->{borrowernumber}, 'With privacy=0, the issue should not be anonymised' );
233
        Koha::Patrons->find( $patron->{borrowernumber})->delete;
234
    };
235
236
    t::lib::Mocks::mock_preference( 'AnonymousPatron', '' );
237
238
    subtest 'AnonymousPatron is not defined' => sub {
239
        plan tests => 3;
240
241
        t::lib::Mocks::mock_preference('IndependentBranches', 0);
242
        my $patron = $builder->build(
243
            {   source => 'Borrower',
244
                value  => { privacy => 1, }
245
            }
246
        );
247
        my $item = $builder->build(
248
            {   source => 'Item',
249
                value  => {
250
                    itemlost  => 0,
251
                    withdrawn => 0,
252
                },
253
            }
254
        );
255
        my $issue = $builder->build(
256
            {   source => 'Issue',
257
                value  => {
258
                    borrowernumber => $patron->{borrowernumber},
259
                    itemnumber     => $item->{itemnumber},
260
                },
261
            }
262
        );
263
264
        my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' );
265
        is( $returned, 1, 'The item should have been returned' );
266
        my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( '2010-10-11')->anonymise_issue_history('2010-10-11');
267
        ok( $rows_affected > 0, 'AnonymiseIssueHistory should affect at least 1 row' );
268
269
        my $dbh = C4::Context->dbh;
270
        my ($borrowernumber_used_to_anonymised) = $dbh->selectrow_array(q|
271
            SELECT borrowernumber FROM old_issues where itemnumber = ?
272
        |, undef, $item->{itemnumber});
273
        is( $borrowernumber_used_to_anonymised, undef, 'With AnonymousPatron is not defined, the issue should have been anonymised anyway' );
274
        Koha::Patrons->find( $patron->{borrowernumber})->delete;
275
    };
276
277
    subtest 'Logged in librarian is not superlibrarian & IndependentBranches' => sub {
278
        plan tests => 1;
279
        t::lib::Mocks::mock_preference( 'IndependentBranches', 1 );
280
        my $patron = $builder->build(
281
            {   source => 'Borrower',
282
                value  => { privacy => 1 }    # Another branchcode than the logged in librarian
283
            }
284
        );
285
        my $item = $builder->build(
286
            {   source => 'Item',
287
                value  => {
288
                    itemlost  => 0,
289
                    withdrawn => 0,
290
                },
291
            }
292
        );
293
        my $issue = $builder->build(
294
            {   source => 'Issue',
295
                value  => {
296
                    borrowernumber => $patron->{borrowernumber},
297
                    itemnumber     => $item->{itemnumber},
298
                },
299
            }
300
        );
301
302
        my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' );
303
        is( Koha::Patrons->search_patrons_to_anonymise( '2010-10-11')->count, 0 );
304
        Koha::Patrons->find( $patron->{borrowernumber})->delete;
305
    };
306
307
    Koha::Patrons->find( $anonymous->{borrowernumber})->delete;
308
    Koha::Patrons->find( $userenv_patron->{borrowernumber})->delete;
309
};
310
130
$retrieved_patron_1->delete;
311
$retrieved_patron_1->delete;
131
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
312
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
132
313
133
- 

Return to bug 16966