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

(-)a/t/db_dependent/ArticleRequests.t (-1 / +93 lines)
Lines 32-37 use Koha::Patron; Link Here
32
use Koha::Library::Group;
32
use Koha::Library::Group;
33
use Koha::CirculationRules;
33
use Koha::CirculationRules;
34
use Koha::Caches;
34
use Koha::Caches;
35
use Koha::DateUtils qw( dt_from_string );
36
use Try::Tiny;
35
37
36
BEGIN {
38
BEGIN {
37
    use_ok('Koha::ArticleRequest');
39
    use_ok('Koha::ArticleRequest');
Lines 250-255 subtest 'may_article_request' => sub { Link Here
250
    $cache->clear_from_cache( Koha::CirculationRules::GUESSED_ITEMTYPES_KEY );
252
    $cache->clear_from_cache( Koha::CirculationRules::GUESSED_ITEMTYPES_KEY );
251
};
253
};
252
254
255
256
subtest 'article request limit' => sub {
257
  plan tests => 12;
258
259
  t::lib::Mocks::mock_preference('ArticleRequests', 1);
260
261
  my $item = $builder->build_sample_item;
262
263
  my $category = $builder->build_object(
264
    {
265
      class => 'Koha::Patron::Categories',
266
      value => {
267
        article_request_limit => 1
268
      }
269
    }
270
  );
271
  my $patron   = $builder->build_object(
272
    {
273
      class => 'Koha::Patrons',
274
      value => {
275
        categorycode => $category->categorycode
276
      },
277
    }
278
  );
279
  $patron->article_requests->delete();
280
281
  is($patron->can_request_article, 1, 'Patron can request more articles');
282
283
  my $article_request_1 = Koha::ArticleRequest->new(
284
    {
285
      borrowernumber => $patron->id,
286
      biblionumber   => $item->biblionumber,
287
      itemnumber     => $item->itemnumber,
288
      title          => 'an article request',
289
    }
290
  )->store();
291
292
  is($patron->can_request_article, 0, 'Patron cannot request more articles');
293
  is($patron->article_requests->count, 1, 'There is one current article request');
294
295
  try {
296
    Koha::ArticleRequest->new(
297
      {
298
        borrowernumber => $patron->id,
299
        biblionumber   => $item->biblionumber,
300
        itemnumber     => $item->itemnumber,
301
        title          => 'an second article request',
302
      }
303
    )->store();
304
  }
305
  catch {
306
    is(ref($_), 'Koha::Exceptions::ArticleRequest::LimitReached', 'Limit reached thrown');
307
  };
308
309
  is($patron->can_request_article, 0, 'Patron cannot request more articles');
310
  is($patron->article_requests->count, 1, 'There is still one article request');
311
312
  $article_request_1->created_on(dt_from_string->add(days => -1))->store();
313
314
  is($patron->can_request_article, 1, 'Patron can request more articles');
315
316
  my $article_request_3 = Koha::ArticleRequest->new(
317
    {
318
      borrowernumber => $patron->id,
319
      biblionumber   => $item->biblionumber,
320
      itemnumber     => $item->itemnumber,
321
      title          => 'an third article request',
322
    }
323
  )->store();
324
325
  is($patron->can_request_article, 0, 'Patron cannot request more articles');
326
  is($patron->article_requests->count, 2, 'There are 2 article requests');
327
328
  $article_request_3->cancel();
329
330
  is($patron->can_request_article, 1, 'Patron can request more articles');
331
332
  Koha::ArticleRequest->new(
333
    {
334
      borrowernumber => $patron->id,
335
      biblionumber   => $item->biblionumber,
336
      itemnumber     => $item->itemnumber,
337
      title          => 'an fourth article request',
338
    }
339
  )->store();
340
341
  is($patron->can_request_article, 0, 'Patron cannot request more articles');
342
  is($patron->article_requests->count, 3, 'There are 3 current article requests');
343
344
};
345
253
$schema->storage->txn_rollback();
346
$schema->storage->txn_rollback();
254
347
255
subtest 'set_pending() tests' => sub {
348
subtest 'set_pending() tests' => sub {
256
- 

Return to bug 27945