Bug 17600: Standardize our EXPORT_OK
[koha.git] / t / db_dependent / Koha / Biblio.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
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.
9 #
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.
14 #
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>.
17
18 use Modern::Perl;
19
20 use Test::More tests => 14;
21
22 use C4::Biblio qw( AddBiblio ModBiblio );
23 use Koha::Database;
24 use Koha::Acquisition::Orders;
25
26 use t::lib::TestBuilder;
27 use t::lib::Mocks;
28
29 BEGIN {
30     use_ok('Koha::Biblio');
31     use_ok('Koha::Biblios');
32 }
33
34 my $schema  = Koha::Database->new->schema;
35 my $builder = t::lib::TestBuilder->new;
36
37 subtest 'metadata() tests' => sub {
38
39     plan tests => 4;
40
41     $schema->storage->txn_begin;
42
43     my $title = 'Oranges and Peaches';
44
45     my $record = MARC::Record->new();
46     my $field = MARC::Field->new('245','','','a' => $title);
47     $record->append_fields( $field );
48     my ($biblionumber) = C4::Biblio::AddBiblio($record, '');
49
50     my $biblio = Koha::Biblios->find( $biblionumber );
51     is( ref $biblio, 'Koha::Biblio', 'Found a Koha::Biblio object' );
52
53     my $metadata = $biblio->metadata;
54     is( ref $metadata, 'Koha::Biblio::Metadata', 'Method metadata() returned a Koha::Biblio::Metadata object' );
55
56     my $record2 = $metadata->record;
57     is( ref $record2, 'MARC::Record', 'Method record() returned a MARC::Record object' );
58
59     is( $record2->field('245')->subfield("a"), $title, 'Title in 245$a matches title from original record object' );
60
61     $schema->storage->txn_rollback;
62 };
63
64 subtest 'hidden_in_opac() tests' => sub {
65
66     plan tests => 6;
67
68     $schema->storage->txn_begin;
69
70     my $biblio = $builder->build_sample_biblio();
71     my $rules  = { withdrawn => [ 2 ] };
72
73     t::lib::Mocks::mock_preference( 'OpacHiddenItemsHidesRecord', 0 );
74
75     ok(
76         !$biblio->hidden_in_opac({ rules => $rules }),
77         'Biblio not hidden if there is no item attached (!OpacHiddenItemsHidesRecord)'
78     );
79
80     t::lib::Mocks::mock_preference( 'OpacHiddenItemsHidesRecord', 1 );
81
82     ok(
83         !$biblio->hidden_in_opac({ rules => $rules }),
84         'Biblio not hidden if there is no item attached (OpacHiddenItemsHidesRecord)'
85     );
86
87     my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
88     my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
89
90     $item_1->withdrawn( 1 )->store->discard_changes;
91     $item_2->withdrawn( 1 )->store->discard_changes;
92
93     ok( !$biblio->hidden_in_opac({ rules => $rules }), 'Biblio not hidden' );
94
95     $item_2->withdrawn( 2 )->store->discard_changes;
96     $biblio->discard_changes; # refresh
97
98     ok( !$biblio->hidden_in_opac({ rules => $rules }), 'Biblio not hidden' );
99
100     $item_1->withdrawn( 2 )->store->discard_changes;
101     $biblio->discard_changes; # refresh
102
103     ok( $biblio->hidden_in_opac({ rules => $rules }), 'Biblio hidden' );
104
105     t::lib::Mocks::mock_preference( 'OpacHiddenItemsHidesRecord', 0 );
106     ok(
107         !$biblio->hidden_in_opac( { rules => $rules } ),
108         'Biblio hidden (!OpacHiddenItemsHidesRecord)'
109     );
110
111
112     $schema->storage->txn_rollback;
113 };
114
115 subtest 'items() tests' => sub {
116
117     plan tests => 4;
118
119     $schema->storage->txn_begin;
120
121     my $biblio = $builder->build_sample_biblio();
122
123     is( $biblio->items->count, 0, 'No items, count is 0' );
124
125     my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
126     my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
127
128     my $items = $biblio->items;
129     is( ref($items), 'Koha::Items', 'Returns a Koha::Items resultset' );
130     is( $items->count, 2, 'Two items in resultset' );
131
132     my @items = $biblio->items->as_list;
133     is( scalar @items, 2, 'Same result, but in list context' );
134
135     $schema->storage->txn_rollback;
136
137 };
138
139 subtest 'get_coins and get_openurl' => sub {
140
141     plan tests => 4;
142
143     $schema->storage->txn_begin;
144
145     my $builder = t::lib::TestBuilder->new;
146     my $biblio = $builder->build_sample_biblio({
147             title => 'Title 1',
148             author => 'Author 1'
149         });
150     is(
151         $biblio->get_coins,
152         'ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=Title%201&amp;rft.au=Author%201',
153         'GetCOinsBiblio returned right metadata'
154     );
155
156     my $record = MARC::Record->new();
157     $record->append_fields( MARC::Field->new('100','','','a' => 'Author 2'), MARC::Field->new('880','','','a' => 'Something') );
158     my ( $biblionumber ) = C4::Biblio::AddBiblio($record, '');
159     my $biblio_no_title = Koha::Biblios->find($biblionumber);
160     is(
161         $biblio_no_title->get_coins,
162         'ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.au=Author%202',
163         'GetCOinsBiblio returned right metadata if biblio does not have a title'
164     );
165
166     t::lib::Mocks::mock_preference("OpenURLResolverURL", "https://koha.example.com/");
167     is(
168         $biblio->get_openurl,
169         'https://koha.example.com/?ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=Title%201&amp;rft.au=Author%201',
170         'Koha::Biblio->get_openurl returned right URL'
171     );
172
173     t::lib::Mocks::mock_preference("OpenURLResolverURL", "https://koha.example.com/?client_id=ci1");
174     is(
175         $biblio->get_openurl,
176         'https://koha.example.com/?client_id=ci1&amp;ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=Title%201&amp;rft.au=Author%201',
177         'Koha::Biblio->get_openurl returned right URL'
178     );
179
180     $schema->storage->txn_rollback;
181 };
182
183 subtest 'is_serial() tests' => sub {
184
185     plan tests => 3;
186
187     $schema->storage->txn_begin;
188
189     my $biblio = $builder->build_sample_biblio();
190
191     $biblio->serial( 1 )->store->discard_changes;
192     ok( $biblio->is_serial, 'Bibliographic record is serial' );
193
194     $biblio->serial( 0 )->store->discard_changes;
195     ok( !$biblio->is_serial, 'Bibliographic record is not serial' );
196
197     my $record = $biblio->metadata->record;
198     $record->leader('00142nas a22     7a 4500');
199     ModBiblio($record, $biblio->biblionumber );
200     $biblio = Koha::Biblios->find($biblio->biblionumber);
201
202     ok( $biblio->is_serial, 'Bibliographic record is serial' );
203
204     $schema->storage->txn_rollback;
205 };
206
207 subtest 'pickup_locations' => sub {
208     plan tests => 9;
209
210     $schema->storage->txn_begin;
211
212     Koha::CirculationRules->search->delete;
213     Koha::CirculationRules->set_rules(
214         {
215             categorycode => undef,
216             itemtype     => undef,
217             branchcode   => undef,
218             rules        => {
219                 reservesallowed => 25,
220             }
221         }
222     );
223
224     my $root1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
225     my $root2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
226     my $root3 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
227
228     my $library1 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, branchname => 'zzz' } } );
229     my $library2 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, branchname => 'AAA' } } );
230     my $library3 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 0, branchname => 'FFF' } } );
231     my $library4 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, branchname => 'CCC' } } );
232     my $library5 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, branchname => 'eee' } } );
233     my $library6 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, branchname => 'BBB' } } );
234     my $library7 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, branchname => 'DDD' } } );
235     my $library8 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 0, branchname => 'GGG' } } );
236
237     our @branchcodes = map { $_->branchcode } ($library1, $library2, $library3, $library4, $library5, $library6, $library7, $library8);
238
239     Koha::CirculationRules->set_rules(
240         {
241             branchcode => $library1->branchcode,
242             itemtype   => undef,
243             rules => {
244                 holdallowed => 'from_home_library',
245                 hold_fulfillment_policy => 'any',
246                 returnbranch => 'any'
247             }
248         }
249     );
250
251     Koha::CirculationRules->set_rules(
252         {
253             branchcode => $library2->branchcode,
254             itemtype   => undef,
255             rules => {
256                 holdallowed => 'from_local_hold_group',
257                 hold_fulfillment_policy => 'holdgroup',
258                 returnbranch => 'any'
259             }
260         }
261     );
262
263     Koha::CirculationRules->set_rules(
264         {
265             branchcode => $library3->branchcode,
266             itemtype   => undef,
267             rules => {
268                 holdallowed => 'from_local_hold_group',
269                 hold_fulfillment_policy => 'patrongroup',
270                 returnbranch => 'any'
271             }
272         }
273     );
274
275     Koha::CirculationRules->set_rules(
276         {
277             branchcode => $library4->branchcode,
278             itemtype   => undef,
279             rules => {
280                 holdallowed => 'from_any_library',
281                 hold_fulfillment_policy => 'holdingbranch',
282                 returnbranch => 'any'
283             }
284         }
285     );
286
287     Koha::CirculationRules->set_rules(
288         {
289             branchcode => $library5->branchcode,
290             itemtype   => undef,
291             rules => {
292                 holdallowed => 'from_any_library',
293                 hold_fulfillment_policy => 'homebranch',
294                 returnbranch => 'any'
295             }
296         }
297     );
298
299     Koha::CirculationRules->set_rules(
300         {
301             branchcode => $library6->branchcode,
302             itemtype   => undef,
303             rules => {
304                 holdallowed => 'from_home_library',
305                 hold_fulfillment_policy => 'holdgroup',
306                 returnbranch => 'any'
307             }
308         }
309     );
310
311     Koha::CirculationRules->set_rules(
312         {
313             branchcode => $library7->branchcode,
314             itemtype   => undef,
315             rules => {
316                 holdallowed => 'from_local_hold_group',
317                 hold_fulfillment_policy => 'holdingbranch',
318                 returnbranch => 'any'
319             }
320         }
321     );
322
323
324     Koha::CirculationRules->set_rules(
325         {
326             branchcode => $library8->branchcode,
327             itemtype   => undef,
328             rules => {
329                 holdallowed => 'from_any_library',
330                 hold_fulfillment_policy => 'patrongroup',
331                 returnbranch => 'any'
332             }
333         }
334     );
335
336     my $group1_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library1->branchcode } } );
337     my $group1_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library2->branchcode } } );
338
339     my $group2_3 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } );
340     my $group2_4 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } );
341
342     my $group3_5 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library5->branchcode } } );
343     my $group3_6 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library6->branchcode } } );
344     my $group3_7 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library7->branchcode } } );
345     my $group3_8 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library8->branchcode } } );
346
347     my $biblio1  = $builder->build_sample_biblio({ title => '1' });
348     my $biblio2  = $builder->build_sample_biblio({ title => '2' });
349
350     my $item1_1  = $builder->build_sample_item({
351         biblionumber     => $biblio1->biblionumber,
352         homebranch       => $library1->branchcode,
353         holdingbranch    => $library2->branchcode,
354     })->store;
355
356     my $item1_3  = $builder->build_sample_item({
357         biblionumber     => $biblio1->biblionumber,
358         homebranch       => $library3->branchcode,
359         holdingbranch    => $library4->branchcode,
360     })->store;
361
362     my $item1_7  = $builder->build_sample_item({
363         biblionumber     => $biblio1->biblionumber,
364         homebranch       => $library7->branchcode,
365         holdingbranch    => $library4->branchcode,
366     })->store;
367
368     my $item2_2  = $builder->build_sample_item({
369         biblionumber     => $biblio2->biblionumber,
370         homebranch       => $library2->branchcode,
371         holdingbranch    => $library1->branchcode,
372     })->store;
373
374     my $item2_4  = $builder->build_sample_item({
375         biblionumber     => $biblio2->biblionumber,
376         homebranch       => $library4->branchcode,
377         holdingbranch    => $library3->branchcode,
378     })->store;
379
380     my $item2_6  = $builder->build_sample_item({
381         biblionumber     => $biblio2->biblionumber,
382         homebranch       => $library6->branchcode,
383         holdingbranch    => $library4->branchcode,
384     })->store;
385
386     my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { firstname=>'1', branchcode => $library1->branchcode } } );
387     my $patron8 = $builder->build_object( { class => 'Koha::Patrons', value => { firstname=>'8', branchcode => $library8->branchcode } } );
388
389     my $results = {
390         "ItemHomeLibrary-1-1" => 6,
391         "ItemHomeLibrary-1-8" => 1,
392         "ItemHomeLibrary-2-1" => 2,
393         "ItemHomeLibrary-2-8" => 0,
394         "PatronLibrary-1-1" => 6,
395         "PatronLibrary-1-8" => 3,
396         "PatronLibrary-2-1" => 0,
397         "PatronLibrary-2-8" => 3,
398     };
399
400     sub _doTest {
401         my ( $cbranch, $biblio, $patron, $results ) = @_;
402         t::lib::Mocks::mock_preference('ReservesControlBranch', $cbranch);
403
404         my @pl = map {
405             my $pickup_location = $_;
406             grep { $pickup_location->branchcode eq $_ } @branchcodes
407         } $biblio->pickup_locations( { patron => $patron } )->as_list;
408
409         ok(
410             scalar(@pl) == $results->{ $cbranch . '-'
411                   . $biblio->title . '-'
412                   . $patron->firstname },
413             'ReservesControlBranch: '
414               . $cbranch
415               . ', biblio'
416               . $biblio->title
417               . ', patron'
418               . $patron->firstname
419               . ' should return '
420               . $results->{ $cbranch . '-'
421                   . $biblio->title . '-'
422                   . $patron->firstname }
423               . ' but returns '
424               . scalar(@pl)
425         );
426     }
427
428     foreach my $cbranch ('ItemHomeLibrary','PatronLibrary') {
429         foreach my $biblio ($biblio1, $biblio2) {
430             foreach my $patron ($patron1, $patron8) {
431                 _doTest($cbranch, $biblio, $patron, $results);
432             }
433         }
434     }
435
436     my @pl_names = map { $_->branchname } $biblio1->pickup_locations( { patron => $patron1 } )->as_list;
437     my $pl_ori_str = join('|', @pl_names);
438     my $pl_sorted_str = join('|', sort { lc($a) cmp lc($b) } @pl_names);
439     ok(
440         $pl_ori_str eq $pl_sorted_str,
441         'Libraries must be sorted by name'
442     );
443     $schema->storage->txn_rollback;
444 };
445
446 subtest 'to_api() tests' => sub {
447
448     $schema->storage->txn_begin;
449
450     my $biblio = $builder->build_sample_biblio();
451     my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
452
453     my $biblioitem_api = $biblio->biblioitem->to_api;
454     my $biblio_api     = $biblio->to_api;
455
456     plan tests => (scalar keys %{ $biblioitem_api }) + 1;
457
458     foreach my $key ( keys %{ $biblioitem_api } ) {
459         is( $biblio_api->{$key}, $biblioitem_api->{$key}, "$key is added to the biblio object" );
460     }
461
462     $biblio_api = $biblio->to_api({ embed => { items => {} } });
463     is_deeply( $biblio_api->{items}, [ $item->to_api ], 'Item correctly embedded' );
464
465     $schema->storage->txn_rollback;
466 };
467
468 subtest 'suggestions() tests' => sub {
469
470     plan tests => 3;
471
472     $schema->storage->txn_begin;
473
474     my $biblio     = $builder->build_sample_biblio();
475
476     is( ref($biblio->suggestions), 'Koha::Suggestions', 'Return type is correct' );
477
478     is_deeply(
479         $biblio->suggestions->unblessed,
480         [],
481         '->suggestions returns an empty Koha::Suggestions resultset'
482     );
483
484     my $suggestion = $builder->build_object(
485         {
486             class => 'Koha::Suggestions',
487             value => { biblionumber => $biblio->biblionumber }
488         }
489     );
490
491     my $suggestions = $biblio->suggestions->unblessed;
492
493     is_deeply(
494         $biblio->suggestions->unblessed,
495         [ $suggestion->unblessed ],
496         '->suggestions returns the related Koha::Suggestion objects'
497     );
498
499     $schema->storage->txn_rollback;
500 };
501
502 subtest 'orders() and active_orders() tests' => sub {
503
504     plan tests => 5;
505
506     $schema->storage->txn_begin;
507
508     my $biblio = $builder->build_sample_biblio();
509
510     my $orders        = $biblio->orders;
511     my $active_orders = $biblio->active_orders;
512
513     is( ref($orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
514     is( $biblio->orders->count, $biblio->active_orders->count, '->orders->count returns the count for the resultset' );
515
516     # Add a couple orders
517     foreach (1..2) {
518         $builder->build_object(
519             {
520                 class => 'Koha::Acquisition::Orders',
521                 value => {
522                     biblionumber => $biblio->biblionumber,
523                     datecancellationprinted => '2019-12-31'
524                 }
525             }
526         );
527     }
528
529     $builder->build_object(
530         {
531             class => 'Koha::Acquisition::Orders',
532             value => {
533                 biblionumber => $biblio->biblionumber,
534                 datecancellationprinted => undef
535             }
536         }
537     );
538
539     $orders = $biblio->orders;
540     $active_orders = $biblio->active_orders;
541
542     is( ref($orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
543     is( ref($active_orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
544     is( $orders->count, $active_orders->count + 2, '->active_orders->count returns the rigt count' );
545
546     $schema->storage->txn_rollback;
547 };
548
549 subtest 'subscriptions() tests' => sub {
550
551     plan tests => 4;
552
553     $schema->storage->txn_begin;
554
555     my $biblio = $builder->build_sample_biblio;
556
557     my $subscriptions = $biblio->subscriptions;
558     is( ref($subscriptions), 'Koha::Subscriptions',
559         'Koha::Biblio->subscriptions should return a Koha::Subscriptions object'
560     );
561     is( $subscriptions->count, 0, 'Koha::Biblio->subscriptions should return the correct number of subscriptions');
562
563     # Add two subscriptions
564     foreach (1..2) {
565         $builder->build_object(
566             {
567                 class => 'Koha::Subscriptions',
568                 value => { biblionumber => $biblio->biblionumber }
569             }
570         );
571     }
572
573     $subscriptions = $biblio->subscriptions;
574     is( ref($subscriptions), 'Koha::Subscriptions',
575         'Koha::Biblio->subscriptions should return a Koha::Subscriptions object'
576     );
577     is( $subscriptions->count, 2, 'Koha::Biblio->subscriptions should return the correct number of subscriptions');
578
579     $schema->storage->txn_rollback;
580 };
581
582 subtest 'get_marc_notes() MARC21 tests' => sub {
583     plan tests => 11;
584
585     $schema->storage->txn_begin;
586
587     t::lib::Mocks::mock_preference( 'NotesToHide', '520' );
588
589     my $biblio = $builder->build_sample_biblio;
590     my $record = $biblio->metadata->record;
591     $record->append_fields(
592         MARC::Field->new( '500', '', '', a => 'Note1' ),
593         MARC::Field->new( '505', '', '', a => 'Note2', u => 'http://someserver.com' ),
594         MARC::Field->new( '520', '', '', a => 'Note3 skipped' ),
595         MARC::Field->new( '541', '0', '', a => 'Note4 skipped on opac' ),
596         MARC::Field->new( '541', '', '', a => 'Note5' ),
597     );
598     C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
599     $biblio = Koha::Biblios->find( $biblio->biblionumber);
600     my $notes = $biblio->get_marc_notes({ marcflavour => 'MARC21' });
601     is( $notes->[0]->{marcnote}, 'Note1', 'First note' );
602     is( $notes->[1]->{marcnote}, 'Note2', 'Second note' );
603     is( $notes->[2]->{marcnote}, 'http://someserver.com', 'URL separated' );
604     is( $notes->[3]->{marcnote}, 'Note4 skipped on opac',"Not shows if not opac" );
605     is( $notes->[4]->{marcnote}, 'Note5', 'Fifth note' );
606     is( @$notes, 5, 'No more notes' );
607     $notes = $biblio->get_marc_notes({ marcflavour => 'MARC21', opac => 1 });
608     is( $notes->[0]->{marcnote}, 'Note1', 'First note' );
609     is( $notes->[1]->{marcnote}, 'Note2', 'Second note' );
610     is( $notes->[2]->{marcnote}, 'http://someserver.com', 'URL separated' );
611     is( $notes->[3]->{marcnote}, 'Note5', 'Fifth note shows after fourth skipped' );
612     is( @$notes, 4, 'No more notes' );
613
614     $schema->storage->txn_rollback;
615 };
616
617 subtest 'get_marc_notes() UNIMARC tests' => sub {
618     plan tests => 3;
619
620     $schema->storage->txn_begin;
621
622     t::lib::Mocks::mock_preference( 'NotesToHide', '310' );
623
624     my $biblio = $builder->build_sample_biblio;
625     my $record = $biblio->metadata->record;
626     $record->append_fields(
627         MARC::Field->new( '300', '', '', a => 'Note1' ),
628         MARC::Field->new( '300', '', '', a => 'Note2' ),
629         MARC::Field->new( '310', '', '', a => 'Note3 skipped' ),
630     );
631     C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
632     $biblio = Koha::Biblios->find( $biblio->biblionumber);
633     my $notes = $biblio->get_marc_notes({ marcflavour => 'UNIMARC' });
634     is( $notes->[0]->{marcnote}, 'Note1', 'First note' );
635     is( $notes->[1]->{marcnote}, 'Note2', 'Second note' );
636     is( @$notes, 2, 'No more notes' );
637
638     $schema->storage->txn_rollback;
639 };