3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use File::Basename qw/basename/;
22 use C4::Circulation qw( AddIssue AddReturn );
25 use Koha::Illrequestattributes;
26 use Koha::Illrequest::Config;
32 use Koha::MessageAttributes;
33 use Koha::Notice::Templates;
34 use Koha::AuthorisedValueCategories;
35 use Koha::AuthorisedValues;
37 use t::lib::TestBuilder;
41 use Test::Deep qw/ cmp_deeply ignore /;
44 use Test::More tests => 14;
46 my $schema = Koha::Database->new->schema;
47 my $builder = t::lib::TestBuilder->new;
48 use_ok('Koha::Illrequest');
49 use_ok('Koha::Illrequests');
51 subtest 'Basic object tests' => sub {
55 $schema->storage->txn_begin;
57 Koha::Illrequests->search->delete;
58 my $illrq = $builder->build({ source => 'Illrequest' });
59 my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id});
61 isa_ok($illrq_obj, 'Koha::Illrequest',
62 "Correctly create and load an illrequest object.");
63 isa_ok($illrq_obj->_config, 'Koha::Illrequest::Config',
64 "Created a config object as part of Illrequest creation.");
66 is($illrq_obj->illrequest_id, $illrq->{illrequest_id},
67 "Illrequest_id getter works.");
68 is($illrq_obj->borrowernumber, $illrq->{borrowernumber},
69 "Borrowernumber getter works.");
70 is($illrq_obj->biblio_id, $illrq->{biblio_id},
71 "Biblio_Id getter works.");
72 is($illrq_obj->branchcode, $illrq->{branchcode},
73 "Branchcode getter works.");
74 is($illrq_obj->status, $illrq->{status},
75 "Status getter works.");
76 is($illrq_obj->placed, $illrq->{placed},
77 "Placed getter works.");
78 is($illrq_obj->replied, $illrq->{replied},
79 "Replied getter works.");
80 is($illrq_obj->updated, $illrq->{updated},
81 "Updated getter works.");
82 is($illrq_obj->completed, $illrq->{completed},
83 "Completed getter works.");
84 is($illrq_obj->medium, $illrq->{medium},
85 "Medium getter works.");
86 is($illrq_obj->accessurl, $illrq->{accessurl},
87 "Accessurl getter works.");
88 is($illrq_obj->cost, $illrq->{cost},
89 "Cost getter works.");
90 is($illrq_obj->price_paid, $illrq->{price_paid},
91 "Price_paid getter works.");
92 is($illrq_obj->notesopac, $illrq->{notesopac},
93 "Notesopac getter works.");
94 is($illrq_obj->notesstaff, $illrq->{notesstaff},
95 "Notesstaff getter works.");
96 is($illrq_obj->orderid, $illrq->{orderid},
97 "Orderid getter works.");
98 is($illrq_obj->backend, $illrq->{backend},
99 "Backend getter works.");
101 is($illrq_obj->get_type, undef,
102 'get_type() returns undef if no type is set');
104 source => 'Illrequestattribute',
106 illrequest_id => $illrq_obj->illrequest_id,
111 is($illrq_obj->get_type, 'book',
112 'get_type() returns correct type if set');
114 isnt($illrq_obj->status, 'COMP',
115 "ILL is not currently marked complete.");
116 $illrq_obj->mark_completed;
117 is($illrq_obj->status, 'COMP',
118 "ILL is now marked complete.");
122 is(Koha::Illrequests->search->count, 0,
123 "No illrequest found after delete.");
125 $schema->storage->txn_rollback;
128 subtest 'Working with related objects' => sub {
132 $schema->storage->txn_begin;
134 Koha::Illrequests->search->delete;
136 my $patron = $builder->build({ source => 'Borrower' });
137 my $illrq = $builder->build({
138 source => 'Illrequest',
139 value => { borrowernumber => $patron->{borrowernumber} }
141 my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id});
143 isa_ok($illrq_obj->patron, 'Koha::Patron',
144 "OK accessing related patron.");
147 source => 'Illrequestattribute',
148 value => { illrequest_id => $illrq_obj->illrequest_id, type => 'X' }
151 source => 'Illrequestattribute',
152 value => { illrequest_id => $illrq_obj->illrequest_id, type => 'Y' }
155 source => 'Illrequestattribute',
156 value => { illrequest_id => $illrq_obj->illrequest_id, type => 'Z' }
159 is($illrq_obj->illrequestattributes->count, Koha::Illrequestattributes->search->count,
160 "Fetching expected number of Illrequestattributes for our request.");
162 my $illrq1 = $builder->build({ source => 'Illrequest' });
164 source => 'Illrequestattribute',
165 value => { illrequest_id => $illrq1->{illrequest_id}, type => 'X' }
168 is($illrq_obj->illrequestattributes->count + 1, Koha::Illrequestattributes->search->count,
169 "Fetching expected number of Illrequestattributes for our request.");
171 is($illrq_obj->biblio, undef, "->biblio returns undef if no biblio");
172 my $biblio = $builder->build_object({ class => 'Koha::Biblios' });
173 my $req_bib = $builder->build_object({
174 class => 'Koha::Illrequests',
176 biblio_id => $biblio->biblionumber
179 isa_ok($req_bib->biblio, 'Koha::Biblio', "OK accessing related biblio");
182 is(Koha::Illrequestattributes->search->count, 1,
183 "Correct number of illrequestattributes after delete.");
185 isa_ok(Koha::Patrons->find($patron->{borrowernumber}), 'Koha::Patron',
186 "Borrower was not deleted after illrq delete.");
188 $schema->storage->txn_rollback;
191 subtest 'Status Graph tests' => sub {
195 $schema->storage->txn_begin;
197 my $illrq = $builder->build({source => 'Illrequest'});
198 my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id});
200 # _core_status_graph tests: it's just a constant, so here we just make
201 # sure it returns a hashref.
202 is(ref $illrq_obj->_core_status_graph, "HASH",
203 "_core_status_graph returns a hash.");
205 # _status_graph_union: let's try different merge operations.
208 $illrq_obj->_status_graph_union($illrq_obj->_core_status_graph, {}),
209 $illrq_obj->_core_status_graph,
210 "core_status_graph + null = core_status_graph"
215 $illrq_obj->_status_graph_union({}, $illrq_obj->_core_status_graph),
216 $illrq_obj->_core_status_graph,
217 "null + core_status_graph = core_status_graph"
220 # Correct merge behaviour
222 $illrq_obj->_status_graph_union({
230 prev_actions => [ 'REQ' ],
232 next_actions => [ 'REQ' ],
237 prev_actions => [ 'QER' ],
239 next_actions => [ 'QER' ],
242 prev_actions => [ 'REQ' ],
244 next_actions => [ 'REQ' ],
247 "REQ atom + linking QER = cyclical status graph"
250 # Create a new node, with no prev_actions and no next_actions. This should
251 # protect us against regressions related to bug 22280.
259 # Add the new node to the core_status_grpah
260 my $new_graph = $illrq_obj->_status_graph_union( $new_node, $illrq_obj->_core_status_graph);
261 # Compare the updated graph to the expected graph
262 # The structure we compare against here is just a copy of the structure found
263 # in Koha::Illrequest::_core_status_graph() + the new node we created above
264 cmp_deeply( $new_graph,
272 prev_actions => [ ], # Actions containing buttons
273 # leading to this status
274 id => 'NEW', # ID of this status
275 name => 'New request', # UI name of this status
276 ui_method_name => 'New request', # UI name of method leading
278 method => 'create', # method to this status
279 next_actions => [ 'REQ', 'GENREQ', 'KILL' ], # buttons to add to all
280 # requests with this status
281 ui_method_icon => 'fa-plus', # UI Style class
284 prev_actions => [ 'NEW', 'REQREV', 'QUEUED', 'CANCREQ' ],
287 ui_method_name => 'Confirm request',
289 next_actions => [ 'REQREV', 'COMP', 'CHK' ],
290 ui_method_icon => 'fa-check',
293 prev_actions => [ 'NEW', 'REQREV' ],
295 name => 'Requested from partners',
296 ui_method_name => 'Place request with partners',
297 method => 'generic_confirm',
298 next_actions => [ 'COMP', 'CHK' ],
299 ui_method_icon => 'fa-send-o',
302 prev_actions => [ 'REQ' ],
304 name => 'Request reverted',
305 ui_method_name => 'Revert Request',
307 next_actions => [ 'REQ', 'GENREQ', 'KILL' ],
308 ui_method_icon => 'fa-times',
313 name => 'Queued request',
316 next_actions => [ 'REQ', 'KILL' ],
320 prev_actions => [ 'NEW' ],
322 name => 'Cancellation requested',
325 next_actions => [ 'KILL', 'REQ' ],
329 prev_actions => [ 'REQ' ],
332 ui_method_name => 'Mark completed',
333 method => 'mark_completed',
334 next_actions => [ 'CHK' ],
335 ui_method_icon => 'fa-check',
338 prev_actions => [ 'QUEUED', 'REQREV', 'NEW', 'CANCREQ' ],
341 ui_method_name => 'Delete request',
344 ui_method_icon => 'fa-trash',
347 prev_actions => [ 'REQ', 'GENREQ', 'COMP' ],
349 name => 'Checked out',
350 ui_method_name => 'Check out',
351 needs_prefs => [ 'CirculateILL' ],
352 needs_perms => [ 'user_circulate_circulate_remaining_permissions' ],
353 needs_all => ignore(),
354 method => 'check_out',
356 ui_method_icon => 'fa-upload',
359 prev_actions => [ 'CHK' ],
361 name => 'Returned to library',
362 ui_method_name => 'Check in',
363 method => 'check_in',
364 next_actions => [ 'COMP' ],
365 ui_method_icon => 'fa-download',
368 "new node + core_status_graph = bigger status graph"
369 ) || diag explain $new_graph;
371 # Create a duplicate node
374 prev_actions => [ 'NEW', 'REQREV', 'QUEUED', 'CANCREQ' ],
377 ui_method_name => 'Confirm request dupe',
379 next_actions => [ 'REQREV', 'COMP', 'CHK' ],
380 ui_method_icon => 'fa-check',
383 # Add the dupe node to the core_status_grpah
384 my $dupe_graph = $illrq_obj->_status_graph_union( $illrq_obj->_core_status_graph, $dupe_node);
385 # Compare the updated graph to the expected graph
386 # The structure we compare against here is just a copy of the structure found
387 # in Koha::Illrequest::_core_status_graph() + the new node we created above
388 cmp_deeply( $dupe_graph,
391 prev_actions => [ ], # Actions containing buttons
392 # leading to this status
393 id => 'NEW', # ID of this status
394 name => 'New request', # UI name of this status
395 ui_method_name => 'New request', # UI name of method leading
397 method => 'create', # method to this status
398 next_actions => [ 'REQ', 'GENREQ', 'KILL' ], # buttons to add to all
399 # requests with this status
400 ui_method_icon => 'fa-plus', # UI Style class
403 prev_actions => [ 'NEW', 'REQREV', 'QUEUED', 'CANCREQ' ],
406 ui_method_name => 'Confirm request dupe',
408 next_actions => [ 'REQREV', 'COMP', 'CHK' ],
409 ui_method_icon => 'fa-check',
412 prev_actions => [ 'NEW', 'REQREV' ],
414 name => 'Requested from partners',
415 ui_method_name => 'Place request with partners',
416 method => 'generic_confirm',
417 next_actions => [ 'COMP', 'CHK' ],
418 ui_method_icon => 'fa-send-o',
421 prev_actions => [ 'REQ' ],
423 name => 'Request reverted',
424 ui_method_name => 'Revert Request',
426 next_actions => [ 'REQ', 'GENREQ', 'KILL' ],
427 ui_method_icon => 'fa-times',
432 name => 'Queued request',
435 next_actions => [ 'REQ', 'KILL' ],
439 prev_actions => [ 'NEW' ],
441 name => 'Cancellation requested',
444 next_actions => [ 'KILL', 'REQ' ],
448 prev_actions => [ 'REQ' ],
451 ui_method_name => 'Mark completed',
452 method => 'mark_completed',
453 next_actions => [ 'CHK' ],
454 ui_method_icon => 'fa-check',
457 prev_actions => [ 'QUEUED', 'REQREV', 'NEW', 'CANCREQ' ],
460 ui_method_name => 'Delete request',
463 ui_method_icon => 'fa-trash',
466 prev_actions => [ 'REQ', 'GENREQ', 'COMP' ],
468 name => 'Checked out',
469 ui_method_name => 'Check out',
470 needs_prefs => [ 'CirculateILL' ],
471 needs_perms => [ 'user_circulate_circulate_remaining_permissions' ],
472 needs_all => ignore(),
473 method => 'check_out',
475 ui_method_icon => 'fa-upload',
478 prev_actions => [ 'CHK' ],
480 name => 'Returned to library',
481 ui_method_name => 'Check in',
482 method => 'check_in',
483 next_actions => [ 'COMP' ],
484 ui_method_icon => 'fa-download',
487 "new node + core_status_graph = bigger status graph"
488 ) || diag explain $dupe_graph;
490 $schema->storage->txn_rollback;
493 subtest 'Backend testing (mocks)' => sub {
497 $schema->storage->txn_begin;
499 # testing load_backend & available_backends requires that we have at least
500 # the Dummy plugin installed. load_backend & available_backends don't
501 # currently have tests as a result.
503 t::lib::Mocks->mock_config('interlibrary_loans', { backend_dir => 'a_dir' } );
504 my $backend = Test::MockObject->new;
505 $backend->set_isa('Koha::Illbackends::Mock');
506 $backend->set_always('name', 'Mock');
508 my $patron = $builder->build({ source => 'Borrower' });
509 my $illrq = $builder->build_object({
510 class => 'Koha::Illrequests',
513 $illrq->_backend($backend);
515 isa_ok($illrq->_backend, 'Koha::Illbackends::Mock',
516 "OK accessing mocked backend.");
518 # _backend_capability tests:
519 # We need to test whether this optional feature of a mocked backend
520 # behaves as expected.
521 # 3 scenarios: feature not implemented, feature implemented, but requested
522 # capability is not provided by backend, & feature is implemented &
523 # capability exists. This method can be used to implement custom backend
524 # functionality, such as unmediated in the BLDSS backend (also see
526 $backend->set_always('capabilities', undef);
527 is($illrq->_backend_capability('Test'), 0,
528 "0 returned on Mock not implementing capabilities.");
530 $backend->set_always('capabilities', 0);
531 is($illrq->_backend_capability('Test'), 0,
532 "0 returned on Mock not implementing Test capability.");
534 $backend->set_always('capabilities', sub { return 'bar'; } );
535 is($illrq->_backend_capability('Test'), 'bar',
536 "'bar' returned on Mock implementing Test capability.");
538 # metadata test: we need to be sure that we return the arbitrary values
543 my ( $self, $rq ) = @_;
545 ID => $rq->illrequest_id,
546 Title => $rq->patron->borrowernumber
554 ID => $illrq->illrequest_id,
555 Title => $illrq->patron->borrowernumber
562 # No backend graph extension
563 $backend->set_always('status_graph', {});
564 is_deeply($illrq->capabilities('COMP'),
566 prev_actions => [ 'REQ' ],
569 ui_method_name => 'Mark completed',
570 method => 'mark_completed',
571 next_actions => [ 'CHK' ],
572 ui_method_icon => 'fa-check',
574 "Dummy status graph for COMP.");
575 is($illrq->capabilities('UNKNOWN'), undef,
576 "Dummy status graph for UNKNOWN.");
577 is_deeply($illrq->capabilities(),
578 $illrq->_core_status_graph,
579 "Dummy full status graph.");
580 # Simple backend graph extension
581 $backend->set_always('status_graph',
584 prev_actions => [ 'REQ' ],
586 next_actions => [ 'REQ' ],
589 is_deeply($illrq->capabilities('QER'),
591 prev_actions => [ 'REQ' ],
593 next_actions => [ 'REQ' ],
595 "Simple status graph for QER.");
596 is($illrq->capabilities('UNKNOWN'), undef,
597 "Simple status graph for UNKNOWN.");
598 is_deeply($illrq->capabilities(),
599 $illrq->_status_graph_union(
600 $illrq->_core_status_graph,
603 prev_actions => [ 'REQ' ],
605 next_actions => [ 'REQ' ],
609 "Simple full status graph.");
613 # No backend graph extension
614 $backend->set_always('status_graph', {});
615 is($illrq->custom_capability('unknown', {}), 0,
616 "Unknown candidate.");
618 # Simple backend graph extension
619 $backend->set_always('status_graph',
622 prev_actions => [ 'REQ' ],
624 method => 'identity',
625 next_actions => [ 'REQ' ],
628 $backend->mock('identity',
629 sub { my ( $self, $params ) = @_; return $params->{other}; });
630 is($illrq->custom_capability('identity', { test => 1, method => 'blah' })->{test}, 1,
631 "Resolve identity custom_capability");
633 $schema->storage->txn_rollback;
637 subtest 'Backend core methods' => sub {
641 $schema->storage->txn_begin;
643 # Build infrastructure
644 my $backend = Test::MockObject->new;
645 $backend->set_isa('Koha::Illbackends::Mock');
646 $backend->set_always('name', 'Mock');
647 $backend->mock('capabilities', sub { return 'Mock'; });
649 my $config = Test::MockObject->new;
650 $config->set_always('backend_dir', "/tmp");
651 $config->set_always('getLimitRules',
652 { default => { count => 0, method => 'active' } });
654 my $illrq = $builder->build_object({
655 class => 'Koha::Illrequests',
656 value => { backend => undef }
658 $illrq->_config($config);
660 # Test error conditions (no backend)
661 throws_ok { $illrq->load_backend; }
662 'Koha::Exceptions::Ill::InvalidBackendId',
663 'Exception raised correctly';
665 throws_ok { $illrq->load_backend(''); }
666 'Koha::Exceptions::Ill::InvalidBackendId',
667 'Exception raised correctly';
669 # Now load the mocked backend
670 $illrq->_backend($backend);
673 is_deeply($illrq->expandTemplate({ test => 1, method => "bar" }),
677 template => "/tmp/Mock/intra-includes/bar.inc",
678 opac_template => "/tmp/Mock/opac-includes/bar.inc",
683 # we are testing simple cases.
684 $backend->set_series('create',
685 { stage => 'bar', method => 'create' },
686 { stage => 'commit', method => 'create' },
687 { stage => 'commit', method => 'create' },
688 { stage => 'commit', method => 'create' },
689 { stage => 'commit', method => 'create' });
691 is_deeply($illrq->backend_create({test => 1}),
693 stage => 'bar', method => 'create',
694 template => "/tmp/Mock/intra-includes/create.inc",
695 opac_template => "/tmp/Mock/opac-includes/create.inc",
697 "Backend create: arbitrary stage.");
699 is_deeply($illrq->backend_create({test => 1}),
701 stage => 'commit', method => 'create', permitted => 0,
702 template => "/tmp/Mock/intra-includes/create.inc",
703 opac_template => "/tmp/Mock/opac-includes/create.inc",
705 "Backend create: arbitrary stage, not permitted.");
706 is($illrq->status, "QUEUED", "Backend create: queued if restricted.");
707 $config->set_always('getLimitRules', {});
708 $illrq->status('NEW');
709 is_deeply($illrq->backend_create({test => 1}),
711 stage => 'commit', method => 'create', permitted => 1,
712 template => "/tmp/Mock/intra-includes/create.inc",
713 opac_template => "/tmp/Mock/opac-includes/create.inc",
715 "Backend create: arbitrary stage, permitted.");
716 is($illrq->status, "NEW", "Backend create: not-queued.");
718 # Test that enabling the unmediated workflow causes the backend's
719 # 'unmediated_ill' method to be called
720 t::lib::Mocks::mock_preference('ILLModuleUnmediated', '1');
724 my ($self, $name) = @_;
725 if ($name eq 'unmediated_ill') {
727 return { unmediated_ill => 1 };
732 $illrq->status('NEW');
734 $illrq->backend_create({test => 1}),
736 'opac_template' => '/tmp/Mock/opac-includes/.inc',
737 'template' => '/tmp/Mock/intra-includes/.inc',
738 'unmediated_ill' => 1
740 "Backend create: commit stage, permitted, ILLModuleUnmediated enabled."
743 # Test that disabling the unmediated workflow causes the backend's
744 # 'unmediated_ill' method to be NOT called
745 t::lib::Mocks::mock_preference('ILLModuleUnmediated', '0');
746 $illrq->status('NEW');
748 $illrq->backend_create({test => 1}),
750 stage => 'commit', method => 'create', permitted => 1,
751 template => "/tmp/Mock/intra-includes/create.inc",
752 opac_template => "/tmp/Mock/opac-includes/create.inc",
754 "Backend create: commit stage, permitted, ILLModuleUnmediated disabled."
758 $backend->set_series('renew', { stage => 'bar', method => 'renew' });
759 is_deeply($illrq->backend_renew({test => 1}),
761 stage => 'bar', method => 'renew',
762 template => "/tmp/Mock/intra-includes/renew.inc",
763 opac_template => "/tmp/Mock/opac-includes/renew.inc",
765 "Backend renew: arbitrary stage.");
768 $backend->set_series('cancel', { stage => 'bar', method => 'cancel' });
769 is_deeply($illrq->backend_cancel({test => 1}),
771 stage => 'bar', method => 'cancel',
772 template => "/tmp/Mock/intra-includes/cancel.inc",
773 opac_template => "/tmp/Mock/opac-includes/cancel.inc",
775 "Backend cancel: arbitrary stage.");
778 $backend->set_series('illview', { stage => '', method => 'illview' });
779 is_deeply($illrq->backend_illview({test => 1}), 0,
780 "Backend illview optional method.");
782 # backend_update_status
783 $backend->set_series('update_status', { stage => 'bar', method => 'update_status' });
784 is_deeply($illrq->backend_update_status({test => 1}),
786 stage => 'bar', method => 'update_status',
787 template => "/tmp/Mock/intra-includes/update_status.inc",
788 opac_template => "/tmp/Mock/opac-includes/update_status.inc",
790 "Backend update_status: arbitrary stage.");
793 $backend->set_series('confirm', { stage => 'bar', method => 'confirm' });
794 is_deeply($illrq->backend_confirm({test => 1}),
796 stage => 'bar', method => 'confirm',
797 template => "/tmp/Mock/intra-includes/confirm.inc",
798 opac_template => "/tmp/Mock/opac-includes/confirm.inc",
800 "Backend confirm: arbitrary stage.");
804 'get_supplier_update',
806 my ( $self, $options ) = @_;
810 $backend->mock('capabilities', sub { return sub { return 1; } });
811 is_deeply($illrq->backend_get_update({}), 1,
812 "Backend get_update method.");
814 $config->set_always('partner_code', "ILLTSTLIB");
815 $backend->set_always('metadata', { Test => "Foobar" });
816 my $illbrn = $builder->build({
818 value => { branchemail => "", branchreplyto => "" }
820 my $partner1 = $builder->build({
821 source => 'Borrower',
822 value => { categorycode => "ILLTSTLIB" },
824 my $partner2 = $builder->build({
825 source => 'Borrower',
826 value => { categorycode => "ILLTSTLIB" },
828 my $gen_conf = $illrq->generic_confirm({
829 current_branchcode => $illbrn->{branchcode}
831 isnt(index($gen_conf->{value}->{draft}->{body}, $backend->metadata->{Test}), -1,
832 "Generic confirm: draft contains metadata."
834 is($gen_conf->{value}->{partners}->next->borrowernumber, $partner1->{borrowernumber},
835 "Generic cofnirm: partner 1 is correct."
837 is($gen_conf->{value}->{partners}->next->borrowernumber, $partner2->{borrowernumber},
838 "Generic confirm: partner 2 is correct."
841 dies_ok { $illrq->generic_confirm({
842 current_branchcode => $illbrn->{branchcode},
845 "Generic confirm: missing to dies OK.";
847 $schema->storage->txn_rollback;
851 subtest 'Helpers' => sub {
855 $schema->storage->txn_begin;
857 # Build infrastructure
858 my $backend = Test::MockObject->new;
859 $backend->set_isa('Koha::Illbackends::Mock');
860 $backend->set_always('name', 'Mock');
864 my ( $self, $rq ) = @_;
872 my $config = Test::MockObject->new;
873 $config->set_always('backend_dir', "/tmp");
875 my $patron = $builder->build({
876 source => 'Borrower',
877 value => { categorycode => "A" }
879 # Create a mocked branch with no email addressed defined
880 my $illbrn = $builder->build({
885 branchillemail => "",
889 my $illrq = $builder->build({
890 source => 'Illrequest',
891 value => { branchcode => "HDE", borrowernumber => $patron->{borrowernumber} }
893 my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id});
894 $illrq_obj->_config($config);
895 $illrq_obj->_backend($backend);
898 my $type = 'test_type_1';
899 my $name = 'test_name_1';
900 my $update = Test::MockObject->new;
901 $update->set_isa('Koha::Illrequest::SupplierUpdate');
902 $update->{source_type} = $type;
903 $update->{source_name} = $name;
904 $update->{processors} = [];
905 $update->mock('attach_processor', sub {
906 my ( $self, $to_attach ) = @_;
907 push @{$self->{processors}}, $to_attach;
909 my $processor = Test::MockObject->new;
910 $processor->{target_source_type} = $type;
911 $processor->{target_source_name} = $name;
912 $illrq_obj->init_processors();
913 $illrq_obj->push_processor($processor);
914 $illrq_obj->attach_processors($update);
916 scalar @{$update->{processors}},
918 'attaching processors as appropriate works'
922 $config->set_series('getPrefixes',
923 { HDE => "TEST", TSL => "BAR", default => "DEFAULT" },
924 { A => "ATEST", C => "CBAR", default => "DEFAULT" });
925 is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "HDE" }), "TEST",
926 "getPrefix: branch");
927 $config->set_series('getPrefixes',
928 { HDE => "TEST", TSL => "BAR", default => "DEFAULT" },
929 { A => "ATEST", C => "CBAR", default => "DEFAULT" });
930 is($illrq_obj->getPrefix({ branch => "UNKNOWN" }), "",
931 "getPrefix: default");
932 $config->set_always('getPrefixes', {});
933 is($illrq_obj->getPrefix({ branch => "UNKNOWN" }), "",
934 "getPrefix: the empty prefix");
937 $config->set_series('getPrefixes',
938 { HDE => "TEST", TSL => "BAR", default => "DEFAULT" },
939 { AB => "ATEST", CD => "CBAR", default => "DEFAULT" });
940 is($illrq_obj->id_prefix, "TEST-", "id_prefix: branch");
941 $config->set_series('getPrefixes',
942 { HDET => "TEST", TSLT => "BAR", default => "DEFAULT" },
943 { AB => "ATEST", CD => "CBAR", default => "DEFAULT" });
944 is($illrq_obj->id_prefix, "", "id_prefix: default");
946 # requires_moderation
947 $illrq_obj->status('NEW')->store;
948 is($illrq_obj->requires_moderation, undef, "requires_moderation: No.");
949 $illrq_obj->status('CANCREQ')->store;
950 is($illrq_obj->requires_moderation, 'CANCREQ', "requires_moderation: Yes.");
953 my $attr = Koha::MessageAttributes->find({ message_name => 'Ill_ready' });
954 C4::Members::Messaging::SetMessagingPreference({
955 borrowernumber => $patron->{borrowernumber},
956 message_attribute_id => $attr->message_attribute_id,
957 message_transport_types => ['email']
959 my $return_patron = $illrq_obj->send_patron_notice('ILL_PICKUP_READY');
960 my $notice = $schema->resultset('MessageQueue')->search({
961 letter_code => 'ILL_PICKUP_READY',
962 message_transport_type => 'email',
963 borrowernumber => $illrq_obj->borrowernumber
964 })->next()->letter_code;
967 { result => { success => ['email'], fail => [] } },
968 "Correct return when notice created"
970 is($notice, 'ILL_PICKUP_READY' ,"Notice is correctly created");
972 # ill update notice, passes additional text parameter
973 my $attr_update = Koha::MessageAttributes->find({ message_name => 'Ill_update' });
974 C4::Members::Messaging::SetMessagingPreference({
975 borrowernumber => $patron->{borrowernumber},
976 message_attribute_id => $attr_update->message_attribute_id,
977 message_transport_types => ['email']
979 my $return_patron_update = $illrq_obj->send_patron_notice('ILL_REQUEST_UPDATE', 'Some additional text');
980 my $notice_update = $schema->resultset('MessageQueue')->search({
981 letter_code => 'ILL_REQUEST_UPDATE',
982 message_transport_type => 'email',
983 borrowernumber => $illrq_obj->borrowernumber
984 })->next()->letter_code;
986 $return_patron_update,
987 { result => { success => ['email'], fail => [] } },
988 "Correct return when notice created"
990 is($notice_update, 'ILL_REQUEST_UPDATE' ,"Notice is correctly created");
993 my $return_patron_fail = $illrq_obj->send_patron_notice();
996 { error => 'notice_no_type' },
997 "Correct error when missing type"
1001 # Specify that no staff notices should be send
1002 t::lib::Mocks::mock_preference('ILLSendStaffNotices', '');
1003 my $return_staff_cancel_fail =
1004 $illrq_obj->send_staff_notice('ILL_REQUEST_CANCEL');
1006 $return_staff_cancel_fail,
1007 { error => 'notice_not_enabled' },
1008 "Does not send notices that are not enabled"
1010 my $queue = $schema->resultset('MessageQueue')->search({
1011 letter_code => 'ILL_REQUEST_CANCEL'
1013 is($queue->count, 0, "Notice is not queued");
1015 # Specify that the cancel notice can be sent
1016 t::lib::Mocks::mock_preference('ILLSendStaffNotices', 'ILL_REQUEST_CANCEL');
1017 my $return_staff_cancel = $illrq_obj->send_staff_notice(
1018 'ILL_REQUEST_CANCEL'
1021 $return_staff_cancel,
1022 { success => 'notice_queued' },
1023 "Correct return when staff notice created"
1025 $queue = $schema->resultset('MessageQueue')->search({
1026 letter_code => 'ILL_REQUEST_CANCEL'
1028 is($queue->count, 1, "Notice queued as expected");
1030 my $return_staff_fail = $illrq_obj->send_staff_notice();
1033 { error => 'notice_no_type' },
1034 "Correct error when missing type"
1036 $queue = $schema->resultset('MessageQueue')->search({
1037 letter_code => 'ILL_REQUEST_CANCEL'
1039 is($queue->count, 1, "Notice is not queued");
1042 my $not = $illrq_obj->get_notice({
1043 notice_code => 'ILL_REQUEST_CANCEL',
1044 transport => 'email'
1047 # We test the properties of the hashref separately because the random
1048 # hash ordering of the metadata means we can't test the entire thing
1051 $not->{module} eq 'ill',
1052 'Correct module return from get_notice'
1055 $not->{name} eq 'ILL request cancelled',
1056 'Correct name return from get_notice'
1059 $not->{message_transport_type} eq 'email',
1060 'Correct message_transport_type return from get_notice'
1063 $not->{title} eq 'Interlibrary loan request cancelled',
1064 'Correct title return from get_notice'
1066 $not->{content} =~ s/\s//g;
1069 $not->{content},"Thepatronforinterlibraryloansrequest" . $illrq_obj->id . ",withthefollowingdetails,hasrequestedcancellationofthisILLrequest:-author:myauthor-title:mytitle",
1070 'Correct content returned from get_notice with metadata correctly ordered'
1073 $illrq_obj->append_to_note('Some text');
1075 $illrq_obj->notesstaff,
1077 'appending to a note works'
1080 $schema->storage->txn_rollback;
1084 subtest 'Censorship' => sub {
1088 $schema->storage->txn_begin;
1090 # Build infrastructure
1091 my $backend = Test::MockObject->new;
1092 $backend->set_isa('Koha::Illbackends::Mock');
1093 $backend->set_always('name', 'Mock');
1095 my $config = Test::MockObject->new;
1096 $config->set_always('backend_dir', "/tmp");
1098 my $illrq = $builder->build({source => 'Illrequest'});
1099 my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id});
1100 $illrq_obj->_config($config);
1101 $illrq_obj->_backend($backend);
1103 $config->set_always('censorship', { censor_notes_staff => 1, censor_reply_date => 0 });
1105 my $censor_out = $illrq_obj->_censor({ foo => 'bar', baz => 564 });
1106 is_deeply($censor_out, { foo => 'bar', baz => 564, display_reply_date => 1 },
1107 "_censor: not OPAC, reply_date = 1");
1109 $censor_out = $illrq_obj->_censor({ foo => 'bar', baz => 564, opac => 1 });
1110 is_deeply($censor_out, {
1111 foo => 'bar', baz => 564, censor_notes_staff => 1,
1112 display_reply_date => 1, opac => 1
1113 }, "_censor: notes_staff = 0, reply_date = 0");
1115 $schema->storage->txn_rollback;
1118 subtest 'Checking out' => sub {
1122 $schema->storage->txn_begin;
1124 my $itemtype = $builder->build_object({
1125 class => 'Koha::ItemTypes',
1130 my $library = $builder->build_object({ class => 'Koha::Libraries' });
1131 my $biblio = $builder->build_sample_biblio();
1132 my $patron = $builder->build_object({
1133 class => 'Koha::Patrons',
1134 value => { category_type => 'x' }
1136 my $request = $builder->build_object({
1137 class => 'Koha::Illrequests',
1139 borrowernumber => $patron->borrowernumber,
1140 biblio_id => $biblio->biblionumber
1144 # First test that calling check_out without a stage param returns
1145 # what's required to build the form
1146 my $no_stage = $request->check_out();
1147 is($no_stage->{method}, 'check_out');
1148 is($no_stage->{stage}, 'form');
1149 isa_ok($no_stage->{value}, 'HASH');
1150 isa_ok($no_stage->{value}->{itemtypes}, 'Koha::ItemTypes');
1151 isa_ok($no_stage->{value}->{libraries}, 'Koha::Libraries');
1152 isa_ok($no_stage->{value}->{statistical}, 'Koha::Patrons');
1153 isa_ok($no_stage->{value}->{biblio}, 'Koha::Biblio');
1155 # Now test that form validation works when we supply a 'form' stage
1158 my $form_stage_missing_params = $request->check_out({
1161 is_deeply($form_stage_missing_params->{value}->{errors}, {
1164 # inhouse passed but not a valid patron
1165 my $form_stage_bad_patron = $request->check_out({
1167 item_type => $itemtype->itemtype,
1168 inhouse => 'I_DONT_EXIST'
1170 is_deeply($form_stage_bad_patron->{value}->{errors}, {
1173 # Too many items attached to biblio
1174 my $item1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
1175 my $item2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
1176 my $form_stage_two_items = $request->check_out({
1178 item_type => $itemtype->itemtype,
1180 is_deeply($form_stage_two_items->{value}->{errors}, {
1184 # Delete the items we created, so we can test that we can create one
1188 # We need to mock the user environment for AddIssue
1189 t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode });
1192 # First we pass bad parameters to the item creation to test we're
1193 # catching the failure of item creation
1194 my $form_stage_bad_branchcode;
1196 $form_stage_bad_branchcode = $request->check_out({
1198 item_type => $itemtype->itemtype,
1201 } qr/DBD::mysql::st execute failed: Cannot add or update a child row: a foreign key constraint fails/,
1202 "Item creation fails on bad parameters";
1204 is_deeply($form_stage_bad_branchcode->{value}->{errors}, {
1206 },"We get expected failure of item creation");
1208 # Now create a proper item
1209 my $form_stage_good_branchcode = $request->check_out({
1211 item_type => $itemtype->itemtype,
1212 branchcode => $library->branchcode
1214 # By default, this item should not be loanable, so check that we're
1215 # informed of that fact
1217 $form_stage_good_branchcode->{value}->{check_out_errors},
1221 itemtype_notforloan => $itemtype->itemtype
1224 "We get expected error on notforloan of item"
1226 # Delete the item that was created
1227 $biblio->items->delete;
1228 # Now create an itemtype that is loanable
1229 my $itemtype_loanable = $builder->build_object({
1230 class => 'Koha::ItemTypes',
1235 # We need to mock the user environment for AddIssue
1236 t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode });
1237 my $form_stage_loanable = $request->check_out({
1239 item_type => $itemtype_loanable->itemtype,
1240 branchcode => $library->branchcode
1242 is($form_stage_loanable->{stage}, 'done_check_out');
1243 isa_ok($patron->checkouts, 'Koha::Checkouts');
1244 is($patron->checkouts->count, 1);
1245 is($request->status, 'CHK');
1247 $schema->storage->txn_rollback;
1250 subtest 'Checking out with custom due date' => sub {
1252 $schema->storage->txn_begin;
1254 my $library = $builder->build_object({ class => 'Koha::Libraries' });
1255 my $patron = $builder->build_object({
1256 class => 'Koha::Patrons',
1257 value => { category_type => 'x' }
1259 my $biblio = $builder->build_sample_biblio();
1260 my $itemtype_loanable = $builder->build_object({
1261 class => 'Koha::ItemTypes',
1266 my $request = $builder->build_object({
1267 class => 'Koha::Illrequests',
1269 borrowernumber => $patron->borrowernumber,
1270 biblio_id => $biblio->biblionumber
1274 t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode });
1275 my $duedate = '2099-05-21 00:00:00';
1276 my $form_stage_loanable = $request->check_out({
1278 item_type => $itemtype_loanable->itemtype,
1279 branchcode => $library->branchcode,
1282 is($patron->checkouts->next->date_due, $duedate, "Custom due date was used");
1284 $schema->storage->txn_rollback;
1287 subtest 'Checking Limits' => sub {
1291 $schema->storage->txn_begin;
1293 # Build infrastructure
1294 my $backend = Test::MockObject->new;
1295 $backend->set_isa('Koha::Illbackends::Mock');
1296 $backend->set_always('name', 'Mock');
1298 my $config = Test::MockObject->new;
1299 $config->set_always('backend_dir', "/tmp");
1301 my $illrq = $builder->build({source => 'Illrequest'});
1302 my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id});
1303 $illrq_obj->_config($config);
1304 $illrq_obj->_backend($backend);
1307 $config->set_series('getLimitRules',
1308 { CPL => { count => 1, method => 'test' } },
1309 { default => { count => 0, method => 'active' } });
1310 is_deeply($illrq_obj->getLimits({ type => 'branch', value => "CPL" }),
1311 { count => 1, method => 'test' },
1312 "getLimits: by value.");
1313 is_deeply($illrq_obj->getLimits({ type => 'branch' }),
1314 { count => 0, method => 'active' },
1315 "getLimits: by default.");
1316 is_deeply($illrq_obj->getLimits({ type => 'branch', value => "CPL" }),
1317 { count => -1, method => 'active' },
1318 "getLimits: by hard-coded.");
1321 is($illrq_obj->_limit_counter('annual', { branchcode => $illrq_obj->branchcode }),
1322 1, "_limit_counter: Initial branch annual count.");
1323 is($illrq_obj->_limit_counter('active', { branchcode => $illrq_obj->branchcode }),
1324 1, "_limit_counter: Initial branch active count.");
1325 is($illrq_obj->_limit_counter('annual', { borrowernumber => $illrq_obj->borrowernumber }),
1326 1, "_limit_counter: Initial patron annual count.");
1327 is($illrq_obj->_limit_counter('active', { borrowernumber => $illrq_obj->borrowernumber }),
1328 1, "_limit_counter: Initial patron active count.");
1330 source => 'Illrequest',
1332 branchcode => $illrq_obj->branchcode,
1333 borrowernumber => $illrq_obj->borrowernumber,
1336 is($illrq_obj->_limit_counter('annual', { branchcode => $illrq_obj->branchcode }),
1337 2, "_limit_counter: Add a qualifying request for branch annual count.");
1338 is($illrq_obj->_limit_counter('active', { branchcode => $illrq_obj->branchcode }),
1339 2, "_limit_counter: Add a qualifying request for branch active count.");
1340 is($illrq_obj->_limit_counter('annual', { borrowernumber => $illrq_obj->borrowernumber }),
1341 2, "_limit_counter: Add a qualifying request for patron annual count.");
1342 is($illrq_obj->_limit_counter('active', { borrowernumber => $illrq_obj->borrowernumber }),
1343 2, "_limit_counter: Add a qualifying request for patron active count.");
1345 source => 'Illrequest',
1347 branchcode => $illrq_obj->branchcode,
1348 borrowernumber => $illrq_obj->borrowernumber,
1349 placed => "2005-05-31",
1352 is($illrq_obj->_limit_counter('annual', { branchcode => $illrq_obj->branchcode }),
1353 2, "_limit_counter: Add an out-of-date branch request.");
1354 is($illrq_obj->_limit_counter('active', { branchcode => $illrq_obj->branchcode }),
1355 3, "_limit_counter: Add a qualifying request for branch active count.");
1356 is($illrq_obj->_limit_counter('annual', { borrowernumber => $illrq_obj->borrowernumber }),
1357 2, "_limit_counter: Add an out-of-date patron request.");
1358 is($illrq_obj->_limit_counter('active', { borrowernumber => $illrq_obj->borrowernumber }),
1359 3, "_limit_counter: Add a qualifying request for patron active count.");
1361 source => 'Illrequest',
1363 branchcode => $illrq_obj->branchcode,
1364 borrowernumber => $illrq_obj->borrowernumber,
1368 is($illrq_obj->_limit_counter('annual', { branchcode => $illrq_obj->branchcode }),
1369 3, "_limit_counter: Add a qualifying request for branch annual count.");
1370 is($illrq_obj->_limit_counter('active', { branchcode => $illrq_obj->branchcode }),
1371 3, "_limit_counter: Add a completed request for branch active count.");
1372 is($illrq_obj->_limit_counter('annual', { borrowernumber => $illrq_obj->borrowernumber }),
1373 3, "_limit_counter: Add a qualifying request for patron annual count.");
1374 is($illrq_obj->_limit_counter('active', { borrowernumber => $illrq_obj->borrowernumber }),
1375 3, "_limit_counter: Add a completed request for patron active count.");
1379 # We've tested _limit_counter, so all we need to test here is whether the
1380 # current counts of 3 for each work as they should against different
1381 # configuration declarations.
1384 $config->set_always('getLimitRules', undef);
1385 is($illrq_obj->check_limits({patron => $illrq_obj->patron,
1386 librarycode => $illrq_obj->branchcode}),
1387 1, "check_limits: no configuration => no limits.");
1390 $config->set_always('getLimitRules',
1391 { $illrq_obj->branchcode => { count => 1, method => 'active' } });
1392 is($illrq_obj->check_limits({patron => $illrq_obj->patron,
1393 librarycode => $illrq_obj->branchcode}),
1394 0, "check_limits: branch active limit exceeded.");
1395 $config->set_always('getLimitRules',
1396 { $illrq_obj->branchcode => { count => 1, method => 'annual' } });
1397 is($illrq_obj->check_limits({patron => $illrq_obj->patron,
1398 librarycode => $illrq_obj->branchcode}),
1399 0, "check_limits: branch annual limit exceeded.");
1400 $config->set_always('getLimitRules',
1401 { $illrq_obj->branchcode => { count => 4, method => 'active' } });
1402 is($illrq_obj->check_limits({patron => $illrq_obj->patron,
1403 librarycode => $illrq_obj->branchcode}),
1404 1, "check_limits: branch active limit OK.");
1405 $config->set_always('getLimitRules',
1406 { $illrq_obj->branchcode => { count => 4, method => 'annual' } });
1407 is($illrq_obj->check_limits({patron => $illrq_obj->patron,
1408 librarycode => $illrq_obj->branchcode}),
1409 1, "check_limits: branch annual limit OK.");
1412 $config->set_always('getLimitRules',
1413 { $illrq_obj->patron->categorycode => { count => 1, method => 'active' } });
1414 is($illrq_obj->check_limits({patron => $illrq_obj->patron,
1415 librarycode => $illrq_obj->branchcode}),
1416 0, "check_limits: patron category active limit exceeded.");
1417 $config->set_always('getLimitRules',
1418 { $illrq_obj->patron->categorycode => { count => 1, method => 'annual' } });
1419 is($illrq_obj->check_limits({patron => $illrq_obj->patron,
1420 librarycode => $illrq_obj->branchcode}),
1421 0, "check_limits: patron category annual limit exceeded.");
1422 $config->set_always('getLimitRules',
1423 { $illrq_obj->patron->categorycode => { count => 4, method => 'active' } });
1424 is($illrq_obj->check_limits({patron => $illrq_obj->patron,
1425 librarycode => $illrq_obj->branchcode}),
1426 1, "check_limits: patron category active limit OK.");
1427 $config->set_always('getLimitRules',
1428 { $illrq_obj->patron->categorycode => { count => 4, method => 'annual' } });
1429 is($illrq_obj->check_limits({patron => $illrq_obj->patron,
1430 librarycode => $illrq_obj->branchcode}),
1431 1, "check_limits: patron category annual limit OK.");
1433 # One rule cancels the other
1434 $config->set_series('getLimitRules',
1435 # Branch rules allow request
1436 { $illrq_obj->branchcode => { count => 4, method => 'active' } },
1437 # Patron rule forbids it
1438 { $illrq_obj->patron->categorycode => { count => 1, method => 'annual' } });
1439 is($illrq_obj->check_limits({patron => $illrq_obj->patron,
1440 librarycode => $illrq_obj->branchcode}),
1441 0, "check_limits: patron category veto overrides branch OK.");
1442 $config->set_series('getLimitRules',
1443 # Branch rules allow request
1444 { $illrq_obj->branchcode => { count => 1, method => 'active' } },
1445 # Patron rule forbids it
1446 { $illrq_obj->patron->categorycode => { count => 4, method => 'annual' } });
1447 is($illrq_obj->check_limits({patron => $illrq_obj->patron,
1448 librarycode => $illrq_obj->branchcode}),
1449 0, "check_limits: branch veto overrides patron category OK.");
1451 $schema->storage->txn_rollback;
1454 subtest 'Custom statuses' => sub {
1458 $schema->storage->txn_begin;
1460 my $cat = Koha::AuthorisedValueCategories->search(
1462 category_name => 'ILLSTATUS'
1466 if ($cat->count == 0) {
1467 $cat = $builder->build_object(
1469 class => 'Koha::AuthorisedValueCategory',
1471 category_name => 'ILLSTATUS'
1477 my $av = $builder->build_object(
1479 class => 'Koha::AuthorisedValues',
1481 category => 'ILLSTATUS'
1486 is($av->category, 'ILLSTATUS',
1487 "Successfully created authorised value for custom status");
1489 my $ill_req = $builder->build_object(
1491 class => 'Koha::Illrequests',
1493 status_alias => $av->authorised_value
1497 isa_ok($ill_req->statusalias, 'Koha::AuthorisedValue',
1498 "statusalias correctly returning Koha::AuthorisedValue object");
1500 $ill_req->status("COMP");
1501 is($ill_req->statusalias, undef,
1502 "Koha::Illrequest->status overloading resetting status_alias");
1504 $schema->storage->txn_rollback;
1507 subtest 'Checking in hook' => sub {
1511 $schema->storage->txn_begin;
1513 # Build infrastructure
1514 my $backend = Test::MockObject->new;
1515 $backend->set_isa('Koha::Illbackends::Mock');
1516 $backend->set_always('name', 'Mock');
1518 my $config = Test::MockObject->new;
1519 $config->set_always('backend_dir', "/tmp");
1521 my $item = $builder->build_sample_item();
1522 my $patron = $builder->build_object({ class => 'Koha::Patrons' });
1524 t::lib::Mocks::mock_userenv(
1527 branchcode => $patron->branchcode
1531 my $illrq = $builder->build_object(
1533 class => 'Koha::Illrequests',
1535 biblio_id => $item->biblio->biblionumber,
1541 $illrq->_config($config);
1542 $illrq->_backend($backend);
1544 t::lib::Mocks::mock_preference('CirculateILL', 1);
1547 AddIssue( $patron->unblessed, $item->barcode );
1548 # Make the item withdrawn so checking-in is rejected
1549 t::lib::Mocks::mock_preference('BlockReturnOfWithdrawnItems', 1);
1550 $item->set({ withdrawn => 1 })->store;
1551 AddReturn( $item->barcode, $patron->branchcode );
1553 $illrq->discard_changes;
1554 isnt( $illrq->status, 'RET' );
1556 # allow the check-in
1557 $item->set({ withdrawn => 0 })->store;
1558 AddReturn( $item->barcode, $patron->branchcode );
1560 $illrq->discard_changes;
1561 is( $illrq->status, 'RET' );
1563 $schema->storage->txn_rollback;