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 => 16;
22 use C4::Biblio qw( AddBiblio ModBiblio );
25 use Koha::Acquisition::Orders;
26 use Koha::AuthorisedValueCategories;
27 use Koha::AuthorisedValues;
28 use Koha::MarcSubfieldStructures;
30 use t::lib::TestBuilder;
34 use_ok('Koha::Biblio');
35 use_ok('Koha::Biblios');
38 my $schema = Koha::Database->new->schema;
39 my $builder = t::lib::TestBuilder->new;
41 subtest 'metadata() tests' => sub {
45 $schema->storage->txn_begin;
47 my $title = 'Oranges and Peaches';
49 my $record = MARC::Record->new();
50 my $field = MARC::Field->new('245','','','a' => $title);
51 $record->append_fields( $field );
52 my ($biblionumber) = C4::Biblio::AddBiblio($record, '');
54 my $biblio = Koha::Biblios->find( $biblionumber );
55 is( ref $biblio, 'Koha::Biblio', 'Found a Koha::Biblio object' );
57 my $metadata = $biblio->metadata;
58 is( ref $metadata, 'Koha::Biblio::Metadata', 'Method metadata() returned a Koha::Biblio::Metadata object' );
60 my $record2 = $metadata->record;
61 is( ref $record2, 'MARC::Record', 'Method record() returned a MARC::Record object' );
63 is( $record2->field('245')->subfield("a"), $title, 'Title in 245$a matches title from original record object' );
65 $schema->storage->txn_rollback;
68 subtest 'hidden_in_opac() tests' => sub {
72 $schema->storage->txn_begin;
74 my $biblio = $builder->build_sample_biblio();
75 my $rules = { withdrawn => [ 2 ] };
77 t::lib::Mocks::mock_preference( 'OpacHiddenItemsHidesRecord', 0 );
80 !$biblio->hidden_in_opac({ rules => $rules }),
81 'Biblio not hidden if there is no item attached (!OpacHiddenItemsHidesRecord)'
84 t::lib::Mocks::mock_preference( 'OpacHiddenItemsHidesRecord', 1 );
87 !$biblio->hidden_in_opac({ rules => $rules }),
88 'Biblio not hidden if there is no item attached (OpacHiddenItemsHidesRecord)'
91 my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
92 my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
94 $item_1->withdrawn( 1 )->store->discard_changes;
95 $item_2->withdrawn( 1 )->store->discard_changes;
97 ok( !$biblio->hidden_in_opac({ rules => $rules }), 'Biblio not hidden' );
99 $item_2->withdrawn( 2 )->store->discard_changes;
100 $biblio->discard_changes; # refresh
102 ok( !$biblio->hidden_in_opac({ rules => $rules }), 'Biblio not hidden' );
104 $item_1->withdrawn( 2 )->store->discard_changes;
105 $biblio->discard_changes; # refresh
107 ok( $biblio->hidden_in_opac({ rules => $rules }), 'Biblio hidden' );
109 t::lib::Mocks::mock_preference( 'OpacHiddenItemsHidesRecord', 0 );
111 !$biblio->hidden_in_opac( { rules => $rules } ),
112 'Biblio hidden (!OpacHiddenItemsHidesRecord)'
116 $schema->storage->txn_rollback;
119 subtest 'items() tests' => sub {
123 $schema->storage->txn_begin;
125 my $biblio = $builder->build_sample_biblio();
127 is( $biblio->items->count, 0, 'No items, count is 0' );
129 my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
130 my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
132 my $items = $biblio->items;
133 is( ref($items), 'Koha::Items', 'Returns a Koha::Items resultset' );
134 is( $items->count, 2, 'Two items in resultset' );
136 my @items = $biblio->items->as_list;
137 is( scalar @items, 2, 'Same result, but in list context' );
139 $schema->storage->txn_rollback;
143 subtest 'get_coins and get_openurl' => sub {
147 $schema->storage->txn_begin;
149 my $builder = t::lib::TestBuilder->new;
150 my $biblio = $builder->build_sample_biblio({
156 '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',
157 'GetCOinsBiblio returned right metadata'
160 my $record = MARC::Record->new();
161 $record->append_fields( MARC::Field->new('100','','','a' => 'Author 2'), MARC::Field->new('880','','','a' => 'Something') );
162 my ( $biblionumber ) = C4::Biblio::AddBiblio($record, '');
163 my $biblio_no_title = Koha::Biblios->find($biblionumber);
165 $biblio_no_title->get_coins,
166 'ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=book&rft.au=Author%202',
167 'GetCOinsBiblio returned right metadata if biblio does not have a title'
170 t::lib::Mocks::mock_preference("OpenURLResolverURL", "https://koha.example.com/");
172 $biblio->get_openurl,
173 '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',
174 'Koha::Biblio->get_openurl returned right URL'
177 t::lib::Mocks::mock_preference("OpenURLResolverURL", "https://koha.example.com/?client_id=ci1");
179 $biblio->get_openurl,
180 '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',
181 'Koha::Biblio->get_openurl returned right URL'
184 $schema->storage->txn_rollback;
187 subtest 'is_serial() tests' => sub {
191 $schema->storage->txn_begin;
193 my $biblio = $builder->build_sample_biblio();
195 $biblio->serial( 1 )->store->discard_changes;
196 ok( $biblio->is_serial, 'Bibliographic record is serial' );
198 $biblio->serial( 0 )->store->discard_changes;
199 ok( !$biblio->is_serial, 'Bibliographic record is not serial' );
201 my $record = $biblio->metadata->record;
202 $record->leader('00142nas a22 7a 4500');
203 ModBiblio($record, $biblio->biblionumber );
204 $biblio = Koha::Biblios->find($biblio->biblionumber);
206 ok( $biblio->is_serial, 'Bibliographic record is serial' );
208 $schema->storage->txn_rollback;
211 subtest 'pickup_locations' => sub {
214 $schema->storage->txn_begin;
216 Koha::CirculationRules->search->delete;
217 Koha::CirculationRules->set_rules(
219 categorycode => undef,
223 reservesallowed => 25,
228 my $root1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
229 my $root2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
230 my $root3 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
232 my $library1 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, branchname => 'zzz' } } );
233 my $library2 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, branchname => 'AAA' } } );
234 my $library3 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 0, branchname => 'FFF' } } );
235 my $library4 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, branchname => 'CCC' } } );
236 my $library5 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, branchname => 'eee' } } );
237 my $library6 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, branchname => 'BBB' } } );
238 my $library7 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, branchname => 'DDD' } } );
239 my $library8 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 0, branchname => 'GGG' } } );
241 our @branchcodes = map { $_->branchcode } ($library1, $library2, $library3, $library4, $library5, $library6, $library7, $library8);
243 Koha::CirculationRules->set_rules(
245 branchcode => $library1->branchcode,
248 holdallowed => 'from_home_library',
249 hold_fulfillment_policy => 'any',
250 returnbranch => 'any'
255 Koha::CirculationRules->set_rules(
257 branchcode => $library2->branchcode,
260 holdallowed => 'from_local_hold_group',
261 hold_fulfillment_policy => 'holdgroup',
262 returnbranch => 'any'
267 Koha::CirculationRules->set_rules(
269 branchcode => $library3->branchcode,
272 holdallowed => 'from_local_hold_group',
273 hold_fulfillment_policy => 'patrongroup',
274 returnbranch => 'any'
279 Koha::CirculationRules->set_rules(
281 branchcode => $library4->branchcode,
284 holdallowed => 'from_any_library',
285 hold_fulfillment_policy => 'holdingbranch',
286 returnbranch => 'any'
291 Koha::CirculationRules->set_rules(
293 branchcode => $library5->branchcode,
296 holdallowed => 'from_any_library',
297 hold_fulfillment_policy => 'homebranch',
298 returnbranch => 'any'
303 Koha::CirculationRules->set_rules(
305 branchcode => $library6->branchcode,
308 holdallowed => 'from_home_library',
309 hold_fulfillment_policy => 'holdgroup',
310 returnbranch => 'any'
315 Koha::CirculationRules->set_rules(
317 branchcode => $library7->branchcode,
320 holdallowed => 'from_local_hold_group',
321 hold_fulfillment_policy => 'holdingbranch',
322 returnbranch => 'any'
328 Koha::CirculationRules->set_rules(
330 branchcode => $library8->branchcode,
333 holdallowed => 'from_any_library',
334 hold_fulfillment_policy => 'patrongroup',
335 returnbranch => 'any'
340 my $group1_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library1->branchcode } } );
341 my $group1_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library2->branchcode } } );
343 my $group2_3 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } );
344 my $group2_4 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } );
346 my $group3_5 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library5->branchcode } } );
347 my $group3_6 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library6->branchcode } } );
348 my $group3_7 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library7->branchcode } } );
349 my $group3_8 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library8->branchcode } } );
351 my $biblio1 = $builder->build_sample_biblio({ title => '1' });
352 my $biblio2 = $builder->build_sample_biblio({ title => '2' });
354 my $item1_1 = $builder->build_sample_item({
355 biblionumber => $biblio1->biblionumber,
356 homebranch => $library1->branchcode,
357 holdingbranch => $library2->branchcode,
360 my $item1_3 = $builder->build_sample_item({
361 biblionumber => $biblio1->biblionumber,
362 homebranch => $library3->branchcode,
363 holdingbranch => $library4->branchcode,
366 my $item1_7 = $builder->build_sample_item({
367 biblionumber => $biblio1->biblionumber,
368 homebranch => $library7->branchcode,
369 holdingbranch => $library4->branchcode,
372 my $item2_2 = $builder->build_sample_item({
373 biblionumber => $biblio2->biblionumber,
374 homebranch => $library2->branchcode,
375 holdingbranch => $library1->branchcode,
378 my $item2_4 = $builder->build_sample_item({
379 biblionumber => $biblio2->biblionumber,
380 homebranch => $library4->branchcode,
381 holdingbranch => $library3->branchcode,
384 my $item2_6 = $builder->build_sample_item({
385 biblionumber => $biblio2->biblionumber,
386 homebranch => $library6->branchcode,
387 holdingbranch => $library4->branchcode,
390 my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { firstname=>'1', branchcode => $library1->branchcode } } );
391 my $patron8 = $builder->build_object( { class => 'Koha::Patrons', value => { firstname=>'8', branchcode => $library8->branchcode } } );
394 "ItemHomeLibrary-1-1" => 6,
395 "ItemHomeLibrary-1-8" => 1,
396 "ItemHomeLibrary-2-1" => 2,
397 "ItemHomeLibrary-2-8" => 0,
398 "PatronLibrary-1-1" => 6,
399 "PatronLibrary-1-8" => 3,
400 "PatronLibrary-2-1" => 0,
401 "PatronLibrary-2-8" => 3,
405 my ( $cbranch, $biblio, $patron, $results ) = @_;
406 t::lib::Mocks::mock_preference('ReservesControlBranch', $cbranch);
409 my $pickup_location = $_;
410 grep { $pickup_location->branchcode eq $_ } @branchcodes
411 } $biblio->pickup_locations( { patron => $patron } )->as_list;
414 scalar(@pl) == $results->{ $cbranch . '-'
415 . $biblio->title . '-'
416 . $patron->firstname },
417 'ReservesControlBranch: '
424 . $results->{ $cbranch . '-'
425 . $biblio->title . '-'
426 . $patron->firstname }
432 foreach my $cbranch ('ItemHomeLibrary','PatronLibrary') {
433 foreach my $biblio ($biblio1, $biblio2) {
434 foreach my $patron ($patron1, $patron8) {
435 _doTest($cbranch, $biblio, $patron, $results);
440 my @pl_names = map { $_->branchname } $biblio1->pickup_locations( { patron => $patron1 } )->as_list;
441 my $pl_ori_str = join('|', @pl_names);
442 my $pl_sorted_str = join('|', sort { lc($a) cmp lc($b) } @pl_names);
444 $pl_ori_str eq $pl_sorted_str,
445 'Libraries must be sorted by name'
447 $schema->storage->txn_rollback;
450 subtest 'to_api() tests' => sub {
452 $schema->storage->txn_begin;
454 my $biblio = $builder->build_sample_biblio();
455 my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
457 my $biblioitem_api = $biblio->biblioitem->to_api;
458 my $biblio_api = $biblio->to_api;
460 plan tests => (scalar keys %{ $biblioitem_api }) + 1;
462 foreach my $key ( keys %{ $biblioitem_api } ) {
463 is( $biblio_api->{$key}, $biblioitem_api->{$key}, "$key is added to the biblio object" );
466 $biblio_api = $biblio->to_api({ embed => { items => {} } });
467 is_deeply( $biblio_api->{items}, [ $item->to_api ], 'Item correctly embedded' );
469 $schema->storage->txn_rollback;
472 subtest 'suggestions() tests' => sub {
476 $schema->storage->txn_begin;
478 my $biblio = $builder->build_sample_biblio();
480 is( ref($biblio->suggestions), 'Koha::Suggestions', 'Return type is correct' );
483 $biblio->suggestions->unblessed,
485 '->suggestions returns an empty Koha::Suggestions resultset'
488 my $suggestion = $builder->build_object(
490 class => 'Koha::Suggestions',
491 value => { biblionumber => $biblio->biblionumber }
495 my $suggestions = $biblio->suggestions->unblessed;
498 $biblio->suggestions->unblessed,
499 [ $suggestion->unblessed ],
500 '->suggestions returns the related Koha::Suggestion objects'
503 $schema->storage->txn_rollback;
506 subtest 'orders() and active_orders() tests' => sub {
510 $schema->storage->txn_begin;
512 my $biblio = $builder->build_sample_biblio();
514 my $orders = $biblio->orders;
515 my $active_orders = $biblio->active_orders;
517 is( ref($orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
518 is( $biblio->orders->count, $biblio->active_orders->count, '->orders->count returns the count for the resultset' );
520 # Add a couple orders
522 $builder->build_object(
524 class => 'Koha::Acquisition::Orders',
526 biblionumber => $biblio->biblionumber,
527 datecancellationprinted => '2019-12-31'
533 $builder->build_object(
535 class => 'Koha::Acquisition::Orders',
537 biblionumber => $biblio->biblionumber,
538 datecancellationprinted => undef
543 $orders = $biblio->orders;
544 $active_orders = $biblio->active_orders;
546 is( ref($orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
547 is( ref($active_orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
548 is( $orders->count, $active_orders->count + 2, '->active_orders->count returns the rigt count' );
550 $schema->storage->txn_rollback;
553 subtest 'subscriptions() tests' => sub {
557 $schema->storage->txn_begin;
559 my $biblio = $builder->build_sample_biblio;
561 my $subscriptions = $biblio->subscriptions;
562 is( ref($subscriptions), 'Koha::Subscriptions',
563 'Koha::Biblio->subscriptions should return a Koha::Subscriptions object'
565 is( $subscriptions->count, 0, 'Koha::Biblio->subscriptions should return the correct number of subscriptions');
567 # Add two subscriptions
569 $builder->build_object(
571 class => 'Koha::Subscriptions',
572 value => { biblionumber => $biblio->biblionumber }
577 $subscriptions = $biblio->subscriptions;
578 is( ref($subscriptions), 'Koha::Subscriptions',
579 'Koha::Biblio->subscriptions should return a Koha::Subscriptions object'
581 is( $subscriptions->count, 2, 'Koha::Biblio->subscriptions should return the correct number of subscriptions');
583 $schema->storage->txn_rollback;
586 subtest 'get_marc_notes() MARC21 tests' => sub {
589 $schema->storage->txn_begin;
591 t::lib::Mocks::mock_preference( 'NotesToHide', '520' );
593 my $biblio = $builder->build_sample_biblio;
594 my $record = $biblio->metadata->record;
595 $record->append_fields(
596 MARC::Field->new( '500', '', '', a => 'Note1' ),
597 MARC::Field->new( '505', '', '', a => 'Note2', u => 'http://someserver.com' ),
598 MARC::Field->new( '520', '', '', a => 'Note3 skipped' ),
599 MARC::Field->new( '541', '0', '', a => 'Note4 skipped on opac' ),
600 MARC::Field->new( '541', '', '', a => 'Note5' ),
601 MARC::Field->new( '590', '', '', a => 'CODE' ),
604 Koha::AuthorisedValueCategory->new({ category_name => 'TEST' })->store;
605 Koha::AuthorisedValue->new({ category => 'TEST', authorised_value => 'CODE', lib => 'Description should show', lib_opac => 'Description should show OPAC' })->store;
606 my $mss = Koha::MarcSubfieldStructures->find({tagfield => "590", tagsubfield => "a", frameworkcode => $biblio->frameworkcode });
607 $mss->update({ authorised_value => "TEST" });
609 my $cache = Koha::Caches->get_instance;
610 $cache->clear_from_cache("MarcStructure-0-");
611 $cache->clear_from_cache("MarcStructure-1-");
612 $cache->clear_from_cache("default_value_for_mod_marc-");
613 $cache->clear_from_cache("MarcSubfieldStructure-");
615 C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
616 $biblio = Koha::Biblios->find( $biblio->biblionumber);
618 my $notes = $biblio->get_marc_notes({ marcflavour => 'MARC21' });
619 is( $notes->[0]->{marcnote}, 'Note1', 'First note' );
620 is( $notes->[1]->{marcnote}, 'Note2', 'Second note' );
621 is( $notes->[2]->{marcnote}, 'http://someserver.com', 'URL separated' );
622 is( $notes->[3]->{marcnote}, 'Note4 skipped on opac',"Not shows if not opac" );
623 is( $notes->[4]->{marcnote}, 'Note5', 'Fifth note' );
624 is( $notes->[5]->{marcnote}, 'Description should show', 'Authorised value is correctly parsed to show description rather than code' );
625 is( @$notes, 6, 'No more notes' );
626 $notes = $biblio->get_marc_notes({ marcflavour => 'MARC21', opac => 1 });
627 is( $notes->[0]->{marcnote}, 'Note1', 'First note' );
628 is( $notes->[1]->{marcnote}, 'Note2', 'Second note' );
629 is( $notes->[2]->{marcnote}, 'http://someserver.com', 'URL separated' );
630 is( $notes->[3]->{marcnote}, 'Note5', 'Fifth note shows after fourth skipped' );
631 is( $notes->[4]->{marcnote}, 'Description should show OPAC', 'Authorised value is correctly parsed for OPAC to show description rather than code' );
632 is( @$notes, 5, 'No more notes' );
634 $cache->clear_from_cache("MarcStructure-0-");
635 $cache->clear_from_cache("MarcStructure-1-");
636 $cache->clear_from_cache("default_value_for_mod_marc-");
637 $cache->clear_from_cache("MarcSubfieldStructure-");
639 $schema->storage->txn_rollback;
642 subtest 'get_marc_notes() UNIMARC tests' => sub {
645 $schema->storage->txn_begin;
647 t::lib::Mocks::mock_preference( 'NotesToHide', '310' );
649 my $biblio = $builder->build_sample_biblio;
650 my $record = $biblio->metadata->record;
651 $record->append_fields(
652 MARC::Field->new( '300', '', '', a => 'Note1' ),
653 MARC::Field->new( '300', '', '', a => 'Note2' ),
654 MARC::Field->new( '310', '', '', a => 'Note3 skipped' ),
656 C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
657 $biblio = Koha::Biblios->find( $biblio->biblionumber);
658 my $notes = $biblio->get_marc_notes({ marcflavour => 'UNIMARC' });
659 is( $notes->[0]->{marcnote}, 'Note1', 'First note' );
660 is( $notes->[1]->{marcnote}, 'Note2', 'Second note' );
661 is( @$notes, 2, 'No more notes' );
663 $schema->storage->txn_rollback;
666 subtest 'host_items() tests' => sub {
669 $schema->storage->txn_begin;
671 my $biblio = $builder->build_sample_biblio( { frameworkcode => '' } );
673 t::lib::Mocks::mock_preference( 'EasyAnalyticalRecords', 1 );
674 my $host_items = $biblio->host_items;
675 is( ref($host_items), 'Koha::Items' );
676 is( $host_items->count, 0 );
679 $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
680 my $host_item_1 = $builder->build_sample_item;
681 my $host_item_2 = $builder->build_sample_item;
683 my $record = $biblio->metadata->record;
684 $record->append_fields(
687 9 => $host_item_1->itemnumber,
688 9 => $host_item_2->itemnumber
691 C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
692 $biblio = $biblio->get_from_storage;
693 $host_items = $biblio->host_items;
694 is( $host_items->count, 2 );
695 is_deeply( [ $host_items->get_column('itemnumber') ],
696 [ $host_item_1->itemnumber, $host_item_2->itemnumber ] );
698 t::lib::Mocks::mock_preference( 'EasyAnalyticalRecords', 0 );
699 $host_items = $biblio->host_items;
700 is( ref($host_items), 'Koha::Items' );
701 is( $host_items->count, 0 );
703 $schema->storage->txn_rollback;
706 subtest 'article_requests() tests' => sub {
710 $schema->storage->txn_begin;
712 my $item = $builder->build_sample_item;
713 my $biblio = $item->biblio;
715 my $article_requests = $biblio->article_requests;
716 is( ref($article_requests), 'Koha::ArticleRequests',
717 'In scalar context, type is correct' );
718 is( $article_requests->count, 0, 'No article requests' );
720 foreach my $i ( 0 .. 3 ) {
722 my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
724 Koha::ArticleRequest->new(
726 borrowernumber => $patron->id,
727 biblionumber => $biblio->id,
728 itemnumber => $item->id,
729 title => $biblio->title,
734 $article_requests = $biblio->article_requests;
735 is( $article_requests->count, 4, '4 article requests' );
737 $schema->storage->txn_rollback;