Bug 26963: (QA follow-up) Fix up tests and cover case of undefined ccode
[koha.git] / t / db_dependent / Koha / Item.t
1 #!/usr/bin/perl
2
3 # Copyright 2019 Koha Development team
4 #
5 # This file is part of Koha
6 #
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.
11 #
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.
16 #
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>.
19
20 use Modern::Perl;
21
22 use Test::More tests => 7;
23
24 use C4::Biblio;
25 use C4::Circulation;
26
27 use Koha::Items;
28 use Koha::Database;
29 use Koha::Old::Items;
30
31 use List::MoreUtils qw(all);
32
33 use t::lib::TestBuilder;
34 use t::lib::Mocks;
35
36 my $schema  = Koha::Database->new->schema;
37 my $builder = t::lib::TestBuilder->new;
38
39 subtest 'hidden_in_opac() tests' => sub {
40
41     plan tests => 4;
42
43     $schema->storage->txn_begin;
44
45     my $item  = $builder->build_sample_item({ itemlost => 2 });
46     my $rules = {};
47
48     # disable hidelostitems as it interteres with OpachiddenItems for the calculation
49     t::lib::Mocks::mock_preference( 'hidelostitems', 0 );
50
51     ok( !$item->hidden_in_opac, 'No rules passed, shouldn\'t hide' );
52     ok( !$item->hidden_in_opac({ rules => $rules }), 'Empty rules passed, shouldn\'t hide' );
53
54     # enable hidelostitems to verify correct behaviour
55     t::lib::Mocks::mock_preference( 'hidelostitems', 1 );
56     ok( $item->hidden_in_opac, 'Even with no rules, item should hide because of hidelostitems syspref' );
57
58     # disable hidelostitems
59     t::lib::Mocks::mock_preference( 'hidelostitems', 0 );
60     my $withdrawn = $item->withdrawn + 1; # make sure this attribute doesn't match
61
62     $rules = { withdrawn => [$withdrawn], itype => [ $item->itype ] };
63
64     ok( $item->hidden_in_opac({ rules => $rules }), 'Rule matching itype passed, should hide' );
65
66
67
68     $schema->storage->txn_rollback;
69 };
70
71 subtest 'has_pending_hold() tests' => sub {
72
73     plan tests => 2;
74
75     $schema->storage->txn_begin;
76
77     my $dbh = C4::Context->dbh;
78     my $item  = $builder->build_sample_item({ itemlost => 0 });
79     my $itemnumber = $item->itemnumber;
80
81     $dbh->do("INSERT INTO tmp_holdsqueue (surname,borrowernumber,itemnumber) VALUES ('Clamp',42,$itemnumber)");
82     ok( $item->has_pending_hold, "Yes, we have a pending hold");
83     $dbh->do("DELETE FROM tmp_holdsqueue WHERE itemnumber=$itemnumber");
84     ok( !$item->has_pending_hold, "We don't have a pending hold if nothing in the tmp_holdsqueue");
85
86     $schema->storage->txn_rollback;
87 };
88
89 subtest "as_marc_field() tests" => sub {
90
91     my $mss = C4::Biblio::GetMarcSubfieldStructure( '', { unsafe => 1 } );
92
93     my @schema_columns = $schema->resultset('Item')->result_source->columns;
94     my @mapped_columns = grep { exists $mss->{'items.'.$_} } @schema_columns;
95
96     plan tests => 2 * (scalar @mapped_columns + 1) + 2;
97
98     $schema->storage->txn_begin;
99
100     my $item = $builder->build_sample_item;
101     # Make sure it has at least one undefined attribute
102     $item->set({ replacementprice => undef })->store->discard_changes;
103
104     # Tests with the mss parameter
105     my $marc_field = $item->as_marc_field({ mss => $mss });
106
107     is(
108         $marc_field->tag,
109         $mss->{'items.itemnumber'}[0]->{tagfield},
110         'Generated field set the right tag number'
111     );
112
113     foreach my $column ( @mapped_columns ) {
114         my $tagsubfield = $mss->{ 'items.' . $column }[0]->{tagsubfield};
115         is( $marc_field->subfield($tagsubfield),
116             $item->$column, "Value is mapped correctly for column $column" );
117     }
118
119     # Tests without the mss parameter
120     $marc_field = $item->as_marc_field();
121
122     is(
123         $marc_field->tag,
124         $mss->{'items.itemnumber'}[0]->{tagfield},
125         'Generated field set the right tag number'
126     );
127
128     foreach my $column (@mapped_columns) {
129         my $tagsubfield = $mss->{ 'items.' . $column }[0]->{tagsubfield};
130         is( $marc_field->subfield($tagsubfield),
131             $item->$column, "Value is mapped correctly for column $column" );
132     }
133
134     my $unmapped_subfield = Koha::MarcSubfieldStructure->new(
135         {
136             frameworkcode => '',
137             tagfield      => $mss->{'items.itemnumber'}[0]->{tagfield},
138             tagsubfield   => 'X',
139         }
140     )->store;
141
142     $mss = C4::Biblio::GetMarcSubfieldStructure( '', { unsafe => 0 } );
143     my @unlinked_subfields;
144     push @unlinked_subfields, X => 'Something weird';
145     $item->more_subfields_xml( C4::Items::_get_unlinked_subfields_xml( \@unlinked_subfields ) )->store;
146
147     $marc_field = $item->as_marc_field;
148
149     my @subfields = $marc_field->subfields;
150     my $result = all { defined $_->[1] } @subfields;
151     ok( $result, 'There are no undef subfields' );
152
153     is( scalar $marc_field->subfield('X'), 'Something weird', 'more_subfield_xml is considered' );
154
155     $schema->storage->txn_rollback;
156 };
157
158 subtest 'pickup_locations' => sub {
159
160     $schema->storage->txn_begin;
161
162     my $dbh = C4::Context->dbh;
163
164     my $root1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1, branchcode => undef } } );
165     my $root2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1, branchcode => undef } } );
166     my $library1 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, } } );
167     my $library2 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, } } );
168     my $library3 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 0, } } );
169     my $library4 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, } } );
170     my $group1_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library1->branchcode } } );
171     my $group1_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library2->branchcode } } );
172
173     my $group2_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } );
174     my $group2_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } );
175
176
177     my $item1 = $builder->build_sample_item(
178         {
179             homebranch    => $library1->branchcode,
180             holdingbranch => $library2->branchcode,
181             copynumber    => 1,
182             ccode         => 'Gollum'
183         }
184     )->store;
185
186     my $item3 = $builder->build_sample_item(
187         {
188             homebranch    => $library3->branchcode,
189             holdingbranch => $library4->branchcode,
190             copynumber    => 3,
191             itype         => $item1->itype,
192         }
193     )->store;
194
195     Koha::CirculationRules->set_rules(
196         {
197             categorycode => undef,
198             itemtype     => $item1->itype,
199             branchcode   => undef,
200             rules        => {
201                 reservesallowed => 25,
202             }
203         }
204     );
205
206
207     my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library1->branchcode, firstname => '1' } } );
208     my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode, firstname => '4' } } );
209
210     my $all_count = Koha::Libraries->search({ pickup_location => 1})->count();
211     plan tests => ($all_count +1) * 7 + 31 + 61;
212
213     my $results = {
214         "1-1-1-any"           => $all_count,
215         "1-1-1-holdgroup"     => 2,
216         "1-1-1-patrongroup"   => 2,
217         "1-1-1-homebranch"    => 1,
218         "1-1-1-holdingbranch" => 1,
219         "1-1-2-any"           => $all_count,
220         "1-1-2-holdgroup"     => 2,
221         "1-1-2-patrongroup"   => 2,
222         "1-1-2-homebranch"    => 1,
223         "1-1-2-holdingbranch" => 1,
224         "1-1-3-any"           => $all_count,
225         "1-1-3-holdgroup"     => 2,
226         "1-1-3-patrongroup"   => 2,
227         "1-1-3-homebranch"    => 1,
228         "1-1-3-holdingbranch" => 1,
229         "1-4-1-any"           => 0,
230         "1-4-1-holdgroup"     => 0,
231         "1-4-1-patrongroup"   => 0,
232         "1-4-1-homebranch"    => 0,
233         "1-4-1-holdingbranch" => 0,
234         "1-4-2-any"           => $all_count,
235         "1-4-2-holdgroup"     => 2,
236         "1-4-2-patrongroup"   => 1,
237         "1-4-2-homebranch"    => 1,
238         "1-4-2-holdingbranch" => 1,
239         "1-4-3-any"           => 0,
240         "1-4-3-holdgroup"     => 0,
241         "1-4-3-patrongroup"   => 0,
242         "1-4-3-homebranch"    => 0,
243         "1-4-3-holdingbranch" => 0,
244         "3-1-1-any"           => 0,
245         "3-1-1-holdgroup"     => 0,
246         "3-1-1-patrongroup"   => 0,
247         "3-1-1-homebranch"    => 0,
248         "3-1-1-holdingbranch" => 0,
249         "3-1-2-any"           => $all_count,
250         "3-1-2-holdgroup"     => 1,
251         "3-1-2-patrongroup"   => 2,
252         "3-1-2-homebranch"    => 0,
253         "3-1-2-holdingbranch" => 1,
254         "3-1-3-any"           => 0,
255         "3-1-3-holdgroup"     => 0,
256         "3-1-3-patrongroup"   => 0,
257         "3-1-3-homebranch"    => 0,
258         "3-1-3-holdingbranch" => 0,
259         "3-4-1-any"           => 0,
260         "3-4-1-holdgroup"     => 0,
261         "3-4-1-patrongroup"   => 0,
262         "3-4-1-homebranch"    => 0,
263         "3-4-1-holdingbranch" => 0,
264         "3-4-2-any"           => $all_count,
265         "3-4-2-holdgroup"     => 1,
266         "3-4-2-patrongroup"   => 1,
267         "3-4-2-homebranch"    => 0,
268         "3-4-2-holdingbranch" => 1,
269         "3-4-3-any"           => $all_count,
270         "3-4-3-holdgroup"     => 1,
271         "3-4-3-patrongroup"   => 1,
272         "3-4-3-homebranch"    => 0,
273         "3-4-3-holdingbranch" => 1
274     };
275
276     sub _doTest {
277         my ( $item, $patron, $ha, $hfp, $results ) = @_;
278
279         Koha::CirculationRules->set_rules(
280             {
281                 branchcode => undef,
282                 itemtype   => undef,
283                 rules => {
284                     holdallowed => $ha,
285                     hold_fulfillment_policy => $hfp,
286                     returnbranch => 'any'
287                 }
288             }
289         );
290         my @pl = $item->pickup_locations( { patron => $patron} )->as_list;
291         my $ha_value=$ha==3?'holdgroup':($ha==2?'any':'homebranch');
292
293         foreach my $pickup_location (@pl) {
294             is( ref($pickup_location), 'Koha::Library', 'Object type is correct' );
295         }
296         ok(
297             scalar(@pl) == $results->{
298                     $item->copynumber . '-'
299                   . $patron->firstname . '-'
300                   . $ha . '-'
301                   . $hfp
302             },
303             'item'
304               . $item->copynumber
305               . ', patron'
306               . $patron->firstname
307               . ', holdallowed: '
308               . $ha_value
309               . ', hold_fulfillment_policy: '
310               . $hfp
311               . ' should return '
312               . $results->{
313                     $item->copynumber . '-'
314                   . $patron->firstname . '-'
315                   . $ha . '-'
316                   . $hfp
317               }
318               . ' and returns '
319               . scalar(@pl)
320         );
321
322     }
323
324
325     foreach my $item ($item1, $item3) {
326         foreach my $patron ($patron1, $patron4) {
327             #holdallowed 1: homebranch, 2: any, 3: holdgroup
328             foreach my $ha (1, 2, 3) {
329                 foreach my $hfp ('any', 'holdgroup', 'patrongroup', 'homebranch', 'holdingbranch') {
330                     _doTest($item, $patron, $ha, $hfp, $results);
331                 }
332             }
333         }
334     }
335
336     # Now test that branchtransferlimits will further filter the pickup locations
337
338     my $item_no_ccode = $builder->build_sample_item(
339         {
340             homebranch    => $library1->branchcode,
341             holdingbranch => $library2->branchcode,
342             itype         => $item1->itype,
343         }
344     )->store;
345
346     t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1);
347     t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
348     Koha::CirculationRules->set_rules(
349         {
350             branchcode => undef,
351             itemtype   => $item1->itype,
352             rules      => {
353                 holdallowed             => 1,
354                 hold_fulfillment_policy => 1,
355                 returnbranch            => 'any'
356             }
357         }
358     );
359     $builder->build_object(
360         {
361             class => 'Koha::Item::Transfer::Limits',
362             value => {
363                 toBranch   => $library1->branchcode,
364                 fromBranch => $library2->branchcode,
365                 itemtype   => $item1->itype,
366                 ccode      => undef,
367             }
368         }
369     );
370
371     my $pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list;
372     is( scalar @$pickup_locations, $all_count - 1, "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library");
373
374     $builder->build_object(
375         {
376             class => 'Koha::Item::Transfer::Limits',
377             value => {
378                 toBranch   => $library4->branchcode,
379                 fromBranch => $library2->branchcode,
380                 itemtype   => $item1->itype,
381                 ccode      => undef,
382             }
383         }
384     );
385
386     $pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list;
387     is( scalar @$pickup_locations, $all_count - 2, "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries");
388
389     t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'ccode');
390     $pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list;
391     is( scalar @$pickup_locations, $all_count, "With no transfer limits of type ccode we get back the libraries that are pickup locations");
392
393     $pickup_locations = $item_no_ccode->pickup_locations( { patron => $patron1 } )->as_list;
394     is( scalar @$pickup_locations, $all_count, "With no transfer limits of type ccode and an item with no ccode we get back the libraries that are pickup locations");
395
396     $builder->build_object(
397         {
398             class => 'Koha::Item::Transfer::Limits',
399             value => {
400                 toBranch   => $library2->branchcode,
401                 fromBranch => $library2->branchcode,
402                 itemtype   => undef,
403                 ccode      => $item1->ccode,
404             }
405         }
406     );
407
408     $pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list;
409     is( scalar @$pickup_locations, $all_count - 1, "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library");
410
411     $builder->build_object(
412         {
413             class => 'Koha::Item::Transfer::Limits',
414             value => {
415                 toBranch   => $library4->branchcode,
416                 fromBranch => $library2->branchcode,
417                 itemtype   => undef,
418                 ccode      => $item1->ccode,
419             }
420         }
421     );
422
423     $pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list;
424     is( scalar @$pickup_locations, $all_count - 2, "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries");
425
426     t::lib::Mocks::mock_preference('UseBranchTransferLimits', 0);
427
428     $schema->storage->txn_rollback;
429 };
430
431 subtest 'deletion' => sub {
432     plan tests => 12;
433
434     $schema->storage->txn_begin;
435
436     my $biblio = $builder->build_sample_biblio();
437
438     my $item = $builder->build_sample_item(
439         {
440             biblionumber => $biblio->biblionumber,
441         }
442     );
443
444     is( ref( $item->move_to_deleted ), 'Koha::Schema::Result::Deleteditem', 'Koha::Item->move_to_deleted should return the Deleted item' )
445       ;    # FIXME This should be Koha::Deleted::Item
446     is( Koha::Old::Items->search({itemnumber => $item->itemnumber})->count, 1, '->move_to_deleted must have moved the item to deleteditem' );
447     $item = $builder->build_sample_item(
448         {
449             biblionumber => $biblio->biblionumber,
450         }
451     );
452     $item->delete;
453     is( Koha::Old::Items->search({itemnumber => $item->itemnumber})->count, 0, '->move_to_deleted must not have moved the item to deleteditem' );
454
455
456     my $library   = $builder->build_object({ class => 'Koha::Libraries' });
457     my $library_2 = $builder->build_object({ class => 'Koha::Libraries' });
458     t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode });
459
460     my $patron = $builder->build_object({class => 'Koha::Patrons'});
461     $item = $builder->build_sample_item({ library => $library->branchcode });
462
463     # book_on_loan
464     C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
465
466     is(
467         $item->safe_to_delete,
468         'book_on_loan',
469         'Koha::Item->safe_to_delete reports item on loan',
470     );
471
472     is(
473         $item->safe_delete,
474         'book_on_loan',
475         'item that is on loan cannot be deleted',
476     );
477
478     AddReturn( $item->barcode, $library->branchcode );
479
480     # book_reserved is tested in t/db_dependent/Reserves.t
481
482     # not_same_branch
483     t::lib::Mocks::mock_preference('IndependentBranches', 1);
484     my $item_2 = $builder->build_sample_item({ library => $library_2->branchcode });
485
486     is(
487         $item_2->safe_to_delete,
488         'not_same_branch',
489         'Koha::Item->safe_to_delete reports IndependentBranches restriction',
490     );
491
492     is(
493         $item_2->safe_delete,
494         'not_same_branch',
495         'IndependentBranches prevents deletion at another branch',
496     );
497
498     # linked_analytics
499
500     { # codeblock to limit scope of $module->mock
501
502         my $module = Test::MockModule->new('C4::Items');
503         $module->mock( GetAnalyticsCount => sub { return 1 } );
504
505         $item->discard_changes;
506         is(
507             $item->safe_to_delete,
508             'linked_analytics',
509             'Koha::Item->safe_to_delete reports linked analytics',
510         );
511
512         is(
513             $item->safe_delete,
514             'linked_analytics',
515             'Linked analytics prevents deletion of item',
516         );
517
518     }
519
520     { # last_item_for_hold
521         C4::Reserves::AddReserve({ branchcode => $patron->branchcode, borrowernumber => $patron->borrowernumber, biblionumber => $item->biblionumber });
522         is( $item->safe_to_delete, 'last_item_for_hold', 'Item cannot be deleted if a biblio-level is placed on the biblio and there is only 1 item attached to the biblio' );
523
524         # With another item attached to the biblio, the item can be deleted
525         $builder->build_sample_item({ biblionumber => $item->biblionumber });
526     }
527
528     is(
529         $item->safe_to_delete,
530         1,
531         'Koha::Item->safe_to_delete shows item safe to delete'
532     );
533
534     $item->safe_delete,
535
536     my $test_item = Koha::Items->find( $item->itemnumber );
537
538     is( $test_item, undef,
539         "Koha::Item->safe_delete should delete item if safe_to_delete returns true"
540     );
541
542     $schema->storage->txn_rollback;
543 };
544
545 subtest 'renewal_branchcode' => sub {
546     plan tests => 13;
547
548     $schema->storage->txn_begin;
549
550     my $item = $builder->build_sample_item();
551     my $branch = $builder->build_object({ class => 'Koha::Libraries' });
552     my $checkout = $builder->build_object({
553         class => 'Koha::Checkouts',
554         value => {
555             itemnumber => $item->itemnumber,
556         }
557     });
558
559
560     C4::Context->interface( 'intranet' );
561     t::lib::Mocks::mock_userenv({ branchcode => $branch->branchcode });
562
563     is( $item->renewal_branchcode, $branch->branchcode, "If interface not opac, we get the branch from context");
564     is( $item->renewal_branchcode({ branch => "PANDA"}), $branch->branchcode, "If interface not opac, we get the branch from context even if we pass one in");
565     C4::Context->set_userenv(51, 'userid4tests', undef, 'firstname', 'surname', undef, undef, 0, undef, undef, undef ); #mock userenv doesn't let us set null branch
566     is( $item->renewal_branchcode({ branch => "PANDA"}), "PANDA", "If interface not opac, we get the branch we pass one in if context not set");
567
568     C4::Context->interface( 'opac' );
569
570     t::lib::Mocks::mock_preference('OpacRenewalBranch', undef);
571     is( $item->renewal_branchcode, 'OPACRenew', "If interface opac and OpacRenewalBranch undef, we get OPACRenew");
572     is( $item->renewal_branchcode({branch=>'COW'}), 'OPACRenew', "If interface opac and OpacRenewalBranch undef, we get OPACRenew even if branch passed");
573
574     t::lib::Mocks::mock_preference('OpacRenewalBranch', 'none');
575     is( $item->renewal_branchcode, '', "If interface opac and OpacRenewalBranch is none, we get blank string");
576     is( $item->renewal_branchcode({branch=>'COW'}), '', "If interface opac and OpacRenewalBranch is none, we get blank string even if branch passed");
577
578     t::lib::Mocks::mock_preference('OpacRenewalBranch', 'checkoutbranch');
579     is( $item->renewal_branchcode, $checkout->branchcode, "If interface opac and OpacRenewalBranch set to checkoutbranch, we get branch of checkout");
580     is( $item->renewal_branchcode({branch=>'MONKEY'}), $checkout->branchcode, "If interface opac and OpacRenewalBranch set to checkoutbranch, we get branch of checkout even if branch passed");
581
582     t::lib::Mocks::mock_preference('OpacRenewalBranch','patronhomebranch');
583     is( $item->renewal_branchcode, $checkout->patron->branchcode, "If interface opac and OpacRenewalBranch set to patronbranch, we get branch of patron");
584     is( $item->renewal_branchcode({branch=>'TURKEY'}), $checkout->patron->branchcode, "If interface opac and OpacRenewalBranch set to patronbranch, we get branch of patron even if branch passed");
585
586     t::lib::Mocks::mock_preference('OpacRenewalBranch','itemhomebranch');
587     is( $item->renewal_branchcode, $item->homebranch, "If interface opac and OpacRenewalBranch set to itemhomebranch, we get homebranch of item");
588     is( $item->renewal_branchcode({branch=>'MANATEE'}), $item->homebranch, "If interface opac and OpacRenewalBranch set to itemhomebranch, we get homebranch of item even if branch passed");
589
590     $schema->storage->txn_rollback;
591 };
592
593 subtest 'Tests for itemtype' => sub {
594     plan tests => 2;
595     $schema->storage->txn_begin;
596
597     my $biblio = $builder->build_sample_biblio;
598     my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' });
599     my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, itype => $itemtype->itemtype });
600
601     t::lib::Mocks::mock_preference('item-level_itypes', 1);
602     is( $item->itemtype->itemtype, $item->itype, 'Pref enabled' );
603     t::lib::Mocks::mock_preference('item-level_itypes', 0);
604     is( $item->itemtype->itemtype, $biblio->biblioitem->itemtype, 'Pref disabled' );
605
606     $schema->storage->txn_rollback;
607 };