View | Details | Raw Unified | Return to bug 27945
Collapse All | Expand All

(-)a/t/db_dependent/ArticleRequests.t (-2 / +93 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use POSIX qw(strftime);
20
use POSIX qw(strftime);
21
21
22
use Test::More tests => 55;
22
use Test::More tests => 56;
23
23
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
25
use t::lib::Mocks;
25
use t::lib::Mocks;
Lines 31-36 use Koha::Patron; Link Here
31
use Koha::Library::Group;
31
use Koha::Library::Group;
32
use Koha::CirculationRules;
32
use Koha::CirculationRules;
33
use Koha::Caches;
33
use Koha::Caches;
34
use Koha::DateUtils qw( dt_from_string );
35
use Try::Tiny;
34
36
35
BEGIN {
37
BEGIN {
36
    use_ok('Koha::ArticleRequest');
38
    use_ok('Koha::ArticleRequest');
Lines 329-332 subtest 'article request fee' => sub { Link Here
329
331
330
};
332
};
331
333
334
subtest 'article request limit' => sub {
335
  plan tests => 12;
336
337
  t::lib::Mocks::mock_preference('ArticleRequests', 1);
338
339
  my $item = $builder->build_sample_item;
340
341
  my $category = $builder->build_object(
342
    {
343
      class => 'Koha::Patron::Categories',
344
      value => {
345
        article_request_limit => 1
346
      }
347
    }
348
  );
349
  my $patron   = $builder->build_object(
350
    {
351
      class => 'Koha::Patrons',
352
      value => {
353
        categorycode => $category->categorycode
354
      },
355
    }
356
  );
357
  $patron->article_requests->delete();
358
359
  is($patron->can_request_article, 1, 'Patron can request more articles');
360
361
  my $article_request_1 = Koha::ArticleRequest->new(
362
    {
363
      borrowernumber => $patron->id,
364
      biblionumber   => $item->biblionumber,
365
      itemnumber     => $item->itemnumber,
366
      title          => 'an article request',
367
    }
368
  )->store();
369
370
  is($patron->can_request_article, 0, 'Patron cannot request more articles');
371
  is($patron->article_requests->count, 1, 'There is one current article request');
372
373
  try {
374
    Koha::ArticleRequest->new(
375
      {
376
        borrowernumber => $patron->id,
377
        biblionumber   => $item->biblionumber,
378
        itemnumber     => $item->itemnumber,
379
        title          => 'an second article request',
380
      }
381
    )->store();
382
  }
383
  catch {
384
    is(ref($_), 'Koha::Exceptions::ArticleRequest::LimitReached', 'Limit reached thrown');
385
  };
386
387
  is($patron->can_request_article, 0, 'Patron cannot request more articles');
388
  is($patron->article_requests->count, 1, 'There is still one article request');
389
390
  $article_request_1->created_on(dt_from_string->add(days => -1))->store();
391
392
  is($patron->can_request_article, 1, 'Patron can request more articles');
393
394
  my $article_request_3 = Koha::ArticleRequest->new(
395
    {
396
      borrowernumber => $patron->id,
397
      biblionumber   => $item->biblionumber,
398
      itemnumber     => $item->itemnumber,
399
      title          => 'an third article request',
400
    }
401
  )->store();
402
403
  is($patron->can_request_article, 0, 'Patron cannot request more articles');
404
  is($patron->article_requests->count, 2, 'There are 2 article requests');
405
406
  $article_request_3->cancel();
407
408
  is($patron->can_request_article, 1, 'Patron can request more articles');
409
410
  Koha::ArticleRequest->new(
411
    {
412
      borrowernumber => $patron->id,
413
      biblionumber   => $item->biblionumber,
414
      itemnumber     => $item->itemnumber,
415
      title          => 'an fourth article request',
416
    }
417
  )->store();
418
419
  is($patron->can_request_article, 0, 'Patron cannot request more articles');
420
  is($patron->article_requests->count, 3, 'There are 3 current article requests');
421
422
};
423
332
$schema->storage->txn_rollback();
424
$schema->storage->txn_rollback();
333
- 

Return to bug 27945