Lines 254-260
subtest 'may_article_request' => sub {
Link Here
|
254 |
|
254 |
|
255 |
|
255 |
|
256 |
subtest 'article request limit' => sub { |
256 |
subtest 'article request limit' => sub { |
257 |
plan tests => 12; |
257 |
plan tests => 13; |
258 |
|
258 |
|
259 |
t::lib::Mocks::mock_preference('ArticleRequests', 1); |
259 |
t::lib::Mocks::mock_preference('ArticleRequests', 1); |
260 |
|
260 |
|
Lines 278-284
subtest 'article request limit' => sub {
Link Here
|
278 |
); |
278 |
); |
279 |
$patron->article_requests->delete(); |
279 |
$patron->article_requests->delete(); |
280 |
|
280 |
|
281 |
is($patron->can_request_article, 1, 'Patron can request more articles'); |
281 |
is($patron->can_request_article, 1, 'There are no AR, so patron can request more articles'); |
282 |
|
282 |
|
283 |
my $article_request_1 = Koha::ArticleRequest->new( |
283 |
my $article_request_1 = Koha::ArticleRequest->new( |
284 |
{ |
284 |
{ |
Lines 289-295
subtest 'article request limit' => sub {
Link Here
|
289 |
} |
289 |
} |
290 |
)->store(); |
290 |
)->store(); |
291 |
|
291 |
|
292 |
is($patron->can_request_article, 0, 'Patron cannot request more articles'); |
292 |
is($patron->can_request_article, 0, 'Limit is 1, so patron cannot request more articles'); |
293 |
is($patron->article_requests->count, 1, 'There is one current article request'); |
293 |
is($patron->article_requests->count, 1, 'There is one current article request'); |
294 |
|
294 |
|
295 |
try { |
295 |
try { |
Lines 298-335
subtest 'article request limit' => sub {
Link Here
|
298 |
borrowernumber => $patron->id, |
298 |
borrowernumber => $patron->id, |
299 |
biblionumber => $item->biblionumber, |
299 |
biblionumber => $item->biblionumber, |
300 |
itemnumber => $item->itemnumber, |
300 |
itemnumber => $item->itemnumber, |
301 |
title => 'an second article request', |
301 |
title => 'a second article request', |
302 |
} |
302 |
} |
303 |
)->store(); |
303 |
)->store(); |
304 |
} |
304 |
} |
305 |
catch { |
305 |
catch { |
306 |
is(ref($_), 'Koha::Exceptions::ArticleRequest::LimitReached', 'Limit reached thrown'); |
306 |
is(ref($_), 'Koha::Exceptions::ArticleRequest::LimitReached', 'When limit was reached and we ask for a new AR, Limit reached is thrown'); |
307 |
}; |
307 |
}; |
308 |
|
308 |
|
309 |
is($patron->can_request_article, 0, 'Patron cannot request more articles'); |
309 |
is($patron->can_request_article, 0, 'There is still an AR, so patron cannot request more articles'); |
310 |
is($patron->article_requests->count, 1, 'There is still one article request'); |
310 |
is($patron->article_requests->count, 1, 'There is still one article request'); |
311 |
|
311 |
|
312 |
$article_request_1->created_on(dt_from_string->add(days => -1))->store(); |
312 |
$article_request_1->complete(); |
313 |
|
313 |
|
314 |
is($patron->can_request_article, 1, 'Patron can request more articles'); |
314 |
is($patron->can_request_article, 0, 'AR was completed but within one day, so patron cannot request more articles'); |
|
|
315 |
|
316 |
$article_request_1->updated_on(dt_from_string->add(days => -2))->store(); |
317 |
|
318 |
is($patron->can_request_article, 1, 'There are no completed AR within one day, so patron can request more articles'); |
315 |
|
319 |
|
316 |
my $article_request_3 = Koha::ArticleRequest->new( |
320 |
my $article_request_3 = Koha::ArticleRequest->new( |
317 |
{ |
321 |
{ |
318 |
borrowernumber => $patron->id, |
322 |
borrowernumber => $patron->id, |
319 |
biblionumber => $item->biblionumber, |
323 |
biblionumber => $item->biblionumber, |
320 |
itemnumber => $item->itemnumber, |
324 |
itemnumber => $item->itemnumber, |
321 |
title => 'an third article request', |
325 |
title => 'a third article request', |
322 |
} |
326 |
} |
323 |
)->store(); |
327 |
)->store(); |
324 |
|
328 |
|
325 |
is($patron->can_request_article, 0, 'Patron cannot request more articles'); |
329 |
is($patron->can_request_article, 0, 'A new AR was created, so patron cannot request more articles'); |
326 |
is($patron->article_requests->count, 2, 'There are 2 article requests'); |
330 |
is($patron->article_requests->count, 2, 'There are 2 article requests'); |
327 |
|
331 |
|
328 |
$article_request_3->cancel(); |
332 |
$article_request_3->cancel(); |
329 |
|
333 |
|
330 |
is($patron->can_request_article, 1, 'Patron can request more articles'); |
334 |
is($patron->can_request_article, 1, 'New AR was cancelled, so patron can request more articles'); |
331 |
|
335 |
|
332 |
Koha::ArticleRequest->new( |
336 |
my $article_request_4 = Koha::ArticleRequest->new( |
333 |
{ |
337 |
{ |
334 |
borrowernumber => $patron->id, |
338 |
borrowernumber => $patron->id, |
335 |
biblionumber => $item->biblionumber, |
339 |
biblionumber => $item->biblionumber, |
Lines 338-344
subtest 'article request limit' => sub {
Link Here
|
338 |
} |
342 |
} |
339 |
)->store(); |
343 |
)->store(); |
340 |
|
344 |
|
341 |
is($patron->can_request_article, 0, 'Patron cannot request more articles'); |
345 |
$article_request_4->updated_on(dt_from_string->add(days => -30))->store(); |
|
|
346 |
|
347 |
is($patron->can_request_article, 0, 'There is an old AR but not completed or cancelled, so patron cannot request more articles'); |
342 |
is($patron->article_requests->count, 3, 'There are 3 current article requests'); |
348 |
is($patron->article_requests->count, 3, 'There are 3 current article requests'); |
343 |
|
349 |
|
344 |
}; |
350 |
}; |
345 |
- |
|
|