Lines 152-159
subtest 'Test StoreLastBorrower with multiple borrowers' => sub {
Link Here
|
152 |
|
152 |
|
153 |
# Test last_returned_by_all with no borrowers |
153 |
# Test last_returned_by_all with no borrowers |
154 |
t::lib::Mocks::mock_preference( 'StoreLastBorrower', '3' ); |
154 |
t::lib::Mocks::mock_preference( 'StoreLastBorrower', '3' ); |
155 |
my @borrowers = $item->last_returned_by_all(); |
155 |
my $borrowers = $item->last_returned_by_all(); |
156 |
is( scalar(@borrowers), 0, 'last_returned_by_all returns empty array when no borrowers stored' ); |
156 |
is( scalar(@$borrowers), 0, 'last_returned_by_all returns empty array when no borrowers stored' ); |
157 |
|
157 |
|
158 |
# Add 3 borrowers for testing, checkout/check in |
158 |
# Add 3 borrowers for testing, checkout/check in |
159 |
my @patrons; |
159 |
my @patrons; |
Lines 183-195
subtest 'Test StoreLastBorrower with multiple borrowers' => sub {
Link Here
|
183 |
$item = $item->get_from_storage; |
183 |
$item = $item->get_from_storage; |
184 |
|
184 |
|
185 |
# Test last_returned_by_all returns all borrowers |
185 |
# Test last_returned_by_all returns all borrowers |
186 |
@borrowers = $item->last_returned_by_all(); |
186 |
$borrowers = $item->last_returned_by_all(); |
187 |
is( scalar(@borrowers), 3, 'Correctly returns 3 borrowers' ); |
187 |
is( scalar(@$borrowers), 3, 'Correctly returns 3 borrowers' ); |
188 |
|
188 |
|
189 |
# Test ordering |
189 |
# Test ordering |
190 |
is( $borrowers[0]->borrowernumber, $patrons[2]->{borrowernumber}, 'Most recent borrower first' ); |
190 |
is( $borrowers->[0]->borrowernumber, $patrons[2]->{borrowernumber}, 'Most recent borrower first' ); |
191 |
is( $borrowers[1]->borrowernumber, $patrons[1]->{borrowernumber}, 'Second most recent borrower second' ); |
191 |
is( $borrowers->[1]->borrowernumber, $patrons[1]->{borrowernumber}, 'Second most recent borrower second' ); |
192 |
is( $borrowers[2]->borrowernumber, $patrons[0]->{borrowernumber}, 'Oldest borrower last' ); |
192 |
is( $borrowers->[2]->borrowernumber, $patrons[0]->{borrowernumber}, 'Oldest borrower last' ); |
193 |
|
193 |
|
194 |
# Add 2 more borrowers/check out/check in |
194 |
# Add 2 more borrowers/check out/check in |
195 |
for my $i ( 4 .. 5 ) { |
195 |
for my $i ( 4 .. 5 ) { |
Lines 216-227
subtest 'Test StoreLastBorrower with multiple borrowers' => sub {
Link Here
|
216 |
} |
216 |
} |
217 |
|
217 |
|
218 |
$item = $item->get_from_storage; |
218 |
$item = $item->get_from_storage; |
219 |
@borrowers = $item->last_returned_by_all(); |
219 |
$borrowers = $item->last_returned_by_all(); |
220 |
is( |
220 |
is( |
221 |
scalar(@borrowers), 3, |
221 |
scalar(@$borrowers), 3, |
222 |
'We only retain 3 borrowers when the sys pref is set to 3, even though there are 5 checkouts/checkins' |
222 |
'We only retain 3 borrowers when the sys pref is set to 3, even though there are 5 checkouts/checkins' |
223 |
); |
223 |
); |
224 |
is( $borrowers[0]->borrowernumber, $patrons[4]->{borrowernumber}, 'Most recent borrower after cleanup' ); |
224 |
is( $borrowers->[0]->borrowernumber, $patrons[4]->{borrowernumber}, 'Most recent borrower after cleanup' ); |
225 |
|
225 |
|
226 |
# Reduce StoreLastBorrower to 2 |
226 |
# Reduce StoreLastBorrower to 2 |
227 |
t::lib::Mocks::mock_preference( 'StoreLastBorrower', '2' ); |
227 |
t::lib::Mocks::mock_preference( 'StoreLastBorrower', '2' ); |
Lines 249-258
subtest 'Test StoreLastBorrower with multiple borrowers' => sub {
Link Here
|
249 |
); |
249 |
); |
250 |
|
250 |
|
251 |
$item = $item->get_from_storage; |
251 |
$item = $item->get_from_storage; |
252 |
@borrowers = $item->last_returned_by_all(); |
252 |
$borrowers = $item->last_returned_by_all(); |
253 |
is( scalar(@borrowers), 2, 'StoreLastBorrower was reduced to 2, we should now only keep 2 in the table' ); |
253 |
is( scalar(@$borrowers), 2, 'StoreLastBorrower was reduced to 2, we should now only keep 2 in the table' ); |
254 |
is( |
254 |
is( |
255 |
$borrowers[0]->borrowernumber, $yet_another_patron->{borrowernumber}, |
255 |
$borrowers->[0]->borrowernumber, $yet_another_patron->{borrowernumber}, |
256 |
'Most recent borrower after limit reduction' |
256 |
'Most recent borrower after limit reduction' |
257 |
); |
257 |
); |
258 |
|
258 |
|
Lines 283-290
subtest 'Test StoreLastBorrower with multiple borrowers' => sub {
Link Here
|
283 |
); |
283 |
); |
284 |
|
284 |
|
285 |
$item = $item->get_from_storage; |
285 |
$item = $item->get_from_storage; |
286 |
@borrowers = $item->last_returned_by_all(); |
286 |
$borrowers = $item->last_returned_by_all(); |
287 |
is( scalar(@borrowers), 0, 'last_returned_by_all respects preference value 0' ); |
287 |
is( scalar(@$borrowers), 0, 'last_returned_by_all respects preference value 0' ); |
288 |
|
288 |
|
289 |
my $cleanup_patron = $builder->build( |
289 |
my $cleanup_patron = $builder->build( |
290 |
{ |
290 |
{ |
Lines 309-316
subtest 'Test StoreLastBorrower with multiple borrowers' => sub {
Link Here
|
309 |
); |
309 |
); |
310 |
|
310 |
|
311 |
$item = $item->get_from_storage; |
311 |
$item = $item->get_from_storage; |
312 |
@borrowers = $item->last_returned_by_all(); |
312 |
$borrowers = $item->last_returned_by_all(); |
313 |
is( scalar(@borrowers), 0, 'All entries cleared when preference is 0' ); |
313 |
is( scalar(@$borrowers), 0, 'All entries cleared when preference is 0' ); |
314 |
is( $item->last_returned_by, undef, 'last_returned_by returns undef when no records' ); |
314 |
is( $item->last_returned_by, undef, 'last_returned_by returns undef when no records' ); |
315 |
|
315 |
|
316 |
}; |
316 |
}; |
317 |
- |
|
|