3 # Copyright 2020 Koha Development team
5 # This file is part of Koha
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use Test::More tests => 11;
28 use t::lib::TestBuilder;
32 use Koha::DateUtils qw(dt_from_string);
37 my $schema = Koha::Database->new->schema;
38 my $builder = t::lib::TestBuilder->new;
40 subtest 'store() tests' => sub {
43 $schema->storage->txn_begin;
45 my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
46 my $item = $builder->build_sample_item;
50 borrowernumber => $patron->borrowernumber,
51 biblionumber => $item->biblionumber,
53 itemnumber => $item->itemnumber,
57 'Koha::Exceptions::Hold::MissingPickupLocation',
58 'Exception thrown because branchcode was not passed';
60 my $hold = $builder->build_object( { class => 'Koha::Holds' } );
62 $hold->branchcode(undef)->store;
64 'Koha::Exceptions::Hold::MissingPickupLocation',
65 'Exception thrown if one tries to set branchcode to null';
67 $schema->storage->txn_rollback;
70 subtest 'fill() tests' => sub {
74 $schema->storage->txn_begin;
78 my $category = $builder->build_object(
80 class => 'Koha::Patron::Categories',
81 value => { reservefee => $fee }
84 my $patron = $builder->build_object(
86 class => 'Koha::Patrons',
87 value => { categorycode => $category->id }
90 my $manager = $builder->build_object( { class => 'Koha::Patrons' } );
92 my $title = 'Do what you want';
93 my $biblio = $builder->build_sample_biblio( { title => $title } );
94 my $item = $builder->build_sample_item( { biblionumber => $biblio->id } );
95 my $hold = $builder->build_object(
97 class => 'Koha::Holds',
99 biblionumber => $biblio->id,
100 borrowernumber => $patron->id,
101 itemnumber => $item->id,
107 t::lib::Mocks::mock_preference( 'HoldFeeMode', 'any_time_is_collected' );
108 t::lib::Mocks::mock_preference( 'HoldsLog', 1 );
109 t::lib::Mocks::mock_userenv(
110 { patron => $manager, branchcode => $manager->branchcode } );
112 my $interface = 'api';
113 C4::Context->interface($interface);
115 my $ret = $hold->fill;
117 is( ref($ret), 'Koha::Hold', '->fill returns the object type' );
118 is( $ret->id, $hold->id, '->fill returns the object' );
120 is( Koha::Holds->find($hold->id), undef, 'Hold no longer current' );
121 my $old_hold = Koha::Old::Holds->find( $hold->id );
123 is( $old_hold->id, $hold->id, 'reserve_id retained' );
124 is( $old_hold->priority, 0, 'priority set to 0' );
125 is( $old_hold->found, 'F', 'found set to F' );
127 subtest 'fee applied tests' => sub {
131 my $account = $patron->account;
132 is( $account->balance, $fee, 'Charge applied correctly' );
134 my $debits = $account->outstanding_debits;
135 is( $debits->count, 1, 'Only one fee charged' );
137 my $fee_debit = $debits->next;
138 is( $fee_debit->amount * 1, $fee, 'Fee amount stored correctly' );
139 is( $fee_debit->description, $title,
140 'Fee description stored correctly' );
141 is( $fee_debit->manager_id, $manager->id,
142 'Fee manager_id stored correctly' );
143 is( $fee_debit->branchcode, $manager->branchcode,
144 'Fee branchcode stored correctly' );
145 is( $fee_debit->interface, $interface,
146 'Fee interface stored correctly' );
147 is( $fee_debit->debit_type_code,
148 'RESERVE', 'Fee debit_type_code stored correctly' );
149 is( $fee_debit->itemnumber, $item->id,
150 'Fee itemnumber stored correctly' );
153 my $logs = Koha::ActionLogs->search(
161 is( $logs->count, 1, '1 log line added' );
163 # Set HoldFeeMode to something other than any_time_is_collected
164 t::lib::Mocks::mock_preference( 'HoldFeeMode', 'not_always' );
166 t::lib::Mocks::mock_preference( 'HoldsLog', 0 );
168 $hold = $builder->build_object(
170 class => 'Koha::Holds',
172 biblionumber => $biblio->id,
173 borrowernumber => $patron->id,
174 itemnumber => $item->id,
182 my $account = $patron->account;
183 is( $account->balance, $fee, 'No new charge applied' );
185 my $debits = $account->outstanding_debits;
186 is( $debits->count, 1, 'Only one fee charged, because of HoldFeeMode' );
188 $logs = Koha::ActionLogs->search(
196 is( $logs->count, 0, 'HoldsLog disabled, no logs added' );
198 subtest 'anonymization behavior tests' => sub {
202 # reduce the tests noise
203 t::lib::Mocks::mock_preference( 'HoldsLog', 0 );
204 t::lib::Mocks::mock_preference( 'HoldFeeMode', 'not_always' );
205 # unset AnonymousPatron
206 t::lib::Mocks::mock_preference( 'AnonymousPatron', undef );
209 $patron->privacy(0)->store;
210 my $hold = $builder->build_object(
212 class => 'Koha::Holds',
213 value => { borrowernumber => $patron->id, found => undef }
217 is( Koha::Old::Holds->find( $hold->id )->borrowernumber,
218 $patron->borrowernumber, 'Patron link is kept' );
220 # 1 == "default", meaning it is not protected from removal
221 $patron->privacy(1)->store;
222 $hold = $builder->build_object(
224 class => 'Koha::Holds',
225 value => { borrowernumber => $patron->id, found => undef }
229 is( Koha::Old::Holds->find( $hold->id )->borrowernumber,
230 $patron->borrowernumber, 'Patron link is kept' );
232 my $anonymous_patron = $builder->build_object({ class => 'Koha::Patrons' });
233 t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id );
234 # We need anonymous patron set to change patron privacy to never
235 # (2 == delete immediately)
236 # then we can undef for further tests
237 $patron->privacy(2)->store;
238 t::lib::Mocks::mock_preference( 'AnonymousPatron', undef );
239 $hold = $builder->build_object(
241 class => 'Koha::Holds',
242 value => { borrowernumber => $patron->id, found => undef }
249 'AnonymousPatron not set, exception thrown';
251 $hold->discard_changes; # refresh from DB
253 ok( !$hold->is_found, 'Hold is not filled' );
255 t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id );
257 $hold = $builder->build_object(
259 class => 'Koha::Holds',
260 value => { borrowernumber => $patron->id, found => undef }
265 Koha::Old::Holds->find( $hold->id )->borrowernumber,
266 $anonymous_patron->id,
267 'Patron link is set to the configured anonymous patron immediately'
271 subtest 'holds_queue update tests' => sub {
275 my $biblio = $builder->build_sample_biblio;
277 my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue');
278 $mock->mock( 'enqueue', sub {
279 my ( $self, $args ) = @_;
283 '->fill triggers a holds queue update for the related biblio'
287 t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 );
289 $builder->build_object(
291 class => 'Koha::Holds',
293 biblionumber => $biblio->id,
298 t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 );
299 # this call shouldn't add a new test
300 $builder->build_object(
302 class => 'Koha::Holds',
304 biblionumber => $biblio->id,
310 $schema->storage->txn_rollback;
313 subtest 'patron() tests' => sub {
317 $schema->storage->txn_begin;
319 my $patron = $builder->build_object({ class => 'Koha::Patrons' });
320 my $hold = $builder->build_object(
322 class => 'Koha::Holds',
324 borrowernumber => $patron->borrowernumber
329 my $hold_patron = $hold->patron;
330 is( ref($hold_patron), 'Koha::Patron', 'Right type' );
331 is( $hold_patron->id, $patron->id, 'Right object' );
333 $schema->storage->txn_rollback;
336 subtest 'set_pickup_location() tests' => sub {
340 $schema->storage->txn_begin;
342 my $mock_biblio = Test::MockModule->new('Koha::Biblio');
343 my $mock_item = Test::MockModule->new('Koha::Item');
345 my $library_1 = $builder->build_object({ class => 'Koha::Libraries' });
346 my $library_2 = $builder->build_object({ class => 'Koha::Libraries' });
347 my $library_3 = $builder->build_object({ class => 'Koha::Libraries' });
349 # let's control what Koha::Biblio->pickup_locations returns, for testing
350 $mock_biblio->mock( 'pickup_locations', sub {
351 return Koha::Libraries->search( { branchcode => [ $library_2->branchcode, $library_3->branchcode ] } );
353 # let's mock what Koha::Item->pickup_locations returns, for testing
354 $mock_item->mock( 'pickup_locations', sub {
355 return Koha::Libraries->search( { branchcode => [ $library_2->branchcode, $library_3->branchcode ] } );
358 my $biblio = $builder->build_sample_biblio;
359 my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
361 # Test biblio-level holds
362 my $biblio_hold = $builder->build_object(
364 class => "Koha::Holds",
366 biblionumber => $biblio->biblionumber,
367 branchcode => $library_3->branchcode,
374 { $biblio_hold->set_pickup_location({ library_id => $library_1->branchcode }); }
375 'Koha::Exceptions::Hold::InvalidPickupLocation',
376 'Exception thrown on invalid pickup location';
378 $biblio_hold->discard_changes;
379 is( $biblio_hold->branchcode, $library_3->branchcode, 'branchcode remains untouched' );
381 my $ret = $biblio_hold->set_pickup_location({ library_id => $library_2->id });
382 is( ref($ret), 'Koha::Hold', 'self is returned' );
384 $biblio_hold->discard_changes;
385 is( $biblio_hold->branchcode, $library_2->id, 'Pickup location changed correctly' );
387 # Test item-level holds
388 my $item_hold = $builder->build_object(
390 class => "Koha::Holds",
392 biblionumber => $biblio->biblionumber,
393 branchcode => $library_3->branchcode,
394 itemnumber => $item->itemnumber,
400 { $item_hold->set_pickup_location({ library_id => $library_1->branchcode }); }
401 'Koha::Exceptions::Hold::InvalidPickupLocation',
402 'Exception thrown on invalid pickup location';
404 $item_hold->discard_changes;
405 is( $item_hold->branchcode, $library_3->branchcode, 'branchcode remains untouched' );
407 $item_hold->set_pickup_location({ library_id => $library_1->branchcode, force => 1 });
408 $item_hold->discard_changes;
409 is( $item_hold->branchcode, $library_1->branchcode, 'branchcode changed because of \'force\'' );
411 $ret = $item_hold->set_pickup_location({ library_id => $library_2->id });
412 is( ref($ret), 'Koha::Hold', 'self is returned' );
414 $item_hold->discard_changes;
415 is( $item_hold->branchcode, $library_2->id, 'Pickup location changed correctly' );
418 { $item_hold->set_pickup_location({ library_id => undef }); }
419 'Koha::Exceptions::MissingParameter',
420 'Exception thrown if missing parameter';
422 like( "$@", qr/The library_id parameter is mandatory/, 'Exception message is clear' );
424 $schema->storage->txn_rollback;
427 subtest 'is_pickup_location_valid() tests' => sub {
431 $schema->storage->txn_begin;
433 my $mock_biblio = Test::MockModule->new('Koha::Biblio');
434 my $mock_item = Test::MockModule->new('Koha::Item');
436 my $library_1 = $builder->build_object({ class => 'Koha::Libraries' });
437 my $library_2 = $builder->build_object({ class => 'Koha::Libraries' });
438 my $library_3 = $builder->build_object({ class => 'Koha::Libraries' });
440 # let's control what Koha::Biblio->pickup_locations returns, for testing
441 $mock_biblio->mock( 'pickup_locations', sub {
442 return Koha::Libraries->search( { branchcode => [ $library_2->branchcode, $library_3->branchcode ] } );
444 # let's mock what Koha::Item->pickup_locations returns, for testing
445 $mock_item->mock( 'pickup_locations', sub {
446 return Koha::Libraries->search( { branchcode => [ $library_2->branchcode, $library_3->branchcode ] } );
449 my $biblio = $builder->build_sample_biblio;
450 my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
452 # Test biblio-level holds
453 my $biblio_hold = $builder->build_object(
455 class => "Koha::Holds",
457 biblionumber => $biblio->biblionumber,
458 branchcode => $library_3->branchcode,
464 ok( !$biblio_hold->is_pickup_location_valid({ library_id => $library_1->branchcode }), 'Pickup location invalid');
465 ok( $biblio_hold->is_pickup_location_valid({ library_id => $library_2->id }), 'Pickup location valid');
467 # Test item-level holds
468 my $item_hold = $builder->build_object(
470 class => "Koha::Holds",
472 biblionumber => $biblio->biblionumber,
473 branchcode => $library_3->branchcode,
474 itemnumber => $item->itemnumber,
479 ok( !$item_hold->is_pickup_location_valid({ library_id => $library_1->branchcode }), 'Pickup location invalid');
480 ok( $item_hold->is_pickup_location_valid({ library_id => $library_2->id }), 'Pickup location valid' );
482 subtest 'pickup_locations() returning ->empty' => sub {
486 $schema->storage->txn_begin;
488 my $library = $builder->build_object({ class => 'Koha::Libraries' });
490 my $mock_item = Test::MockModule->new('Koha::Item');
491 $mock_item->mock( 'pickup_locations', sub { return Koha::Libraries->new->empty; } );
493 my $mock_biblio = Test::MockModule->new('Koha::Biblio');
494 $mock_biblio->mock( 'pickup_locations', sub { return Koha::Libraries->new->empty; } );
496 my $item = $builder->build_sample_item();
497 my $biblio = $item->biblio;
499 # Test biblio-level holds
500 my $biblio_hold = $builder->build_object(
502 class => "Koha::Holds",
504 biblionumber => $biblio->biblionumber,
510 ok( !$biblio_hold->is_pickup_location_valid({ library_id => $library->branchcode }), 'Pickup location invalid');
512 # Test item-level holds
513 my $item_hold = $builder->build_object(
515 class => "Koha::Holds",
517 biblionumber => $biblio->biblionumber,
518 itemnumber => $item->itemnumber,
523 ok( !$item_hold->is_pickup_location_valid({ library_id => $library->branchcode }), 'Pickup location invalid');
525 $schema->storage->txn_rollback;
528 $schema->storage->txn_rollback;
531 subtest 'cancel() tests' => sub {
535 $schema->storage->txn_begin;
537 my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
539 # reduce the tests noise
540 t::lib::Mocks::mock_preference( 'HoldsLog', 0 );
541 t::lib::Mocks::mock_preference( 'ExpireReservesMaxPickUpDelayCharge',
544 t::lib::Mocks::mock_preference( 'AnonymousPatron', undef );
547 $patron->privacy(0)->store;
548 my $hold = $builder->build_object(
550 class => 'Koha::Holds',
551 value => { borrowernumber => $patron->id, found => undef }
555 is( Koha::Old::Holds->find( $hold->id )->borrowernumber,
556 $patron->borrowernumber, 'Patron link is kept' );
558 # 1 == "default", meaning it is not protected from removal
559 $patron->privacy(1)->store;
560 $hold = $builder->build_object(
562 class => 'Koha::Holds',
563 value => { borrowernumber => $patron->id, found => undef }
567 is( Koha::Old::Holds->find( $hold->id )->borrowernumber,
568 $patron->borrowernumber, 'Patron link is kept' );
570 my $anonymous_patron = $builder->build_object({ class => 'Koha::Patrons' });
571 t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id );
572 # We need anonymous patron set to change patron privacy to never
573 # (2 == delete immediately)
574 # then we can undef for further tests
575 $patron->privacy(2)->store;
576 t::lib::Mocks::mock_preference( 'AnonymousPatron', undef );
577 $hold = $builder->build_object(
579 class => 'Koha::Holds',
580 value => { borrowernumber => $patron->id, found => undef }
586 'AnonymousPatron not set, exception thrown';
588 $hold->discard_changes;
590 ok( !$hold->is_found, 'Hold is not cancelled' );
592 t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id );
594 $hold = $builder->build_object(
596 class => 'Koha::Holds',
597 value => { borrowernumber => $patron->id, found => undef }
602 Koha::Old::Holds->find( $hold->id )->borrowernumber,
603 $anonymous_patron->id,
604 'Patron link is set to the configured anonymous patron immediately'
607 subtest 'holds_queue update tests' => sub {
611 my $biblio = $builder->build_sample_biblio;
613 t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 );
615 my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue');
616 $mock->mock( 'enqueue', sub {
617 my ( $self, $args ) = @_;
621 '->cancel triggers a holds queue update for the related biblio'
625 $builder->build_object(
627 class => 'Koha::Holds',
629 biblionumber => $biblio->id,
634 # If the skip_holds_queue param is not honoured, then test count will fail.
635 $builder->build_object(
637 class => 'Koha::Holds',
639 biblionumber => $biblio->id,
642 )->cancel({ skip_holds_queue => 1 });
644 t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 );
646 $builder->build_object(
648 class => 'Koha::Holds',
650 biblionumber => $biblio->id,
653 )->cancel({ skip_holds_queue => 0 });
656 $schema->storage->txn_rollback;
659 subtest 'suspend_hold() and resume() tests' => sub {
663 $schema->storage->txn_begin;
665 my $biblio = $builder->build_sample_biblio;
668 t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 );
670 my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue');
671 $mock->mock( 'enqueue', sub {
672 my ( $self, $args ) = @_;
676 "->$action triggers a holds queue update for the related biblio"
680 my $hold = $builder->build_object(
682 class => 'Koha::Holds',
684 biblionumber => $biblio->id,
690 $action = 'suspend_hold';
696 $schema->storage->txn_rollback;
699 subtest 'cancellation_requests() and add_cancellation_request() tests' => sub {
703 $schema->storage->txn_begin;
705 t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 );
707 my $hold = $builder->build_object( { class => 'Koha::Holds', } );
709 is( $hold->cancellation_requests->count, 0 );
711 # Add two cancellation requests
712 my $request_1 = $hold->add_cancellation_request;
713 isnt( $request_1->creation_date, undef, 'creation_date is set' );
715 my $requester = $builder->build_object( { class => 'Koha::Patrons' } );
716 my $creation_date = '2021-06-25 14:05:35';
718 my $request_2 = $hold->add_cancellation_request(
720 creation_date => $creation_date,
724 is( $request_2->creation_date, $creation_date, 'Passed creation_date set' );
726 is( $hold->cancellation_requests->count, 2 );
728 $schema->storage->txn_rollback;
731 subtest 'cancellation_requestable_from_opac() tests' => sub {
735 $schema->storage->txn_begin;
738 $builder->build_object( { class => 'Koha::Patron::Categories' } );
739 my $item_home_library =
740 $builder->build_object( { class => 'Koha::Libraries' } );
741 my $patron_home_library =
742 $builder->build_object( { class => 'Koha::Libraries' } );
745 $builder->build_sample_item( { library => $item_home_library->id } );
746 my $patron = $builder->build_object(
748 class => 'Koha::Patrons',
749 value => { branchcode => $patron_home_library->id }
753 subtest 'Exception cases' => sub {
757 my $hold = $builder->build_object(
759 class => 'Koha::Holds',
763 borrowernumber => $patron->id
768 throws_ok { $hold->cancellation_requestable_from_opac; }
769 'Koha::Exceptions::InvalidStatus',
770 'Exception thrown because hold is not waiting';
772 is( $@->invalid_status, 'hold_not_waiting' );
774 $hold = $builder->build_object(
776 class => 'Koha::Holds',
780 borrowernumber => $patron->id
785 throws_ok { $hold->cancellation_requestable_from_opac; }
786 'Koha::Exceptions::InvalidStatus',
787 'Exception thrown because waiting hold has no item linked';
789 is( $@->invalid_status, 'no_item_linked' );
792 # set default rule to enabled
793 Koha::CirculationRules->set_rule(
798 rule_name => 'waiting_hold_cancellation',
803 my $hold = $builder->build_object(
805 class => 'Koha::Holds',
807 itemnumber => $item->id,
809 borrowernumber => $patron->id
814 t::lib::Mocks::mock_preference( 'ReservesControlBranch',
817 Koha::CirculationRules->set_rule(
819 categorycode => $patron->categorycode,
820 itemtype => $item->itype,
821 branchcode => $item->homebranch,
822 rule_name => 'waiting_hold_cancellation',
827 ok( !$hold->cancellation_requestable_from_opac );
829 Koha::CirculationRules->set_rule(
831 categorycode => $patron->categorycode,
832 itemtype => $item->itype,
833 branchcode => $item->homebranch,
834 rule_name => 'waiting_hold_cancellation',
840 $hold->cancellation_requestable_from_opac,
841 'Make sure it is picking the right circulation rule'
844 t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
846 Koha::CirculationRules->set_rule(
848 categorycode => $patron->categorycode,
849 itemtype => $item->itype,
850 branchcode => $patron->branchcode,
851 rule_name => 'waiting_hold_cancellation',
856 ok( !$hold->cancellation_requestable_from_opac );
858 Koha::CirculationRules->set_rule(
860 categorycode => $patron->categorycode,
861 itemtype => $item->itype,
862 branchcode => $patron->branchcode,
863 rule_name => 'waiting_hold_cancellation',
869 $hold->cancellation_requestable_from_opac,
870 'Make sure it is picking the right circulation rule'
873 $schema->storage->txn_rollback;
876 subtest 'can_update_pickup_location_opac() tests' => sub {
880 $schema->storage->txn_begin;
882 my $hold = $builder->build_object(
883 { class => 'Koha::Holds',
884 value => { found => undef, suspend => 0, suspend_until => undef, waitingdate => undef }
888 t::lib::Mocks::mock_preference( 'OPACAllowUserToChangeBranch', '' );
890 is( $hold->can_update_pickup_location_opac, 0, "Pending hold pickup can't be changed (No change allowed)" );
893 is( $hold->can_update_pickup_location_opac, 0, "In transit hold pickup can't be changed (No change allowed)" );
896 is( $hold->can_update_pickup_location_opac, 0, "Waiting hold pickup can't be changed (No change allowed)" );
899 my $dt = dt_from_string();
901 $hold->suspend_hold( $dt );
902 is( $hold->can_update_pickup_location_opac, 0, "Suspended hold pickup can't be changed (No change allowed)" );
905 t::lib::Mocks::mock_preference( 'OPACAllowUserToChangeBranch', 'pending,intransit,suspended' );
907 is( $hold->can_update_pickup_location_opac, 1, "Pending hold pickup can be changed (pending,intransit,suspended allowed)" );
910 is( $hold->can_update_pickup_location_opac, 1, "In transit hold pickup can be changed (pending,intransit,suspended allowed)" );
913 is( $hold->can_update_pickup_location_opac, 0, "Waiting hold pickup can't be changed (pending,intransit,suspended allowed)" );
916 $dt = dt_from_string();
917 $hold->suspend_hold( $dt );
918 is( $hold->can_update_pickup_location_opac, 1, "Suspended hold pickup can be changed (pending,intransit,suspended allowed)" );
920 $schema->storage->txn_rollback;
923 subtest 'Koha::Hold::item_group tests' => sub {
927 $schema->storage->txn_begin;
929 my $library = $builder->build_object( { class => 'Koha::Libraries' } );
930 my $category = $builder->build_object(
932 class => 'Koha::Patron::Categories',
933 value => { exclude_from_local_holds_priority => 0 }
936 my $patron = $builder->build_object(
938 class => "Koha::Patrons",
940 branchcode => $library->branchcode,
941 categorycode => $category->categorycode
945 my $biblio = $builder->build_sample_biblio();
948 Koha::Biblio::ItemGroup->new( { biblio_id => $biblio->id } )->store();
950 my $hold = $builder->build_object(
952 class => "Koha::Holds",
954 borrowernumber => $patron->borrowernumber,
955 biblionumber => $biblio->biblionumber,
957 item_group_id => $item_group->id,
962 is( $hold->item_group->id, $item_group->id, "Got correct item group" );
964 $schema->storage->txn_rollback;