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