Bug 26963: Unit tests
[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 => 8;
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     plan tests => 114;
160
161     $schema->storage->txn_begin;
162
163     my $dbh = C4::Context->dbh;
164
165     # Cleanup database
166     Koha::Holds->search->delete;
167     $dbh->do('DELETE FROM issues');
168     Koha::Patrons->search->delete;
169     Koha::Items->search->delete;
170     Koha::Libraries->search->delete;
171     Koha::CirculationRules->search->delete;
172     Koha::CirculationRules->set_rules(
173         {
174             categorycode => undef,
175             itemtype     => undef,
176             branchcode   => undef,
177             rules        => {
178                 reservesallowed => 25,
179             }
180         }
181     );
182
183     my $root1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1, branchcode => undef } } );
184     my $root2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1, branchcode => undef } } );
185     my $library1 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, } } );
186     my $library2 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, } } );
187     my $library3 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 0, } } );
188     my $library4 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, } } );
189     my $group1_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library1->branchcode } } );
190     my $group1_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library2->branchcode } } );
191
192     my $group2_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } );
193     my $group2_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } );
194
195     my $item1 = $builder->build_sample_item(
196         {
197             homebranch    => $library1->branchcode,
198             holdingbranch => $library2->branchcode,
199             barcode       => '1',
200             itype         => 'test',
201         }
202     )->store;
203
204     my $item3 = $builder->build_sample_item(
205         {
206             homebranch    => $library3->branchcode,
207             holdingbranch => $library4->branchcode,
208             barcode       => '3',
209             itype         => 'test',
210         }
211     )->store;
212
213     my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library1->branchcode, firstname => '1' } } );
214     my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode, firstname => '4' } } );
215
216     my $results = {
217         "1-1-1-any" => 3,
218         "1-1-1-holdgroup" => 2,
219         "1-1-1-patrongroup" => 2,
220         "1-1-1-homebranch" => 1,
221         "1-1-1-holdingbranch" => 1,
222         "1-1-2-any" => 3,
223         "1-1-2-holdgroup" => 2,
224         "1-1-2-patrongroup" => 2,
225         "1-1-2-homebranch" => 1,
226         "1-1-2-holdingbranch" => 1,
227         "1-1-3-any" => 3,
228         "1-1-3-holdgroup" => 2,
229         "1-1-3-patrongroup" => 2,
230         "1-1-3-homebranch" => 1,
231         "1-1-3-holdingbranch" => 1,
232         "1-4-1-any" => 0,
233         "1-4-1-holdgroup" => 0,
234         "1-4-1-patrongroup" => 0,
235         "1-4-1-homebranch" => 0,
236         "1-4-1-holdingbranch" => 0,
237         "1-4-2-any" => 3,
238         "1-4-2-holdgroup" => 2,
239         "1-4-2-patrongroup" => 1,
240         "1-4-2-homebranch" => 1,
241         "1-4-2-holdingbranch" => 1,
242         "1-4-3-any" => 0,
243         "1-4-3-holdgroup" => 0,
244         "1-4-3-patrongroup" => 0,
245         "1-4-3-homebranch" => 0,
246         "1-4-3-holdingbranch" => 0,
247         "3-1-1-any" => 0,
248         "3-1-1-holdgroup" => 0,
249         "3-1-1-patrongroup" => 0,
250         "3-1-1-homebranch" => 0,
251         "3-1-1-holdingbranch" => 0,
252         "3-1-2-any" => 3,
253         "3-1-2-holdgroup" => 1,
254         "3-1-2-patrongroup" => 2,
255         "3-1-2-homebranch" => 0,
256         "3-1-2-holdingbranch" => 1,
257         "3-1-3-any" => 0,
258         "3-1-3-holdgroup" => 0,
259         "3-1-3-patrongroup" => 0,
260         "3-1-3-homebranch" => 0,
261         "3-1-3-holdingbranch" => 0,
262         "3-4-1-any" => 0,
263         "3-4-1-holdgroup" => 0,
264         "3-4-1-patrongroup" => 0,
265         "3-4-1-homebranch" => 0,
266         "3-4-1-holdingbranch" => 0,
267         "3-4-2-any" => 3,
268         "3-4-2-holdgroup" => 1,
269         "3-4-2-patrongroup" => 1,
270         "3-4-2-homebranch" => 0,
271         "3-4-2-holdingbranch" => 1,
272         "3-4-3-any" => 3,
273         "3-4-3-holdgroup" => 1,
274         "3-4-3-patrongroup" => 1,
275         "3-4-3-homebranch" => 0,
276         "3-4-3-holdingbranch" => 1
277     };
278
279     sub _doTest {
280         my ( $item, $patron, $ha, $hfp, $results ) = @_;
281
282         Koha::CirculationRules->set_rules(
283             {
284                 branchcode => undef,
285                 itemtype   => undef,
286                 rules => {
287                     holdallowed => $ha,
288                     hold_fulfillment_policy => $hfp,
289                     returnbranch => 'any'
290                 }
291             }
292         );
293         my @pl = @{ $item->pickup_locations( { patron => $patron} ) };
294         my $ha_value=$ha==3?'holdgroup':($ha==2?'any':'homebranch');
295
296         foreach my $pickup_location (@pl) {
297             is( ref($pickup_location), 'Koha::Library', 'Object type is correct' );
298         }
299         ok(
300             scalar(@pl) == $results->{
301                     $item->barcode . '-'
302                   . $patron->firstname . '-'
303                   . $ha . '-'
304                   . $hfp
305             },
306             'item'
307               . $item->barcode
308               . ', patron'
309               . $patron->firstname
310               . ', holdallowed: '
311               . $ha_value
312               . ', hold_fulfillment_policy: '
313               . $hfp
314               . ' should return '
315               . $results->{
316                     $item->barcode . '-'
317                   . $patron->firstname . '-'
318                   . $ha . '-'
319                   . $hfp
320               }
321               . ' but returns '
322               . scalar(@pl)
323         );
324
325     }
326
327
328     foreach my $item ($item1, $item3) {
329         foreach my $patron ($patron1, $patron4) {
330             #holdallowed 1: homebranch, 2: any, 3: holdgroup
331             foreach my $ha (1, 2, 3) {
332                 foreach my $hfp ('any', 'holdgroup', 'patrongroup', 'homebranch', 'holdingbranch') {
333                     _doTest($item, $patron, $ha, $hfp, $results);
334                 }
335             }
336         }
337     }
338
339     $schema->storage->txn_rollback;
340 };
341
342 subtest '_can_pickup_at' => sub {
343     plan tests =>8;
344
345     $schema->storage->txn_begin;
346
347     t::lib::Mocks::mock_preference('UseBranchTransferLimits', 0);
348
349     my $library1 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, } } );
350     my $library2 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, } } );
351     my $library3 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 0, } } );
352     my $library4 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, } } );
353
354     my $item = $builder->build_sample_item({
355         homebranch => $library1->branchcode,
356         holdingbranch => $library1->branchcode,
357         ccode => "Gollum"
358     });
359
360     my @to = ( $library1, $library2, $library3, $library4 );
361
362     my $pickup_locations = $item->_can_pickup_at({ to => \@to });
363     is( scalar @$pickup_locations, 3, "With no transfer limits we get back the libraries that are pickup locations");
364
365     t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1);
366     t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
367     $builder->build_object( { class => 'Koha::Item::Transfer::Limits', value => {
368         toBranch => $library2->branchcode,
369         fromBranch => $library1->branchcode,
370         itemtype => $item->itype,
371         ccode => undef,
372         }
373     });
374
375     $pickup_locations = $item->_can_pickup_at({ to => \@to });
376     is( scalar @$pickup_locations, 2, "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library");
377
378     $builder->build_object( { class => 'Koha::Item::Transfer::Limits', value => {
379         toBranch => $library4->branchcode,
380         fromBranch => $library1->branchcode,
381         itemtype => $item->itype,
382         ccode => undef,
383         }
384     });
385
386     $pickup_locations = $item->_can_pickup_at({ to => \@to });
387     is( scalar @$pickup_locations, 1, "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 = $item->_can_pickup_at({ to => \@to });
391     is( scalar @$pickup_locations, 3, "With no transfer limits of type ccode we get back the libraries that are pickup locations");
392
393     $builder->build_object( { class => 'Koha::Item::Transfer::Limits', value => {
394         toBranch => $library2->branchcode,
395         fromBranch => $library1->branchcode,
396         itemtype => undef,
397         ccode => $item->ccode,
398         }
399     });
400
401     $pickup_locations = $item->_can_pickup_at({ to => \@to });
402     is( scalar @$pickup_locations, 2, "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library");
403
404     $builder->build_object( { class => 'Koha::Item::Transfer::Limits', value => {
405         toBranch => $library4->branchcode,
406         fromBranch => $library1->branchcode,
407         itemtype => undef,
408         ccode => $item->ccode,
409         }
410     });
411
412     $pickup_locations = $item->_can_pickup_at({ to => \@to });
413     is( scalar @$pickup_locations, 1, "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries");
414
415
416     $pickup_locations = $item->_can_pickup_at({ to => \@to, from => $library2 });
417     is( scalar @$pickup_locations, 3, "With transfer limits enabled but not applying because of 'from' we get back the libraries that are pickup locations");
418
419     t::lib::Mocks::mock_preference('UseBranchTransferLimits', 0);
420
421     $pickup_locations = $item->_can_pickup_at({ to => \@to });
422     is( scalar @$pickup_locations, 3, "With transfer limits disabled we get back the libraries that are pickup locations");
423
424 };
425
426 subtest 'deletion' => sub {
427     plan tests => 12;
428
429     $schema->storage->txn_begin;
430
431     my $biblio = $builder->build_sample_biblio();
432
433     my $item = $builder->build_sample_item(
434         {
435             biblionumber => $biblio->biblionumber,
436         }
437     );
438
439     is( ref( $item->move_to_deleted ), 'Koha::Schema::Result::Deleteditem', 'Koha::Item->move_to_deleted should return the Deleted item' )
440       ;    # FIXME This should be Koha::Deleted::Item
441     is( Koha::Old::Items->search({itemnumber => $item->itemnumber})->count, 1, '->move_to_deleted must have moved the item to deleteditem' );
442     $item = $builder->build_sample_item(
443         {
444             biblionumber => $biblio->biblionumber,
445         }
446     );
447     $item->delete;
448     is( Koha::Old::Items->search({itemnumber => $item->itemnumber})->count, 0, '->move_to_deleted must not have moved the item to deleteditem' );
449
450
451     my $library   = $builder->build_object({ class => 'Koha::Libraries' });
452     my $library_2 = $builder->build_object({ class => 'Koha::Libraries' });
453     t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode });
454
455     my $patron = $builder->build_object({class => 'Koha::Patrons'});
456     $item = $builder->build_sample_item({ library => $library->branchcode });
457
458     # book_on_loan
459     C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
460
461     is(
462         $item->safe_to_delete,
463         'book_on_loan',
464         'Koha::Item->safe_to_delete reports item on loan',
465     );
466
467     is(
468         $item->safe_delete,
469         'book_on_loan',
470         'item that is on loan cannot be deleted',
471     );
472
473     AddReturn( $item->barcode, $library->branchcode );
474
475     # book_reserved is tested in t/db_dependent/Reserves.t
476
477     # not_same_branch
478     t::lib::Mocks::mock_preference('IndependentBranches', 1);
479     my $item_2 = $builder->build_sample_item({ library => $library_2->branchcode });
480
481     is(
482         $item_2->safe_to_delete,
483         'not_same_branch',
484         'Koha::Item->safe_to_delete reports IndependentBranches restriction',
485     );
486
487     is(
488         $item_2->safe_delete,
489         'not_same_branch',
490         'IndependentBranches prevents deletion at another branch',
491     );
492
493     # linked_analytics
494
495     { # codeblock to limit scope of $module->mock
496
497         my $module = Test::MockModule->new('C4::Items');
498         $module->mock( GetAnalyticsCount => sub { return 1 } );
499
500         $item->discard_changes;
501         is(
502             $item->safe_to_delete,
503             'linked_analytics',
504             'Koha::Item->safe_to_delete reports linked analytics',
505         );
506
507         is(
508             $item->safe_delete,
509             'linked_analytics',
510             'Linked analytics prevents deletion of item',
511         );
512
513     }
514
515     { # last_item_for_hold
516         C4::Reserves::AddReserve({ branchcode => $patron->branchcode, borrowernumber => $patron->borrowernumber, biblionumber => $item->biblionumber });
517         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' );
518
519         # With another item attached to the biblio, the item can be deleted
520         $builder->build_sample_item({ biblionumber => $item->biblionumber });
521     }
522
523     is(
524         $item->safe_to_delete,
525         1,
526         'Koha::Item->safe_to_delete shows item safe to delete'
527     );
528
529     $item->safe_delete,
530
531     my $test_item = Koha::Items->find( $item->itemnumber );
532
533     is( $test_item, undef,
534         "Koha::Item->safe_delete should delete item if safe_to_delete returns true"
535     );
536
537     $schema->storage->txn_rollback;
538 };
539
540 subtest 'renewal_branchcode' => sub {
541     plan tests => 13;
542
543     $schema->storage->txn_begin;
544
545     my $item = $builder->build_sample_item();
546     my $branch = $builder->build_object({ class => 'Koha::Libraries' });
547     my $checkout = $builder->build_object({
548         class => 'Koha::Checkouts',
549         value => {
550             itemnumber => $item->itemnumber,
551         }
552     });
553
554
555     C4::Context->interface( 'intranet' );
556     t::lib::Mocks::mock_userenv({ branchcode => $branch->branchcode });
557
558     is( $item->renewal_branchcode, $branch->branchcode, "If interface not opac, we get the branch from context");
559     is( $item->renewal_branchcode({ branch => "PANDA"}), $branch->branchcode, "If interface not opac, we get the branch from context even if we pass one in");
560     C4::Context->set_userenv(51, 'userid4tests', undef, 'firstname', 'surname', undef, undef, 0, undef, undef, undef ); #mock userenv doesn't let us set null branch
561     is( $item->renewal_branchcode({ branch => "PANDA"}), "PANDA", "If interface not opac, we get the branch we pass one in if context not set");
562
563     C4::Context->interface( 'opac' );
564
565     t::lib::Mocks::mock_preference('OpacRenewalBranch', undef);
566     is( $item->renewal_branchcode, 'OPACRenew', "If interface opac and OpacRenewalBranch undef, we get OPACRenew");
567     is( $item->renewal_branchcode({branch=>'COW'}), 'OPACRenew', "If interface opac and OpacRenewalBranch undef, we get OPACRenew even if branch passed");
568
569     t::lib::Mocks::mock_preference('OpacRenewalBranch', 'none');
570     is( $item->renewal_branchcode, '', "If interface opac and OpacRenewalBranch is none, we get blank string");
571     is( $item->renewal_branchcode({branch=>'COW'}), '', "If interface opac and OpacRenewalBranch is none, we get blank string even if branch passed");
572
573     t::lib::Mocks::mock_preference('OpacRenewalBranch', 'checkoutbranch');
574     is( $item->renewal_branchcode, $checkout->branchcode, "If interface opac and OpacRenewalBranch set to checkoutbranch, we get branch of checkout");
575     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");
576
577     t::lib::Mocks::mock_preference('OpacRenewalBranch','patronhomebranch');
578     is( $item->renewal_branchcode, $checkout->patron->branchcode, "If interface opac and OpacRenewalBranch set to patronbranch, we get branch of patron");
579     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");
580
581     t::lib::Mocks::mock_preference('OpacRenewalBranch','itemhomebranch');
582     is( $item->renewal_branchcode, $item->homebranch, "If interface opac and OpacRenewalBranch set to itemhomebranch, we get homebranch of item");
583     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");
584
585     $schema->storage->txn_rollback;
586 };
587
588 subtest 'Tests for itemtype' => sub {
589     plan tests => 2;
590     $schema->storage->txn_begin;
591
592     my $biblio = $builder->build_sample_biblio;
593     my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' });
594     my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, itype => $itemtype->itemtype });
595
596     t::lib::Mocks::mock_preference('item-level_itypes', 1);
597     is( $item->itemtype->itemtype, $item->itype, 'Pref enabled' );
598     t::lib::Mocks::mock_preference('item-level_itypes', 0);
599     is( $item->itemtype->itemtype, $biblio->biblioitem->itemtype, 'Pref disabled' );
600
601     $schema->storage->txn_rollback;
602 };