|
Lines 18-28
Link Here
|
| 18 |
|
18 |
|
| 19 |
use Modern::Perl; |
19 |
use Modern::Perl; |
| 20 |
|
20 |
|
| 21 |
use Test::More tests => 3; |
21 |
use Test::More tests => 4; |
| 22 |
|
22 |
|
| 23 |
use C4::Context; |
23 |
use C4::Context; |
| 24 |
use C4::Circulation; |
24 |
use C4::Circulation; |
|
|
25 |
|
| 25 |
use Koha::Database; |
26 |
use Koha::Database; |
|
|
27 |
use Koha::Items; |
| 26 |
|
28 |
|
| 27 |
use t::lib::Mocks; |
29 |
use t::lib::Mocks; |
| 28 |
use t::lib::TestBuilder; |
30 |
use t::lib::TestBuilder; |
|
Lines 161-166
subtest 'AnonymousPatron is not defined' => sub {
Link Here
|
| 161 |
is( $borrowernumber_used_to_anonymised, undef, 'With AnonymousPatron is not defined, the issue should have been anonymised anyway' ); |
163 |
is( $borrowernumber_used_to_anonymised, undef, 'With AnonymousPatron is not defined, the issue should have been anonymised anyway' ); |
| 162 |
}; |
164 |
}; |
| 163 |
|
165 |
|
|
|
166 |
subtest 'Test StoreLastBorrower' => sub { |
| 167 |
plan tests => 4; |
| 168 |
|
| 169 |
t::lib::Mocks::mock_preference( 'StoreLastBorrower', '1' ); |
| 170 |
|
| 171 |
my $patron = $builder->build( |
| 172 |
{ |
| 173 |
source => 'Borrower', |
| 174 |
value => { privacy => 1, } |
| 175 |
} |
| 176 |
); |
| 177 |
|
| 178 |
my $item = $builder->build( |
| 179 |
{ |
| 180 |
source => 'Item', |
| 181 |
value => { |
| 182 |
itemlost => 0, |
| 183 |
withdrawn => 0, |
| 184 |
}, |
| 185 |
} |
| 186 |
); |
| 187 |
|
| 188 |
my $issue = $builder->build( |
| 189 |
{ |
| 190 |
source => 'Issue', |
| 191 |
value => { |
| 192 |
borrowernumber => $patron->{borrowernumber}, |
| 193 |
itemnumber => $item->{itemnumber}, |
| 194 |
}, |
| 195 |
} |
| 196 |
); |
| 197 |
|
| 198 |
my $item_object = Koha::Items->find( $item->{itemnumber} ); |
| 199 |
my $patron_object = $item_object->last_returned_by(); |
| 200 |
is( $patron_object, undef, 'Koha::Item::last_returned_by returned undef' ); |
| 201 |
|
| 202 |
my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' ); |
| 203 |
|
| 204 |
$item_object = Koha::Items->find( $item->{itemnumber} ); |
| 205 |
$patron_object = $item_object->last_returned_by(); |
| 206 |
is( ref($patron_object), 'Koha::Borrower', 'Koha::Item::last_returned_by returned Koha::Borrower' ); |
| 207 |
|
| 208 |
$patron = $builder->build( |
| 209 |
{ |
| 210 |
source => 'Borrower', |
| 211 |
value => { privacy => 1, } |
| 212 |
} |
| 213 |
); |
| 214 |
|
| 215 |
$issue = $builder->build( |
| 216 |
{ |
| 217 |
source => 'Issue', |
| 218 |
value => { |
| 219 |
borrowernumber => $patron->{borrowernumber}, |
| 220 |
itemnumber => $item->{itemnumber}, |
| 221 |
}, |
| 222 |
} |
| 223 |
); |
| 224 |
|
| 225 |
( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' ); |
| 226 |
|
| 227 |
$item_object = Koha::Items->find( $item->{itemnumber} ); |
| 228 |
$patron_object = $item_object->last_returned_by(); |
| 229 |
is( $patron_object->id, $patron->{borrowernumber}, 'Second patron to return item replaces the first' ); |
| 230 |
|
| 231 |
$patron = $builder->build( |
| 232 |
{ |
| 233 |
source => 'Borrower', |
| 234 |
value => { privacy => 1, } |
| 235 |
} |
| 236 |
); |
| 237 |
$patron_object = Koha::Borrowers->find( $patron->{borrowernumber} ); |
| 238 |
|
| 239 |
$item_object->last_returned_by($patron_object); |
| 240 |
$item_object = Koha::Items->find( $item->{itemnumber} ); |
| 241 |
my $patron_object2 = $item_object->last_returned_by(); |
| 242 |
is( $patron_object->id, $patron_object2->id, |
| 243 |
'Calling last_returned_by with Borrower object sets last_returned_by to that borrower' ); |
| 244 |
}; |
| 245 |
|
| 164 |
$schema->storage->txn_rollback; |
246 |
$schema->storage->txn_rollback; |
| 165 |
|
247 |
|
| 166 |
1; |
248 |
1; |
| 167 |
- |
|
|