3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 use File::Basename qw/basename/;
23 use Koha::Illrequestattributes;
24 use Koha::Illrequest::Config;
27 use t::lib::TestBuilder;
31 use Test::More tests => 10;
33 my $schema = Koha::Database->new->schema;
34 my $builder = t::lib::TestBuilder->new;
35 use_ok('Koha::Illrequest');
36 use_ok('Koha::Illrequests');
38 subtest 'Basic object tests' => sub {
42 $schema->storage->txn_begin;
44 my $illrq = $builder->build({ source => 'Illrequest' });
45 my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id});
47 isa_ok($illrq_obj, 'Koha::Illrequest',
48 "Correctly create and load an illrequest object.");
49 isa_ok($illrq_obj->_config, 'Koha::Illrequest::Config',
50 "Created a config object as part of Illrequest creation.");
52 is($illrq_obj->illrequest_id, $illrq->{illrequest_id},
53 "Illrequest_id getter works.");
54 is($illrq_obj->borrowernumber, $illrq->{borrowernumber},
55 "Borrowernumber getter works.");
56 is($illrq_obj->biblio_id, $illrq->{biblio_id},
57 "Biblio_Id getter works.");
58 is($illrq_obj->branchcode, $illrq->{branchcode},
59 "Branchcode getter works.");
60 is($illrq_obj->status, $illrq->{status},
61 "Status getter works.");
62 is($illrq_obj->placed, $illrq->{placed},
63 "Placed getter works.");
64 is($illrq_obj->replied, $illrq->{replied},
65 "Replied getter works.");
66 is($illrq_obj->updated, $illrq->{updated},
67 "Updated getter works.");
68 is($illrq_obj->completed, $illrq->{completed},
69 "Completed getter works.");
70 is($illrq_obj->medium, $illrq->{medium},
71 "Medium getter works.");
72 is($illrq_obj->accessurl, $illrq->{accessurl},
73 "Accessurl getter works.");
74 is($illrq_obj->cost, $illrq->{cost},
75 "Cost getter works.");
76 is($illrq_obj->notesopac, $illrq->{notesopac},
77 "Notesopac getter works.");
78 is($illrq_obj->notesstaff, $illrq->{notesstaff},
79 "Notesstaff getter works.");
80 is($illrq_obj->orderid, $illrq->{orderid},
81 "Orderid getter works.");
82 is($illrq_obj->backend, $illrq->{backend},
83 "Backend getter works.");
85 isnt($illrq_obj->status, 'COMP',
86 "ILL is not currently marked complete.");
87 $illrq_obj->mark_completed;
88 is($illrq_obj->status, 'COMP',
89 "ILL is now marked complete.");
93 is(Koha::Illrequests->search->count, 0,
94 "No illrequest found after delete.");
96 $schema->storage->txn_rollback;
99 subtest 'Working with related objects' => sub {
103 $schema->storage->txn_begin;
105 my $patron = $builder->build({ source => 'Borrower' });
106 my $illrq = $builder->build({
107 source => 'Illrequest',
108 value => { borrowernumber => $patron->{borrowernumber} }
110 my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id});
112 isa_ok($illrq_obj->patron, 'Koha::Patron',
113 "OK accessing related patron.");
116 source => 'Illrequestattribute',
117 value => { illrequest_id => $illrq_obj->illrequest_id, type => 'X' }
120 source => 'Illrequestattribute',
121 value => { illrequest_id => $illrq_obj->illrequest_id, type => 'Y' }
124 source => 'Illrequestattribute',
125 value => { illrequest_id => $illrq_obj->illrequest_id, type => 'Z' }
128 is($illrq_obj->illrequestattributes->count, Koha::Illrequestattributes->search->count,
129 "Fetching expected number of Illrequestattributes for our request.");
131 my $illrq1 = $builder->build({ source => 'Illrequest' });
133 source => 'Illrequestattribute',
134 value => { illrequest_id => $illrq1->{illrequest_id}, type => 'X' }
137 is($illrq_obj->illrequestattributes->count + 1, Koha::Illrequestattributes->search->count,
138 "Fetching expected number of Illrequestattributes for our request.");
141 is(Koha::Illrequestattributes->search->count, 1,
142 "Correct number of illrequestattributes after delete.");
144 isa_ok(Koha::Patrons->find($patron->{borrowernumber}), 'Koha::Patron',
145 "Borrower was not deleted after illrq delete.");
147 $schema->storage->txn_rollback;
150 subtest 'Status Graph tests' => sub {
154 $schema->storage->txn_begin;
156 my $illrq = $builder->build({source => 'Illrequest'});
157 my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id});
159 # _core_status_graph tests: it's just a constant, so here we just make
160 # sure it returns a hashref.
161 is(ref $illrq_obj->_core_status_graph, "HASH",
162 "_core_status_graph returns a hash.");
164 # _status_graph_union: let's try different merge operations.
167 $illrq_obj->_status_graph_union($illrq_obj->_core_status_graph, {}),
168 $illrq_obj->_core_status_graph,
169 "core_status_graph + null = core_status_graph"
174 $illrq_obj->_status_graph_union({}, $illrq_obj->_core_status_graph),
175 $illrq_obj->_core_status_graph,
176 "null + core_status_graph = core_status_graph"
179 # Correct merge behaviour
181 $illrq_obj->_status_graph_union({
189 prev_actions => [ 'REQ' ],
191 next_actions => [ 'REQ' ],
196 prev_actions => [ 'QER' ],
198 next_actions => [ 'QER' ],
201 prev_actions => [ 'REQ' ],
203 next_actions => [ 'REQ' ],
206 "REQ atom + linking QER = cyclical status graph"
209 $schema->storage->txn_rollback;
212 subtest 'Backend testing (mocks)' => sub {
216 $schema->storage->txn_begin;
218 # testing load_backend & available_backends requires that we have at least
219 # the Dummy plugin installed. load_backend & available_backends don't
220 # currently have tests as a result.
222 my $backend = Test::MockObject->new;
223 $backend->set_isa('Koha::Illbackends::Mock');
224 $backend->set_always('name', 'Mock');
226 my $patron = $builder->build({ source => 'Borrower' });
227 my $illrq = $builder->build({
228 source => 'Illrequest',
229 value => { borrowernumber => $patron->{borrowernumber} }
231 my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id});
233 $illrq_obj->_backend($backend);
235 isa_ok($illrq_obj->_backend, 'Koha::Illbackends::Mock',
236 "OK accessing mocked backend.");
238 # _backend_capability tests:
239 # We need to test whether this optional feature of a mocked backend
240 # behaves as expected.
241 # 3 scenarios: feature not implemented, feature implemented, but requested
242 # capability is not provided by backend, & feature is implemented &
243 # capability exists. This method can be used to implement custom backend
244 # functionality, such as unmediated in the BLDSS backend (also see
246 $backend->set_always('capabilities', undef);
247 is($illrq_obj->_backend_capability('Test'), 0,
248 "0 returned on Mock not implementing capabilities.");
250 $backend->set_always('capabilities', 0);
251 is($illrq_obj->_backend_capability('Test'), 0,
252 "0 returned on Mock not implementing Test capability.");
254 $backend->set_always('capabilities', sub { return 'bar'; } );
255 is($illrq_obj->_backend_capability('Test'), 'bar',
256 "'bar' returned on Mock implementing Test capability.");
258 # metadata test: we need to be sure that we return the arbitrary values
263 my ( $self, $rq ) = @_;
265 ID => $rq->illrequest_id,
266 Title => $rq->patron->borrowernumber
272 $illrq_obj->metadata,
274 ID => $illrq_obj->illrequest_id,
275 Title => $illrq_obj->patron->borrowernumber
282 # No backend graph extension
283 $backend->set_always('status_graph', {});
284 is_deeply($illrq_obj->capabilities('COMP'),
286 prev_actions => [ 'REQ' ],
289 ui_method_name => 'Mark completed',
290 method => 'mark_completed',
292 ui_method_icon => 'fa-check',
294 "Dummy status graph for COMP.");
295 is($illrq_obj->capabilities('UNKNOWN'), undef,
296 "Dummy status graph for UNKNOWN.");
297 is_deeply($illrq_obj->capabilities(),
298 $illrq_obj->_core_status_graph,
299 "Dummy full status graph.");
300 # Simple backend graph extension
301 $backend->set_always('status_graph',
304 prev_actions => [ 'REQ' ],
306 next_actions => [ 'REQ' ],
309 is_deeply($illrq_obj->capabilities('QER'),
311 prev_actions => [ 'REQ' ],
313 next_actions => [ 'REQ' ],
315 "Simple status graph for QER.");
316 is($illrq_obj->capabilities('UNKNOWN'), undef,
317 "Simple status graph for UNKNOWN.");
318 is_deeply($illrq_obj->capabilities(),
319 $illrq_obj->_status_graph_union(
320 $illrq_obj->_core_status_graph,
323 prev_actions => [ 'REQ' ],
325 next_actions => [ 'REQ' ],
329 "Simple full status graph.");
333 # No backend graph extension
334 $backend->set_always('status_graph', {});
335 is($illrq_obj->custom_capability('unknown', {}), 0,
336 "Unknown candidate.");
338 # Simple backend graph extension
339 $backend->set_always('status_graph',
342 prev_actions => [ 'REQ' ],
344 method => 'identity',
345 next_actions => [ 'REQ' ],
348 $backend->mock('identity',
349 sub { my ( $self, $params ) = @_; return $params->{other}; });
350 is($illrq_obj->custom_capability('identity', { test => 1 })->{test}, 1,
351 "Resolve identity custom_capability");
353 $schema->storage->txn_rollback;
357 subtest 'Backend core methods' => sub {
361 $schema->storage->txn_begin;
363 # Build infrastructure
364 my $backend = Test::MockObject->new;
365 $backend->set_isa('Koha::Illbackends::Mock');
366 $backend->set_always('name', 'Mock');
368 my $config = Test::MockObject->new;
369 $config->set_always('backend_dir', "/tmp");
370 $config->set_always('getLimitRules',
371 { default => { count => 0, method => 'active' } });
373 my $illrq = $builder->build({source => 'Illrequest'});
374 my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id});
375 $illrq_obj->_config($config);
376 $illrq_obj->_backend($backend);
379 is_deeply($illrq_obj->expandTemplate({ test => 1, method => "bar" }),
383 template => "/tmp/Mock/intra-includes/bar.inc",
384 opac_template => "/tmp/Mock/opac-includes/bar.inc",
389 # we are testing simple cases.
390 $backend->set_series('create',
391 { stage => 'bar', method => 'create' },
392 { stage => 'commit', method => 'create' },
393 { stage => 'commit', method => 'create' });
394 # Test Copyright Clearance
395 t::lib::Mocks::mock_preference("ILLModuleCopyrightClearance", "Test Copyright Clearance.");
396 is_deeply($illrq_obj->backend_create({test => 1}),
402 stage => 'copyrightclearance',
407 "Backend create: copyright clearance.");
408 t::lib::Mocks::mock_preference("ILLModuleCopyrightClearance", "");
410 is_deeply($illrq_obj->backend_create({test => 1}),
412 stage => 'bar', method => 'create',
413 template => "/tmp/Mock/intra-includes/create.inc",
414 opac_template => "/tmp/Mock/opac-includes/create.inc",
416 "Backend create: arbitrary stage.");
418 is_deeply($illrq_obj->backend_create({test => 1}),
420 stage => 'commit', method => 'create', permitted => 0,
421 template => "/tmp/Mock/intra-includes/create.inc",
422 opac_template => "/tmp/Mock/opac-includes/create.inc",
424 "Backend create: arbitrary stage, not permitted.");
425 is($illrq_obj->status, "QUEUED", "Backend create: queued if restricted.");
426 $config->set_always('getLimitRules', {});
427 $illrq_obj->status('NEW');
428 is_deeply($illrq_obj->backend_create({test => 1}),
430 stage => 'commit', method => 'create', permitted => 1,
431 template => "/tmp/Mock/intra-includes/create.inc",
432 opac_template => "/tmp/Mock/opac-includes/create.inc",
434 "Backend create: arbitrary stage, permitted.");
435 is($illrq_obj->status, "NEW", "Backend create: not-queued.");
438 $backend->set_series('renew', { stage => 'bar', method => 'renew' });
439 is_deeply($illrq_obj->backend_renew({test => 1}),
441 stage => 'bar', method => 'renew',
442 template => "/tmp/Mock/intra-includes/renew.inc",
443 opac_template => "/tmp/Mock/opac-includes/renew.inc",
445 "Backend renew: arbitrary stage.");
448 $backend->set_series('cancel', { stage => 'bar', method => 'cancel' });
449 is_deeply($illrq_obj->backend_cancel({test => 1}),
451 stage => 'bar', method => 'cancel',
452 template => "/tmp/Mock/intra-includes/cancel.inc",
453 opac_template => "/tmp/Mock/opac-includes/cancel.inc",
455 "Backend cancel: arbitrary stage.");
457 # backend_update_status
458 $backend->set_series('update_status', { stage => 'bar', method => 'update_status' });
459 is_deeply($illrq_obj->backend_update_status({test => 1}),
461 stage => 'bar', method => 'update_status',
462 template => "/tmp/Mock/intra-includes/update_status.inc",
463 opac_template => "/tmp/Mock/opac-includes/update_status.inc",
465 "Backend update_status: arbitrary stage.");
468 $backend->set_series('confirm', { stage => 'bar', method => 'confirm' });
469 is_deeply($illrq_obj->backend_confirm({test => 1}),
471 stage => 'bar', method => 'confirm',
472 template => "/tmp/Mock/intra-includes/confirm.inc",
473 opac_template => "/tmp/Mock/opac-includes/confirm.inc",
475 "Backend confirm: arbitrary stage.");
477 $config->set_always('partner_code', "ILLTSTLIB");
478 $backend->set_always('metadata', { Test => "Foobar" });
479 my $illbrn = $builder->build({
481 value => { branchemail => "", branchreplyto => "" }
483 my $partner1 = $builder->build({
484 source => 'Borrower',
485 value => { categorycode => "ILLTSTLIB" },
487 my $partner2 = $builder->build({
488 source => 'Borrower',
489 value => { categorycode => "ILLTSTLIB" },
491 my $gen_conf = $illrq_obj->generic_confirm({
492 current_branchcode => $illbrn->{branchcode}
494 isnt(index($gen_conf->{value}->{draft}->{body}, $backend->metadata->{Test}), -1,
495 "Generic confirm: draft contains metadata."
497 is($gen_conf->{value}->{partners}->next->borrowernumber, $partner1->{borrowernumber},
498 "Generic cofnirm: partner 1 is correct."
500 is($gen_conf->{value}->{partners}->next->borrowernumber, $partner2->{borrowernumber},
501 "Generic confirm: partner 2 is correct."
504 dies_ok { $illrq_obj->generic_confirm({
505 current_branchcode => $illbrn->{branchcode},
508 "Generic confirm: missing to dies OK.";
510 dies_ok { $illrq_obj->generic_confirm({
511 current_branchcode => $illbrn->{branchcode},
512 partners => $partner1->{email},
515 "Generic confirm: missing from dies OK.";
517 $schema->storage->txn_rollback;
521 subtest 'Helpers' => sub {
525 $schema->storage->txn_begin;
527 # Build infrastructure
528 my $backend = Test::MockObject->new;
529 $backend->set_isa('Koha::Illbackends::Mock');
530 $backend->set_always('name', 'Mock');
532 my $config = Test::MockObject->new;
533 $config->set_always('backend_dir', "/tmp");
535 my $patron = $builder->build({
536 source => 'Borrower',
537 value => { categorycode => "A" }
539 my $illrq = $builder->build({
540 source => 'Illrequest',
541 value => { branchcode => "CPL", borrowernumber => $patron->{borrowernumber} }
543 my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id});
544 $illrq_obj->_config($config);
545 $illrq_obj->_backend($backend);
548 $config->set_series('getPrefixes',
549 { CPL => "TEST", TSL => "BAR", default => "DEFAULT" },
550 { A => "ATEST", C => "CBAR", default => "DEFAULT" });
551 is($illrq_obj->getPrefix({ brw_cat => "C", branch => "CPL" }), "CBAR",
552 "getPrefix: brw_cat");
553 $config->set_series('getPrefixes',
554 { CPL => "TEST", TSL => "BAR", default => "DEFAULT" },
555 { A => "ATEST", C => "CBAR", default => "DEFAULT" });
556 is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "CPL" }), "TEST",
557 "getPrefix: branch");
558 $config->set_series('getPrefixes',
559 { CPL => "TEST", TSL => "BAR", default => "DEFAULT" },
560 { A => "ATEST", C => "CBAR", default => "DEFAULT" });
561 is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "UNKNOWN" }), "DEFAULT",
562 "getPrefix: default");
563 $config->set_always('getPrefixes', {});
564 is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "UNKNOWN" }), "",
565 "getPrefix: the empty prefix");
568 $config->set_series('getPrefixes',
569 { CPL => "TEST", TSL => "BAR", default => "DEFAULT" },
570 { A => "ATEST", C => "CBAR", default => "DEFAULT" });
571 is($illrq_obj->id_prefix, "ATEST-", "id_prefix: brw_cat");
572 $config->set_series('getPrefixes',
573 { CPL => "TEST", TSL => "BAR", default => "DEFAULT" },
574 { AB => "ATEST", CD => "CBAR", default => "DEFAULT" });
575 is($illrq_obj->id_prefix, "TEST-", "id_prefix: branch");
576 $config->set_series('getPrefixes',
577 { CPLT => "TEST", TSLT => "BAR", default => "DEFAULT" },
578 { AB => "ATEST", CD => "CBAR", default => "DEFAULT" });
579 is($illrq_obj->id_prefix, "DEFAULT-", "id_prefix: default");
581 # requires_moderation
582 $illrq_obj->status('NEW')->store;
583 is($illrq_obj->requires_moderation, undef, "requires_moderation: No.");
584 $illrq_obj->status('CANCREQ')->store;
585 is($illrq_obj->requires_moderation, 'CANCREQ', "requires_moderation: Yes.");
587 $schema->storage->txn_rollback;
591 subtest 'Censorship' => sub {
595 $schema->storage->txn_begin;
597 # Build infrastructure
598 my $backend = Test::MockObject->new;
599 $backend->set_isa('Koha::Illbackends::Mock');
600 $backend->set_always('name', 'Mock');
602 my $config = Test::MockObject->new;
603 $config->set_always('backend_dir', "/tmp");
605 my $illrq = $builder->build({source => 'Illrequest'});
606 my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id});
607 $illrq_obj->_config($config);
608 $illrq_obj->_backend($backend);
610 $config->set_always('censorship', { censor_notes_staff => 1, censor_reply_date => 0 });
612 my $censor_out = $illrq_obj->_censor({ foo => 'bar', baz => 564 });
613 is_deeply($censor_out, { foo => 'bar', baz => 564, display_reply_date => 1 },
614 "_censor: not OPAC, reply_date = 1");
616 $censor_out = $illrq_obj->_censor({ foo => 'bar', baz => 564, opac => 1 });
617 is_deeply($censor_out, {
618 foo => 'bar', baz => 564, censor_notes_staff => 1,
619 display_reply_date => 1, opac => 1
620 }, "_censor: notes_staff = 0, reply_date = 0");
622 $schema->storage->txn_rollback;
625 subtest 'Checking Limits' => sub {
629 $schema->storage->txn_begin;
631 # Build infrastructure
632 my $backend = Test::MockObject->new;
633 $backend->set_isa('Koha::Illbackends::Mock');
634 $backend->set_always('name', 'Mock');
636 my $config = Test::MockObject->new;
637 $config->set_always('backend_dir', "/tmp");
639 my $illrq = $builder->build({source => 'Illrequest'});
640 my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id});
641 $illrq_obj->_config($config);
642 $illrq_obj->_backend($backend);
645 $config->set_series('getLimitRules',
646 { CPL => { count => 1, method => 'test' } },
647 { default => { count => 0, method => 'active' } });
648 is_deeply($illrq_obj->getLimits({ type => 'branch', value => "CPL" }),
649 { count => 1, method => 'test' },
650 "getLimits: by value.");
651 is_deeply($illrq_obj->getLimits({ type => 'branch' }),
652 { count => 0, method => 'active' },
653 "getLimits: by default.");
654 is_deeply($illrq_obj->getLimits({ type => 'branch', value => "CPL" }),
655 { count => -1, method => 'active' },
656 "getLimits: by hard-coded.");
659 is($illrq_obj->_limit_counter('annual', { branchcode => $illrq_obj->branchcode }),
660 1, "_limit_counter: Initial branch annual count.");
661 is($illrq_obj->_limit_counter('active', { branchcode => $illrq_obj->branchcode }),
662 1, "_limit_counter: Initial branch active count.");
663 is($illrq_obj->_limit_counter('annual', { borrowernumber => $illrq_obj->borrowernumber }),
664 1, "_limit_counter: Initial patron annual count.");
665 is($illrq_obj->_limit_counter('active', { borrowernumber => $illrq_obj->borrowernumber }),
666 1, "_limit_counter: Initial patron active count.");
668 source => 'Illrequest',
670 branchcode => $illrq_obj->branchcode,
671 borrowernumber => $illrq_obj->borrowernumber,
674 is($illrq_obj->_limit_counter('annual', { branchcode => $illrq_obj->branchcode }),
675 2, "_limit_counter: Add a qualifying request for branch annual count.");
676 is($illrq_obj->_limit_counter('active', { branchcode => $illrq_obj->branchcode }),
677 2, "_limit_counter: Add a qualifying request for branch active count.");
678 is($illrq_obj->_limit_counter('annual', { borrowernumber => $illrq_obj->borrowernumber }),
679 2, "_limit_counter: Add a qualifying request for patron annual count.");
680 is($illrq_obj->_limit_counter('active', { borrowernumber => $illrq_obj->borrowernumber }),
681 2, "_limit_counter: Add a qualifying request for patron active count.");
683 source => 'Illrequest',
685 branchcode => $illrq_obj->branchcode,
686 borrowernumber => $illrq_obj->borrowernumber,
687 placed => "2005-05-31",
690 is($illrq_obj->_limit_counter('annual', { branchcode => $illrq_obj->branchcode }),
691 2, "_limit_counter: Add an out-of-date branch request.");
692 is($illrq_obj->_limit_counter('active', { branchcode => $illrq_obj->branchcode }),
693 3, "_limit_counter: Add a qualifying request for branch active count.");
694 is($illrq_obj->_limit_counter('annual', { borrowernumber => $illrq_obj->borrowernumber }),
695 2, "_limit_counter: Add an out-of-date patron request.");
696 is($illrq_obj->_limit_counter('active', { borrowernumber => $illrq_obj->borrowernumber }),
697 3, "_limit_counter: Add a qualifying request for patron active count.");
699 source => 'Illrequest',
701 branchcode => $illrq_obj->branchcode,
702 borrowernumber => $illrq_obj->borrowernumber,
706 is($illrq_obj->_limit_counter('annual', { branchcode => $illrq_obj->branchcode }),
707 3, "_limit_counter: Add a qualifying request for branch annual count.");
708 is($illrq_obj->_limit_counter('active', { branchcode => $illrq_obj->branchcode }),
709 3, "_limit_counter: Add a completed request for branch active count.");
710 is($illrq_obj->_limit_counter('annual', { borrowernumber => $illrq_obj->borrowernumber }),
711 3, "_limit_counter: Add a qualifying request for patron annual count.");
712 is($illrq_obj->_limit_counter('active', { borrowernumber => $illrq_obj->borrowernumber }),
713 3, "_limit_counter: Add a completed request for patron active count.");
717 # We've tested _limit_counter, so all we need to test here is whether the
718 # current counts of 3 for each work as they should against different
719 # configuration declarations.
722 $config->set_always('getLimitRules', undef);
723 is($illrq_obj->check_limits({patron => $illrq_obj->patron,
724 librarycode => $illrq_obj->branchcode}),
725 1, "check_limits: no configuration => no limits.");
728 $config->set_always('getLimitRules',
729 { $illrq_obj->branchcode => { count => 1, method => 'active' } });
730 is($illrq_obj->check_limits({patron => $illrq_obj->patron,
731 librarycode => $illrq_obj->branchcode}),
732 0, "check_limits: branch active limit exceeded.");
733 $config->set_always('getLimitRules',
734 { $illrq_obj->branchcode => { count => 1, method => 'annual' } });
735 is($illrq_obj->check_limits({patron => $illrq_obj->patron,
736 librarycode => $illrq_obj->branchcode}),
737 0, "check_limits: branch annual limit exceeded.");
738 $config->set_always('getLimitRules',
739 { $illrq_obj->branchcode => { count => 4, method => 'active' } });
740 is($illrq_obj->check_limits({patron => $illrq_obj->patron,
741 librarycode => $illrq_obj->branchcode}),
742 1, "check_limits: branch active limit OK.");
743 $config->set_always('getLimitRules',
744 { $illrq_obj->branchcode => { count => 4, method => 'annual' } });
745 is($illrq_obj->check_limits({patron => $illrq_obj->patron,
746 librarycode => $illrq_obj->branchcode}),
747 1, "check_limits: branch annual limit OK.");
750 $config->set_always('getLimitRules',
751 { $illrq_obj->patron->categorycode => { count => 1, method => 'active' } });
752 is($illrq_obj->check_limits({patron => $illrq_obj->patron,
753 librarycode => $illrq_obj->branchcode}),
754 0, "check_limits: patron category active limit exceeded.");
755 $config->set_always('getLimitRules',
756 { $illrq_obj->patron->categorycode => { count => 1, method => 'annual' } });
757 is($illrq_obj->check_limits({patron => $illrq_obj->patron,
758 librarycode => $illrq_obj->branchcode}),
759 0, "check_limits: patron category annual limit exceeded.");
760 $config->set_always('getLimitRules',
761 { $illrq_obj->patron->categorycode => { count => 4, method => 'active' } });
762 is($illrq_obj->check_limits({patron => $illrq_obj->patron,
763 librarycode => $illrq_obj->branchcode}),
764 1, "check_limits: patron category active limit OK.");
765 $config->set_always('getLimitRules',
766 { $illrq_obj->patron->categorycode => { count => 4, method => 'annual' } });
767 is($illrq_obj->check_limits({patron => $illrq_obj->patron,
768 librarycode => $illrq_obj->branchcode}),
769 1, "check_limits: patron category annual limit OK.");
771 # One rule cancels the other
772 $config->set_series('getLimitRules',
773 # Branch rules allow request
774 { $illrq_obj->branchcode => { count => 4, method => 'active' } },
775 # Patron rule forbids it
776 { $illrq_obj->patron->categorycode => { count => 1, method => 'annual' } });
777 is($illrq_obj->check_limits({patron => $illrq_obj->patron,
778 librarycode => $illrq_obj->branchcode}),
779 0, "check_limits: patron category veto overrides branch OK.");
780 $config->set_series('getLimitRules',
781 # Branch rules allow request
782 { $illrq_obj->branchcode => { count => 1, method => 'active' } },
783 # Patron rule forbids it
784 { $illrq_obj->patron->categorycode => { count => 4, method => 'annual' } });
785 is($illrq_obj->check_limits({patron => $illrq_obj->patron,
786 librarycode => $illrq_obj->branchcode}),
787 0, "check_limits: branch veto overrides patron category OK.");
789 $schema->storage->txn_rollback;