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 Test::More tests => 33;
24 use C4::Biblio qw( AddBiblio ModBiblio ModBiblioMarc );
25 use C4::Circulation qw( AddIssue AddReturn );
28 use Koha::DateUtils qw( dt_from_string );
29 use Koha::Cache::Memory::Lite;
31 use Koha::Acquisition::Orders;
32 use Koha::AuthorisedValueCategories;
33 use Koha::AuthorisedValues;
34 use Koha::MarcSubfieldStructures;
40 use t::lib::TestBuilder;
45 use_ok('Koha::Biblio');
46 use_ok('Koha::Biblios');
49 my $schema = Koha::Database->new->schema;
50 my $builder = t::lib::TestBuilder->new;
52 subtest 'metadata() tests' => sub {
56 $schema->storage->txn_begin;
58 my $title = 'Oranges and Peaches';
60 my $record = MARC::Record->new();
61 my $field = MARC::Field->new('245','','','a' => $title);
62 $record->append_fields( $field );
63 my ($biblionumber) = C4::Biblio::AddBiblio($record, '');
65 my $biblio = Koha::Biblios->find( $biblionumber );
66 is( ref $biblio, 'Koha::Biblio', 'Found a Koha::Biblio object' );
68 my $metadata = $biblio->metadata;
69 is( ref $metadata, 'Koha::Biblio::Metadata', 'Method metadata() returned a Koha::Biblio::Metadata object' );
71 my $record2 = $metadata->record;
72 is( ref $record2, 'MARC::Record', 'Method record() returned a MARC::Record object' );
74 is( $record2->field('245')->subfield("a"), $title, 'Title in 245$a matches title from original record object' );
76 $schema->storage->txn_rollback;
79 subtest 'hidden_in_opac() tests' => sub {
83 $schema->storage->txn_begin;
85 my $biblio = $builder->build_sample_biblio();
86 my $rules = { withdrawn => [ 2 ] };
88 t::lib::Mocks::mock_preference( 'OpacHiddenItemsHidesRecord', 0 );
91 !$biblio->hidden_in_opac({ rules => $rules }),
92 'Biblio not hidden if there is no item attached (!OpacHiddenItemsHidesRecord)'
95 t::lib::Mocks::mock_preference( 'OpacHiddenItemsHidesRecord', 1 );
98 !$biblio->hidden_in_opac({ rules => $rules }),
99 'Biblio not hidden if there is no item attached (OpacHiddenItemsHidesRecord)'
102 my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
103 my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
105 $item_1->withdrawn( 1 )->store->discard_changes;
106 $item_2->withdrawn( 1 )->store->discard_changes;
108 ok( !$biblio->hidden_in_opac({ rules => $rules }), 'Biblio not hidden' );
110 $item_2->withdrawn( 2 )->store->discard_changes;
111 $biblio->discard_changes; # refresh
113 ok( !$biblio->hidden_in_opac({ rules => $rules }), 'Biblio not hidden' );
115 $item_1->withdrawn( 2 )->store->discard_changes;
116 $biblio->discard_changes; # refresh
118 ok( $biblio->hidden_in_opac({ rules => $rules }), 'Biblio hidden' );
120 t::lib::Mocks::mock_preference( 'OpacHiddenItemsHidesRecord', 0 );
122 !$biblio->hidden_in_opac( { rules => $rules } ),
123 'Biblio hidden (!OpacHiddenItemsHidesRecord)'
127 $schema->storage->txn_rollback;
130 subtest 'items() tests' => sub {
134 $schema->storage->txn_begin;
136 my $biblio = $builder->build_sample_biblio();
138 is( $biblio->items->count, 0, 'No items, count is 0' );
140 my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
141 my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
143 my $items = $biblio->items;
144 is( ref($items), 'Koha::Items', 'Returns a Koha::Items resultset' );
145 is( $items->count, 2, 'Two items in resultset' );
147 $schema->storage->txn_rollback;
151 subtest 'bookable_items() tests' => sub {
154 $schema->storage->txn_begin;
156 my $biblio = $builder->build_sample_biblio();
159 my $bookable_item1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, bookable => 1 } );
162 my $non_bookable_item1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, bookable => 0 } );
163 my $non_bookable_item2 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, bookable => 0 } );
165 is( ref( $biblio->bookable_items ), 'Koha::Items', "bookable_items returns a Koha::Items resultset" );
166 is( $biblio->bookable_items->count, 1, "bookable_items returns the correct number of items" );
168 $biblio->bookable_items->next->itemnumber, $bookable_item1->itemnumber,
169 "bookable_items returned the correct item"
172 $schema->storage->txn_rollback;
175 subtest 'get_coins and get_openurl' => sub {
179 $schema->storage->txn_begin;
181 my $builder = t::lib::TestBuilder->new;
182 my $biblio = $builder->build_sample_biblio({
188 'ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=book&rft.btitle=Title%201&rft.au=Author%201',
189 'GetCOinsBiblio returned right metadata'
192 my $record = MARC::Record->new();
193 $record->append_fields( MARC::Field->new('100','','','a' => 'Author 2'), MARC::Field->new('880','','','a' => 'Something') );
194 my ( $biblionumber ) = C4::Biblio::AddBiblio($record, '');
195 my $biblio_no_title = Koha::Biblios->find($biblionumber);
197 $biblio_no_title->get_coins,
198 'ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=book&rft.au=Author%202',
199 'GetCOinsBiblio returned right metadata if biblio does not have a title'
202 t::lib::Mocks::mock_preference("OpenURLResolverURL", "https://koha.example.com/");
204 $biblio->get_openurl,
205 'https://koha.example.com/?ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=book&rft.btitle=Title%201&rft.au=Author%201',
206 'Koha::Biblio->get_openurl returned right URL'
209 t::lib::Mocks::mock_preference("OpenURLResolverURL", "https://koha.example.com/?client_id=ci1");
211 $biblio->get_openurl,
212 'https://koha.example.com/?client_id=ci1&ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=book&rft.btitle=Title%201&rft.au=Author%201',
213 'Koha::Biblio->get_openurl returned right URL'
216 $schema->storage->txn_rollback;
219 subtest 'is_serial() tests' => sub {
223 $schema->storage->txn_begin;
225 my $biblio = $builder->build_sample_biblio();
227 $biblio->serial( 1 )->store->discard_changes;
228 ok( $biblio->is_serial, 'Bibliographic record is serial' );
230 $biblio->serial( 0 )->store->discard_changes;
231 ok( !$biblio->is_serial, 'Bibliographic record is not serial' );
233 my $record = $biblio->metadata->record;
234 $record->leader('00142nas a22 7a 4500');
235 ModBiblio($record, $biblio->biblionumber );
236 $biblio = Koha::Biblios->find($biblio->biblionumber);
238 ok( $biblio->is_serial, 'Bibliographic record is serial' );
240 $schema->storage->txn_rollback;
243 subtest 'pickup_locations() tests' => sub {
247 $schema->storage->txn_begin;
249 Koha::CirculationRules->search->delete;
250 Koha::CirculationRules->set_rules(
252 categorycode => undef,
256 reservesallowed => 25,
261 my $root1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
262 my $root2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
263 my $root3 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
265 my $library1 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, branchname => 'zzz' } } );
266 my $library2 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, branchname => 'AAA' } } );
267 my $library3 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 0, branchname => 'FFF' } } );
268 my $library4 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, branchname => 'CCC' } } );
269 my $library5 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, branchname => 'eee' } } );
270 my $library6 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, branchname => 'BBB' } } );
271 my $library7 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, branchname => 'DDD' } } );
272 my $library8 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 0, branchname => 'GGG' } } );
274 our @branchcodes = map { $_->branchcode } ($library1, $library2, $library3, $library4, $library5, $library6, $library7, $library8);
276 Koha::CirculationRules->set_rules(
278 branchcode => $library1->branchcode,
281 holdallowed => 'from_home_library',
282 hold_fulfillment_policy => 'any',
283 returnbranch => 'any'
288 Koha::CirculationRules->set_rules(
290 branchcode => $library2->branchcode,
293 holdallowed => 'from_local_hold_group',
294 hold_fulfillment_policy => 'holdgroup',
295 returnbranch => 'any'
300 Koha::CirculationRules->set_rules(
302 branchcode => $library3->branchcode,
305 holdallowed => 'from_local_hold_group',
306 hold_fulfillment_policy => 'patrongroup',
307 returnbranch => 'any'
312 Koha::CirculationRules->set_rules(
314 branchcode => $library4->branchcode,
317 holdallowed => 'from_any_library',
318 hold_fulfillment_policy => 'holdingbranch',
319 returnbranch => 'any'
324 Koha::CirculationRules->set_rules(
326 branchcode => $library5->branchcode,
329 holdallowed => 'from_any_library',
330 hold_fulfillment_policy => 'homebranch',
331 returnbranch => 'any'
336 Koha::CirculationRules->set_rules(
338 branchcode => $library6->branchcode,
341 holdallowed => 'from_home_library',
342 hold_fulfillment_policy => 'holdgroup',
343 returnbranch => 'any'
348 Koha::CirculationRules->set_rules(
350 branchcode => $library7->branchcode,
353 holdallowed => 'from_local_hold_group',
354 hold_fulfillment_policy => 'holdingbranch',
355 returnbranch => 'any'
361 Koha::CirculationRules->set_rules(
363 branchcode => $library8->branchcode,
366 holdallowed => 'from_any_library',
367 hold_fulfillment_policy => 'patrongroup',
368 returnbranch => 'any'
373 my $group1_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library1->branchcode } } );
374 my $group1_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library2->branchcode } } );
376 my $group2_3 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } );
377 my $group2_4 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } );
379 my $group3_5 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library5->branchcode } } );
380 my $group3_6 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library6->branchcode } } );
381 my $group3_7 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library7->branchcode } } );
382 my $group3_8 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library8->branchcode } } );
384 my $biblio1 = $builder->build_sample_biblio({ title => '1' });
385 my $biblio2 = $builder->build_sample_biblio({ title => '2' });
388 { $biblio1->pickup_locations }
389 'Koha::Exceptions::MissingParameter',
390 'Exception thrown on missing parameter';
392 is( $@->parameter, 'patron', 'Exception param correctly set' );
394 my $item1_1 = $builder->build_sample_item({
395 biblionumber => $biblio1->biblionumber,
396 homebranch => $library1->branchcode,
397 holdingbranch => $library2->branchcode,
400 my $item1_3 = $builder->build_sample_item({
401 biblionumber => $biblio1->biblionumber,
402 homebranch => $library3->branchcode,
403 holdingbranch => $library4->branchcode,
406 my $item1_7 = $builder->build_sample_item({
407 biblionumber => $biblio1->biblionumber,
408 homebranch => $library7->branchcode,
409 holdingbranch => $library4->branchcode,
412 my $item2_2 = $builder->build_sample_item({
413 biblionumber => $biblio2->biblionumber,
414 homebranch => $library2->branchcode,
415 holdingbranch => $library1->branchcode,
418 my $item2_4 = $builder->build_sample_item({
419 biblionumber => $biblio2->biblionumber,
420 homebranch => $library4->branchcode,
421 holdingbranch => $library3->branchcode,
424 my $item2_6 = $builder->build_sample_item({
425 biblionumber => $biblio2->biblionumber,
426 homebranch => $library6->branchcode,
427 holdingbranch => $library4->branchcode,
430 my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { firstname=>'1', branchcode => $library1->branchcode } } );
431 my $patron8 = $builder->build_object( { class => 'Koha::Patrons', value => { firstname=>'8', branchcode => $library8->branchcode } } );
434 "ItemHomeLibrary-1-1" => 6,
435 "ItemHomeLibrary-1-8" => 1,
436 "ItemHomeLibrary-2-1" => 2,
437 "ItemHomeLibrary-2-8" => 0,
438 "PatronLibrary-1-1" => 6,
439 "PatronLibrary-1-8" => 3,
440 "PatronLibrary-2-1" => 0,
441 "PatronLibrary-2-8" => 3,
445 my ( $cbranch, $biblio, $patron, $results ) = @_;
446 t::lib::Mocks::mock_preference('ReservesControlBranch', $cbranch);
449 my $pickup_location = $_;
450 grep { $pickup_location->branchcode eq $_ } @branchcodes
451 } $biblio->pickup_locations( { patron => $patron } )->as_list;
454 scalar(@pl) == $results->{ $cbranch . '-'
455 . $biblio->title . '-'
456 . $patron->firstname },
457 'ReservesControlBranch: '
464 . $results->{ $cbranch . '-'
465 . $biblio->title . '-'
466 . $patron->firstname }
472 foreach my $cbranch ('ItemHomeLibrary','PatronLibrary') {
473 my $cache = Koha::Cache::Memory::Lite->get_instance();
474 $cache->flush(); # needed since we change ReservesControlBranch
475 foreach my $biblio ($biblio1, $biblio2) {
476 foreach my $patron ($patron1, $patron8) {
477 _doTest($cbranch, $biblio, $patron, $results);
482 my @pl_names = map { $_->branchname } $biblio1->pickup_locations( { patron => $patron1 } )->as_list;
483 my $pl_ori_str = join('|', @pl_names);
484 my $pl_sorted_str = join('|', sort { lc($a) cmp lc($b) } @pl_names);
486 $pl_ori_str eq $pl_sorted_str,
487 'Libraries must be sorted by name'
489 $schema->storage->txn_rollback;
492 subtest 'to_api() tests' => sub {
494 $schema->storage->txn_begin;
496 my $biblio = $builder->build_sample_biblio();
497 my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
499 my $biblioitem_api = $biblio->biblioitem->to_api;
500 my $biblio_api = $biblio->to_api;
502 plan tests => (scalar keys %{ $biblioitem_api }) + 1;
504 foreach my $key ( keys %{ $biblioitem_api } ) {
505 is( $biblio_api->{$key}, $biblioitem_api->{$key}, "$key is added to the biblio object" );
508 $biblio_api = $biblio->to_api({ embed => { items => {} } });
509 is_deeply( $biblio_api->{items}, [ $item->to_api ], 'Item correctly embedded' );
511 $schema->storage->txn_rollback;
514 subtest 'bookings() tests' => sub {
518 $schema->storage->txn_begin;
520 my $biblio = $builder->build_sample_biblio();
522 is( ref( $biblio->bookings ), 'Koha::Bookings', 'Return type is correct' );
525 $biblio->bookings->unblessed,
527 '->bookings returns an empty Koha::Bookings resultset'
530 my $booking = $builder->build_object(
532 class => 'Koha::Bookings',
533 value => { biblio_id => $biblio->biblionumber }
537 my $bookings = $biblio->bookings->unblessed;
540 $biblio->bookings->unblessed,
541 [ $booking->unblessed ],
542 '->bookings returns the related Koha::Booking objects'
545 $schema->storage->txn_rollback;
548 subtest 'suggestions() tests' => sub {
552 $schema->storage->txn_begin;
554 my $biblio = $builder->build_sample_biblio();
556 is( ref($biblio->suggestions), 'Koha::Suggestions', 'Return type is correct' );
559 $biblio->suggestions->unblessed,
561 '->suggestions returns an empty Koha::Suggestions resultset'
564 my $suggestion = $builder->build_object(
566 class => 'Koha::Suggestions',
567 value => { biblionumber => $biblio->biblionumber }
571 my $suggestions = $biblio->suggestions->unblessed;
574 $biblio->suggestions->unblessed,
575 [ $suggestion->unblessed ],
576 '->suggestions returns the related Koha::Suggestion objects'
579 $schema->storage->txn_rollback;
582 subtest 'get_marc_components() tests' => sub {
586 $schema->storage->txn_begin;
588 my ($host_bibnum) = C4::Biblio::AddBiblio(host_record(), '');
589 my $host_biblio = Koha::Biblios->find($host_bibnum);
590 t::lib::Mocks::mock_preference( 'SearchEngine', 'Zebra' );
591 my $search_mod = Test::MockModule->new( 'Koha::SearchEngine::Zebra::Search' );
592 $search_mod->mock( 'search_compat', \&search_component_record2 );
594 my $components = $host_biblio->get_marc_components;
595 is( ref($components), 'ARRAY', 'Return type is correct' );
600 '->get_marc_components returns an empty ARRAY'
603 $search_mod->unmock( 'search_compat');
604 $search_mod->mock( 'search_compat', \&search_component_record1 );
605 my $component_record = component_record1()->as_xml();
608 $host_biblio->get_marc_components,
610 '->get_marc_components returns the related component part record'
612 $search_mod->unmock( 'search_compat');
614 $search_mod->mock( 'search_compat',
615 sub { Koha::Exception->throw("error searching analytics") }
617 warning_like { $components = $host_biblio->get_marc_components }
618 qr{Warning from search_compat: .* 'error searching analytics'};
621 $host_biblio->object_messages,
625 message => 'component_search',
626 payload => "Exception 'Koha::Exception' thrown 'error searching analytics'\n"
630 $search_mod->unmock( 'search_compat');
632 $schema->storage->txn_rollback;
635 subtest 'get_components_query' => sub {
638 my $biblio = $builder->build_sample_biblio();
639 my $biblionumber = $biblio->biblionumber;
640 my $record = $biblio->metadata->record;
642 foreach my $engine ('Zebra','Elasticsearch'){
643 t::lib::Mocks::mock_preference( 'SearchEngine', $engine );
645 t::lib::Mocks::mock_preference( 'UseControlNumber', '0' );
646 t::lib::Mocks::mock_preference( 'ComponentSortField', 'author' );
647 t::lib::Mocks::mock_preference( 'ComponentSortOrder', 'za' );
648 my ( $comp_query, $comp_query_str, $comp_sort ) = $biblio->get_components_query;
649 is($comp_query_str, 'Host-item:("Some boring read")', "$engine: UseControlNumber disabled");
650 is($comp_sort, "author_za", "$engine: UseControlNumber disabled sort is correct");
652 t::lib::Mocks::mock_preference( 'UseControlNumber', '1' );
653 t::lib::Mocks::mock_preference( 'ComponentSortOrder', 'az' );
654 my $marc_001_field = MARC::Field->new('001', $biblionumber);
655 $record->append_fields($marc_001_field);
656 C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
657 $biblio = Koha::Biblios->find( $biblio->biblionumber);
659 ( $comp_query, $comp_query_str, $comp_sort ) = $biblio->get_components_query;
660 is($comp_query_str, "(rcn:\"$biblionumber\" AND (bib-level:a OR bib-level:b))", "$engine: UseControlNumber enabled without MarcOrgCode");
661 is($comp_sort, "author_az", "$engine: UseControlNumber enabled without MarcOrgCode sort is correct");
663 my $marc_003_field = MARC::Field->new('003', 'OSt');
664 $record->append_fields($marc_003_field);
665 C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
666 $biblio = Koha::Biblios->find( $biblio->biblionumber);
668 t::lib::Mocks::mock_preference( 'ComponentSortField', 'title' );
669 t::lib::Mocks::mock_preference( 'ComponentSortOrder', 'asc' );
670 ( $comp_query, $comp_query_str, $comp_sort ) = $biblio->get_components_query;
671 is($comp_query_str, "(((rcn:\"$biblionumber\" AND cni:\"OSt\") OR rcn:\"OSt $biblionumber\") AND (bib-level:a OR bib-level:b))", "$engine: UseControlNumber enabled with MarcOrgCode");
672 is($comp_sort, "title_asc", "$engine: UseControlNumber enabled with MarcOrgCode sort if correct");
673 $record->delete_field($marc_003_field);
677 subtest 'get_volumes_query' => sub {
680 my $biblio = $builder->build_sample_biblio();
681 my $biblionumber = $biblio->biblionumber;
682 my $record = $biblio->metadata->record;
684 # Ensure our mocked record is captured as a set or monographic series
685 my $ldr = $record->leader();
686 substr( $ldr, 19, 1 ) = 'a';
687 $record->leader($ldr);
688 C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
689 $biblio = Koha::Biblios->find( $biblio->biblionumber );
691 t::lib::Mocks::mock_preference( 'UseControlNumber', '0' );
693 $biblio->get_volumes_query,
694 "(title-series,phr:(\"Some boring read\") OR Host-item,phr:(\"Some boring read\") NOT (bib-level:a OR bib-level:b))",
695 "UseControlNumber disabled"
698 t::lib::Mocks::mock_preference( 'UseControlNumber', '1' );
699 my $marc_001_field = MARC::Field->new( '001', $biblionumber );
700 $record->append_fields($marc_001_field);
701 C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
702 $biblio = Koha::Biblios->find( $biblio->biblionumber );
706 $biblio->get_volumes_query, "(rcn:$biblionumber NOT (bib-level:a OR bib-level:b))",
707 "UseControlNumber enabled without MarcOrgCode"
710 my $marc_003_field = MARC::Field->new( '003', 'OSt' );
711 $record->append_fields($marc_003_field);
712 C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
713 $biblio = Koha::Biblios->find( $biblio->biblionumber );
716 $biblio->get_volumes_query,
717 "(((rcn:$biblionumber AND cni:OSt) OR rcn:\"OSt $biblionumber\") NOT (bib-level:a OR bib-level:b))",
718 "UseControlNumber enabled with MarcOrgCode"
722 subtest 'orders() and active_orders() tests' => sub {
726 $schema->storage->txn_begin;
728 my $biblio = $builder->build_sample_biblio();
730 my $orders = $biblio->orders;
731 my $active_orders = $biblio->active_orders;
733 is( ref($orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
734 is( $biblio->orders->count, $biblio->active_orders->count, '->orders->count returns the count for the resultset' );
736 # Add a couple orders
738 $builder->build_object(
740 class => 'Koha::Acquisition::Orders',
742 biblionumber => $biblio->biblionumber,
743 datecancellationprinted => '2019-12-31'
749 $builder->build_object(
751 class => 'Koha::Acquisition::Orders',
753 biblionumber => $biblio->biblionumber,
754 datecancellationprinted => undef
759 $orders = $biblio->orders;
760 $active_orders = $biblio->active_orders;
762 is( ref($orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
763 is( ref($active_orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
764 is( $orders->count, $active_orders->count + 2, '->active_orders->count returns the rigt count' );
766 $schema->storage->txn_rollback;
769 subtest 'tickets() tests' => sub {
773 $schema->storage->txn_begin;
775 my $biblio = $builder->build_sample_biblio();
776 my $tickets = $biblio->tickets;
777 is( ref($tickets), 'Koha::Tickets', 'Koha::Biblio->tickets should return a Koha::Tickets object' );
778 is( $tickets->count, 0, 'Koha::Biblio->tickets should return a count of 0 when there are no related tickets' );
782 $builder->build_object(
784 class => 'Koha::Tickets',
785 value => { biblio_id => $biblio->biblionumber }
790 $tickets = $biblio->tickets;
791 is( ref($tickets), 'Koha::Tickets', 'Koha::Biblio->tickets should return a Koha::Tickets object' );
792 is( $tickets->count, 2, 'Koha::Biblio->tickets should return the correct number of tickets' );
794 $schema->storage->txn_rollback;
797 subtest 'subscriptions() tests' => sub {
801 $schema->storage->txn_begin;
803 my $biblio = $builder->build_sample_biblio;
805 my $subscriptions = $biblio->subscriptions;
806 is( ref($subscriptions), 'Koha::Subscriptions',
807 'Koha::Biblio->subscriptions should return a Koha::Subscriptions object'
809 is( $subscriptions->count, 0, 'Koha::Biblio->subscriptions should return the correct number of subscriptions');
811 # Add two subscriptions
813 $builder->build_object(
815 class => 'Koha::Subscriptions',
816 value => { biblionumber => $biblio->biblionumber }
821 $subscriptions = $biblio->subscriptions;
822 is( ref($subscriptions), 'Koha::Subscriptions',
823 'Koha::Biblio->subscriptions should return a Koha::Subscriptions object'
825 is( $subscriptions->count, 2, 'Koha::Biblio->subscriptions should return the correct number of subscriptions');
827 $schema->storage->txn_rollback;
830 subtest 'get_marc_notes() MARC21 tests' => sub {
833 $schema->storage->txn_begin;
835 t::lib::Mocks::mock_preference( 'NotesToHide', '520' );
837 my $av = $builder->build_object( { class => 'Koha::AuthorisedValues' } );
839 my $biblio = $builder->build_sample_biblio;
840 my $record = $biblio->metadata->record;
841 $record->append_fields(
842 MARC::Field->new( '500', '', '', a => 'Note1' ),
843 MARC::Field->new( '505', '', '', a => 'Note2', u => 'http://someserver.com' ),
844 MARC::Field->new( '520', '', '', a => 'Note3 skipped' ),
845 MARC::Field->new( '541', '0', '', a => 'Note4 skipped on opac' ),
846 MARC::Field->new( '544', '', '', a => 'Note5' ),
847 MARC::Field->new( '590', '', '', a => $av->authorised_value ),
848 MARC::Field->new( '545', '', '', a => 'Invisible on OPAC' ),
851 my $mss = Koha::MarcSubfieldStructures->find({tagfield => "590", tagsubfield => "a", frameworkcode => $biblio->frameworkcode });
852 $mss->update({ authorised_value => $av->category });
854 $mss = Koha::MarcSubfieldStructures->find({tagfield => "545", tagsubfield => "a", frameworkcode => $biblio->frameworkcode });
855 $mss->update({ hidden => 1 });
857 my $cache = Koha::Caches->get_instance;
858 $cache->clear_from_cache("MarcStructure-0-");
859 $cache->clear_from_cache("MarcStructure-1-");
860 $cache->clear_from_cache("MarcSubfieldStructure-");
861 $cache->clear_from_cache("MarcCodedFields-");
863 C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
864 $biblio = Koha::Biblios->find( $biblio->biblionumber);
866 my $notes = $biblio->get_marc_notes;
867 is( $notes->[0]->{marcnote}, 'Note1', 'First note' );
868 is( $notes->[1]->{marcnote}, 'Note2', 'Second note' );
869 is( $notes->[2]->{marcnote}, 'http://someserver.com', 'URL separated' );
870 is( $notes->[3]->{marcnote}, 'Note4 skipped on opac',"Note shows if not opac (Hidden by Indicator)" );
871 is( $notes->[4]->{marcnote}, 'Note5', 'Fifth note' );
872 is( $notes->[5]->{marcnote}, $av->lib, 'Authorised value is correctly parsed to show description rather than code' );
873 is( $notes->[6]->{marcnote}, 'Invisible on OPAC', 'Note shows if not opac (Hidden by framework)' );
874 is( @$notes, 7, 'No more notes' );
875 $notes = $biblio->get_marc_notes({ opac => 1 });
876 is( $notes->[0]->{marcnote}, 'Note1', 'First note' );
877 is( $notes->[1]->{marcnote}, 'Note2', 'Second note' );
878 is( $notes->[2]->{marcnote}, 'http://someserver.com', 'URL separated' );
879 is( $notes->[3]->{marcnote}, 'Note5', 'Fifth note shows after fourth skipped' );
880 is( $notes->[4]->{marcnote}, $av->lib_opac, 'Authorised value is correctly parsed for OPAC to show description rather than code' );
881 is( @$notes, 5, 'No more notes' );
883 $cache->clear_from_cache("MarcStructure-0-");
884 $cache->clear_from_cache("MarcStructure-1-");
885 $cache->clear_from_cache("MarcSubfieldStructure-");
886 $cache->clear_from_cache("MarcCodedFields-");
888 $schema->storage->txn_rollback;
891 subtest 'get_marc_notes() UNIMARC tests' => sub {
894 $schema->storage->txn_begin;
896 t::lib::Mocks::mock_preference( 'NotesToHide', '310' );
897 t::lib::Mocks::mock_preference( 'marcflavour', 'UNIMARC' );
899 my $biblio = $builder->build_sample_biblio;
900 my $record = $biblio->metadata->record;
901 $record->append_fields(
902 MARC::Field->new( '300', '', '', a => 'Note1' ),
903 MARC::Field->new( '300', '', '', a => 'Note2' ),
904 MARC::Field->new( '310', '', '', a => 'Note3 skipped' ),
906 C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
907 $biblio = Koha::Biblios->find( $biblio->biblionumber);
908 my $notes = $biblio->get_marc_notes({ marcflavour => 'UNIMARC' });
909 is( $notes->[0]->{marcnote}, 'Note1', 'First note' );
910 is( $notes->[1]->{marcnote}, 'Note2', 'Second note' );
911 is( @$notes, 2, 'No more notes' );
913 t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' );
914 $schema->storage->txn_rollback;
917 subtest 'host_items() tests' => sub {
920 $schema->storage->txn_begin;
922 my $biblio = $builder->build_sample_biblio( { frameworkcode => '' } );
924 t::lib::Mocks::mock_preference( 'EasyAnalyticalRecords', 1 );
925 my $host_items = $biblio->host_items;
926 is( ref($host_items), 'Koha::Items' );
927 is( $host_items->count, 0 );
930 $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
931 my $host_item_1 = $builder->build_sample_item;
932 my $host_item_2 = $builder->build_sample_item;
934 my $record = $biblio->metadata->record;
935 $record->append_fields(
938 9 => $host_item_1->itemnumber,
939 9 => $host_item_2->itemnumber
942 C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
943 $biblio = $biblio->get_from_storage;
944 $host_items = $biblio->host_items;
945 is( $host_items->count, 2 );
946 is_deeply( [ $host_items->get_column('itemnumber') ],
947 [ $host_item_1->itemnumber, $host_item_2->itemnumber ] );
949 t::lib::Mocks::mock_preference( 'EasyAnalyticalRecords', 0 );
950 $host_items = $biblio->host_items;
951 is( ref($host_items), 'Koha::Items' );
952 is( $host_items->count, 0 );
954 subtest 'test host_items param in items()' => sub {
957 my $items = $biblio->items;
958 is( $items->count, 1, "Without host_items param we only get the items on the biblio");
959 $items = $biblio->items({ host_items => 1 });
960 is( $items->count, 3, "With param host_items we get the biblio items plus analytics");
961 is( ref($items), 'Koha::Items', "We correctly get an Items object");
962 is_deeply( [ $items->get_column('itemnumber') ],
963 [ $item_1->itemnumber, $host_item_1->itemnumber, $host_item_2->itemnumber ] );
966 $schema->storage->txn_rollback;
969 subtest 'article_requests() tests' => sub {
973 $schema->storage->txn_begin;
975 my $item = $builder->build_sample_item;
976 my $biblio = $item->biblio;
978 my $article_requests = $biblio->article_requests;
979 is( ref($article_requests), 'Koha::ArticleRequests',
980 'In scalar context, type is correct' );
981 is( $article_requests->count, 0, 'No article requests' );
983 foreach my $i ( 0 .. 3 ) {
985 my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
987 Koha::ArticleRequest->new(
989 borrowernumber => $patron->id,
990 biblionumber => $biblio->id,
991 itemnumber => $item->id,
992 title => $biblio->title,
997 $article_requests = $biblio->article_requests;
998 is( $article_requests->count, 4, '4 article requests' );
1000 $schema->storage->txn_rollback;
1003 subtest 'current_checkouts() and old_checkouts() tests' => sub {
1007 $schema->storage->txn_begin;
1009 my $library = $builder->build_object({ class => 'Koha::Libraries' });
1011 my $patron_1 = $builder->build_object({ class => 'Koha::Patrons' });
1012 my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' });
1014 my $item_1 = $builder->build_sample_item;
1015 my $item_2 = $builder->build_sample_item({ biblionumber => $item_1->biblionumber });
1017 t::lib::Mocks::mock_userenv({ branchcode => $library->id });
1019 AddIssue( $patron_1, $item_1->barcode );
1020 AddIssue( $patron_1, $item_2->barcode );
1022 AddReturn( $item_1->barcode );
1023 AddIssue( $patron_2, $item_1->barcode );
1025 my $biblio = $item_1->biblio;
1026 my $current_checkouts = $biblio->current_checkouts;
1027 my $old_checkouts = $biblio->old_checkouts;
1029 is( ref($current_checkouts), 'Koha::Checkouts', 'Type is correct' );
1030 is( ref($old_checkouts), 'Koha::Old::Checkouts', 'Type is correct' );
1032 is( $current_checkouts->count, 2, 'Count is correct for current checkouts' );
1033 is( $old_checkouts->count, 1, 'Count is correct for old checkouts' );
1035 $schema->storage->txn_rollback;
1038 subtest 'get_marc_contributors() tests' => sub {
1042 $schema->storage->txn_begin;
1044 my $biblio = $builder->build_sample_biblio({ author => 'Main author' });
1045 my $record = $biblio->metadata->record;
1047 # add author information
1048 my $field = MARC::Field->new('700','1','','a' => 'Jefferson, Thomas');
1049 $record->append_fields($field);
1050 $field = MARC::Field->new('701','1','','d' => 'Secondary author 2');
1051 $record->append_fields($field);
1054 C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
1055 $biblio = Koha::Biblios->find( $biblio->biblionumber );
1057 is( @{$biblio->get_marc_authors}, 3, 'get_marc_authors retrieves correct number of author subfields' );
1058 is( @{$biblio->get_marc_contributors}, 2, 'get_marc_contributors retrieves correct number of author subfields' );
1059 $schema->storage->txn_rollback;
1062 subtest 'Recalls tests' => sub {
1066 $schema->storage->txn_begin;
1068 my $item1 = $builder->build_sample_item;
1069 my $biblio = $item1->biblio;
1070 my $branchcode = $item1->holdingbranch;
1071 my $patron1 = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $branchcode } });
1072 my $patron2 = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $branchcode } });
1073 my $patron3 = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $branchcode } });
1074 my $item2 = $builder->build_object({ class => 'Koha::Items', value => { holdingbranch => $branchcode, homebranch => $branchcode, biblionumber => $biblio->biblionumber, itype => $item1->effective_itemtype } });
1075 t::lib::Mocks::mock_userenv({ patron => $patron1 });
1077 my $recall1 = Koha::Recall->new(
1078 { patron_id => $patron1->borrowernumber,
1079 created_date => \'NOW()',
1080 biblio_id => $biblio->biblionumber,
1081 pickup_library_id => $branchcode,
1082 item_id => $item1->itemnumber,
1083 expiration_date => undef,
1087 my $recall2 = Koha::Recall->new(
1088 { patron_id => $patron2->borrowernumber,
1089 created_date => \'NOW()',
1090 biblio_id => $biblio->biblionumber,
1091 pickup_library_id => $branchcode,
1093 expiration_date => undef,
1097 my $recall3 = Koha::Recall->new(
1098 { patron_id => $patron3->borrowernumber,
1099 created_date => \'NOW()',
1100 biblio_id => $biblio->biblionumber,
1101 pickup_library_id => $branchcode,
1102 item_id => $item1->itemnumber,
1103 expiration_date => undef,
1108 my $recalls = $biblio->recalls;
1109 is( $recalls->count, 3, 'Correctly get number of recalls for biblio' );
1111 $recall1->set_cancelled;
1112 $recall2->set_expired({ interface => 'COMMANDLINE' });
1114 is( $recalls->count, 3, 'Correctly get number of recalls for biblio' );
1115 is( $recalls->filter_by_current->count, 1, 'Correctly get number of active recalls for biblio' );
1117 t::lib::Mocks::mock_preference('UseRecalls', 0);
1118 is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall with UseRecalls disabled" );
1120 t::lib::Mocks::mock_preference("UseRecalls", 1);
1121 $item1->update({ notforloan => 1 });
1122 is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall with no available items" );
1124 $item1->update({ notforloan => 0 });
1125 Koha::CirculationRules->set_rules({
1126 branchcode => $branchcode,
1127 categorycode => $patron1->categorycode,
1128 itemtype => $item1->effective_itemtype,
1130 recalls_allowed => 0,
1131 recalls_per_record => 1,
1132 on_shelf_recalls => 'all',
1135 is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if recalls_allowed = 0" );
1137 Koha::CirculationRules->set_rules({
1138 branchcode => $branchcode,
1139 categorycode => $patron1->categorycode,
1140 itemtype => $item1->effective_itemtype,
1142 recalls_allowed => 1,
1143 recalls_per_record => 1,
1144 on_shelf_recalls => 'all',
1147 is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if patron has more existing recall(s) than recalls_allowed" );
1148 is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if patron has more existing recall(s) than recalls_per_record" );
1150 $recall1->set_cancelled;
1151 C4::Circulation::AddIssue( $patron1, $item2->barcode );
1152 is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if patron has already checked out an item attached to this biblio" );
1154 is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if on_shelf_recalls = all and items are still available" );
1156 Koha::CirculationRules->set_rules({
1157 branchcode => $branchcode,
1158 categorycode => $patron1->categorycode,
1159 itemtype => $item1->effective_itemtype,
1161 recalls_allowed => 1,
1162 recalls_per_record => 1,
1163 on_shelf_recalls => 'any',
1166 C4::Circulation::AddReturn( $item2->barcode, $branchcode );
1167 is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if no items are checked out" );
1169 $recall2->set_cancelled;
1170 C4::Circulation::AddIssue( $patron2, $item2->barcode );
1171 C4::Circulation::AddIssue( $patron2, $item1->barcode );
1172 is( $biblio->can_be_recalled({ patron => $patron1 }), 2, "Can recall two items" );
1174 $item1->update({ withdrawn => 1 });
1175 is( $biblio->can_be_recalled({ patron => $patron1 }), 1, "Can recall one item" );
1177 $schema->storage->txn_rollback;
1180 subtest 'ill_requests() tests' => sub {
1184 $schema->storage->txn_begin;
1186 my $biblio = $builder->build_sample_biblio;
1188 my $rs = $biblio->ill_requests;
1189 is( ref($rs), 'Koha::Illrequests' );
1190 is( $rs->count, 0, 'No linked requests' );
1193 $builder->build_object(
1195 class => 'Koha::Illrequests',
1196 value => { biblio_id => $biblio->id }
1201 is( $biblio->ill_requests->count, 10, 'Linked requests are present' );
1203 $schema->storage->txn_rollback;
1206 subtest 'item_groups() tests' => sub {
1210 $schema->storage->txn_begin;
1212 my $biblio = $builder->build_sample_biblio();
1214 my @item_groups = $biblio->item_groups->as_list;
1215 is( scalar(@item_groups), 0, 'Got zero item groups');
1217 my $item_group_1 = Koha::Biblio::ItemGroup->new( { biblio_id => $biblio->id } )->store();
1219 @item_groups = $biblio->item_groups->as_list;
1220 is( scalar(@item_groups), 1, 'Got one item group');
1221 is( $item_groups[0]->id, $item_group_1->id, 'Got correct item group');
1223 my $item_group_2 = Koha::Biblio::ItemGroup->new( { biblio_id => $biblio->id } )->store();
1225 @item_groups = $biblio->item_groups->as_list;
1226 is( scalar(@item_groups), 2, 'Got two item groups');
1227 is( $item_groups[0]->id, $item_group_1->id, 'Got correct item group 1');
1228 is( $item_groups[1]->id, $item_group_2->id, 'Got correct item group 2');
1230 $schema->storage->txn_rollback;
1233 subtest 'normalized_isbn' => sub {
1236 # We will move the tests from GetNormalizedISBN here when it will get replaced
1237 my $biblio = $builder->build_sample_biblio();
1238 $biblio->biblioitem->set( { isbn => '9781250067128 | 125006712X' } )->store;
1240 $biblio->normalized_isbn, C4::Koha::GetNormalizedISBN( $biblio->biblioitem->isbn ),
1241 'normalized_isbn is a wrapper around C4::Koha::GetNormalizedISBN'
1245 subtest 'normalized_upc' => sub {
1248 # We will move the tests from GetNormalizedUPC here when it will get replaced
1249 # Note that only a single test exist and it's not really meaningful...
1250 my $biblio = $builder->build_sample_biblio();
1252 $biblio->normalized_upc, C4::Koha::GetNormalizedUPC( $biblio->metadata->record ),
1253 'normalized_upc is a wrapper around C4::Koha::GetNormalizedUPC'
1257 subtest 'normalized_oclc' => sub {
1260 # We will move the tests from GetNormalizedOCLC here when it will get replaced
1261 # Note that only a single test exist and it's not really meaningful...
1262 my $biblio = $builder->build_sample_biblio();
1264 $biblio->normalized_oclc, C4::Koha::GetNormalizedOCLCNumber( $biblio->metadata->record ),
1265 'normalized_oclc is a wrapper around C4::Koha::GetNormalizedOCLCNumber'
1269 subtest 'ratings' => sub {
1271 # See t/db_dependent/Koha/Ratings.t
1275 subtest 'opac_summary_html' => sub {
1279 my $author = 'my author';
1280 my $title = 'my title';
1281 my $isbn = '9781250067128 | 125006712X';
1282 my $biblio = $builder->build_sample_biblio( { author => $author, title => $title } );
1283 $biblio->biblioitem->set( { isbn => '9781250067128 | 125006712X' } )->store;
1285 t::lib::Mocks::mock_preference( 'OPACMySummaryHTML', '' );
1286 is( $biblio->opac_summary_html, '', 'opac_summary_html returns empty string if pref is off' );
1288 t::lib::Mocks::mock_preference(
1289 'OPACMySummaryHTML',
1290 'Replace {AUTHOR}, {TITLE}, {ISBN} AND {BIBLIONUMBER} please'
1293 $biblio->opac_summary_html,
1294 sprintf( 'Replace %s, %s, %s AND %s please', $author, $title, $biblio->normalized_isbn, $biblio->biblionumber ),
1295 'opac_summary_html replaces the different patterns'
1299 sub component_record1 {
1300 my $marc = MARC::Record->new;
1301 $marc->append_fields(
1302 MARC::Field->new( '001', '3456' ),
1303 MARC::Field->new( '245', '', '', a => 'Some title 1' ),
1304 MARC::Field->new( '773', '', '', w => '(FIRST)1234' ),
1308 sub search_component_record1 {
1309 my @results = ( component_record1()->as_xml() );
1310 return ( undef, { biblioserver => { RECORDS => \@results, hits => 1 } }, 1 );
1313 sub search_component_record2 {
1315 return ( undef, { biblioserver => { RECORDS => \@results, hits => 0 } }, 0 );
1319 my $marc = MARC::Record->new;
1320 $marc->append_fields(
1321 MARC::Field->new( '001', '1234' ),
1322 MARC::Field->new( '003', 'FIRST' ),
1323 MARC::Field->new( '245', '', '', a => 'Some title' ),
1328 subtest 'check_booking tests' => sub {
1331 $schema->storage->txn_begin;
1333 my $biblio = $builder->build_sample_biblio();
1336 my $item = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, bookable => 1 } );
1340 my $can_book = $biblio->check_booking(
1342 start_date => dt_from_string(),
1343 end_date => dt_from_string()->add( days => 7 )
1349 "True returned from Koha::Biblio->check_booking if there are no bookings"
1352 my $start_1 = dt_from_string()->subtract( days => 7 );
1353 my $end_1 = dt_from_string()->subtract( days => 1 );
1354 my $start_2 = dt_from_string();
1355 my $end_2 = dt_from_string()->add( days => 7 );
1359 for my $item (@items) {
1361 my $booking = $builder->build_object(
1363 class => 'Koha::Bookings',
1365 biblio_id => $biblio->biblionumber,
1366 item_id => $item->itemnumber,
1367 start_date => $start_1,
1372 push @bookings, $booking;
1375 $can_book = $biblio->check_booking(
1377 start_date => dt_from_string(),
1378 end_date => dt_from_string()->add( days => 7 ),
1385 "Koha::Biblio->check_booking returns true when we all existing bookings are in the past"
1389 my @current_bookings;
1390 for my $item (@items) {
1391 my $booking = $builder->build_object(
1393 class => 'Koha::Bookings',
1395 biblio_id => $biblio->biblionumber,
1396 item_id => $item->itemnumber,
1397 start_date => $start_2,
1402 push @current_bookings, $booking;
1405 $can_book = $biblio->check_booking(
1407 start_date => dt_from_string(),
1408 end_date => dt_from_string()->add( days => 7 ),
1414 "Koha::Biblio->check_booking returns false if the booking would conflict with existing bookings"
1417 $can_book = $biblio->check_booking(
1419 start_date => dt_from_string(),
1420 end_date => dt_from_string()->add( days => 7 ),
1421 booking_id => $current_bookings[0]->booking_id
1427 "Koha::Biblio->check_booking returns true if we pass the booking_id of one of the bookings that we would conflict with"
1430 $schema->storage->txn_rollback;