|
Lines 1-8
Link Here
|
| 1 |
use Modern::Perl; |
1 |
use Modern::Perl; |
| 2 |
use Test::More tests => 3; |
2 |
use Test::More tests => 4; |
| 3 |
|
3 |
|
| 4 |
use C4::Context; |
4 |
use C4::Context; |
| 5 |
use C4::Circulation; |
5 |
use C4::Circulation; |
|
|
6 |
use Koha::Items; |
| 6 |
use t::lib::Mocks; |
7 |
use t::lib::Mocks; |
| 7 |
use t::lib::TestBuilder; |
8 |
use t::lib::TestBuilder; |
| 8 |
|
9 |
|
|
Lines 136-138
subtest 'AnonymousPatron is not defined' => sub {
Link Here
|
| 136 |
|, undef, $item->{itemnumber}); |
137 |
|, undef, $item->{itemnumber}); |
| 137 |
is( $borrowernumber_used_to_anonymised, undef, 'With AnonymousPatron is not defined, the issue should have been anonymised anyway' ); |
138 |
is( $borrowernumber_used_to_anonymised, undef, 'With AnonymousPatron is not defined, the issue should have been anonymised anyway' ); |
| 138 |
}; |
139 |
}; |
| 139 |
- |
140 |
|
|
|
141 |
subtest 'Test StoreLastBorrower' => sub { |
| 142 |
plan tests => 4; |
| 143 |
|
| 144 |
t::lib::Mocks::mock_preference( 'StoreLastBorrower', '1' ); |
| 145 |
|
| 146 |
my $patron = $builder->build( |
| 147 |
{ |
| 148 |
source => 'Borrower', |
| 149 |
value => { privacy => 1, } |
| 150 |
} |
| 151 |
); |
| 152 |
|
| 153 |
my $item = $builder->build( |
| 154 |
{ |
| 155 |
source => 'Item', |
| 156 |
value => { |
| 157 |
itemlost => 0, |
| 158 |
withdrawn => 0, |
| 159 |
}, |
| 160 |
} |
| 161 |
); |
| 162 |
|
| 163 |
my $issue = $builder->build( |
| 164 |
{ |
| 165 |
source => 'Issue', |
| 166 |
value => { |
| 167 |
borrowernumber => $patron->{borrowernumber}, |
| 168 |
itemnumber => $item->{itemnumber}, |
| 169 |
}, |
| 170 |
} |
| 171 |
); |
| 172 |
|
| 173 |
my $item_object = Koha::Items->find( $item->{itemnumber} ); |
| 174 |
my $patron_object = $item_object->last_returned_by(); |
| 175 |
is( $patron_object, undef, 'Koha::Item::last_returned_by returned undef' ); |
| 176 |
|
| 177 |
my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' ); |
| 178 |
|
| 179 |
$item_object = Koha::Items->find( $item->{itemnumber} ); |
| 180 |
$patron_object = $item_object->last_returned_by(); |
| 181 |
is( ref($patron_object), 'Koha::Borrower', 'Koha::Item::last_returned_by returned Koha::Borrower' ); |
| 182 |
|
| 183 |
$patron = $builder->build( |
| 184 |
{ |
| 185 |
source => 'Borrower', |
| 186 |
value => { privacy => 1, } |
| 187 |
} |
| 188 |
); |
| 189 |
|
| 190 |
$issue = $builder->build( |
| 191 |
{ |
| 192 |
source => 'Issue', |
| 193 |
value => { |
| 194 |
borrowernumber => $patron->{borrowernumber}, |
| 195 |
itemnumber => $item->{itemnumber}, |
| 196 |
}, |
| 197 |
} |
| 198 |
); |
| 199 |
|
| 200 |
( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' ); |
| 201 |
|
| 202 |
$item_object = Koha::Items->find( $item->{itemnumber} ); |
| 203 |
$patron_object = $item_object->last_returned_by(); |
| 204 |
is( $patron_object->id, $patron->{borrowernumber}, 'Second patron to return item replaces the first' ); |
| 205 |
|
| 206 |
$patron = $builder->build( |
| 207 |
{ |
| 208 |
source => 'Borrower', |
| 209 |
value => { privacy => 1, } |
| 210 |
} |
| 211 |
); |
| 212 |
$patron_object = Koha::Borrowers->find( $patron->{borrowernumber} ); |
| 213 |
|
| 214 |
$item_object->last_returned_by($patron_object); |
| 215 |
$item_object = Koha::Items->find( $item->{itemnumber} ); |
| 216 |
my $patron_object2 = $item_object->last_returned_by(); |
| 217 |
is( $patron_object->id, $patron_object2->id, |
| 218 |
'Calling last_returned_by with Borrower object sets last_returned_by to that borrower' ); |
| 219 |
}; |