Lines 56-67
subtest 'General Add, Get and Del tests' => sub {
Link Here
|
56 |
|
56 |
|
57 |
# Create a biblio instance for testing |
57 |
# Create a biblio instance for testing |
58 |
t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); |
58 |
t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); |
59 |
my ($bibnum, $bibitemnum) = get_biblio(); |
59 |
my $biblio = $builder->gimme_a_biblio(); |
60 |
|
60 |
|
61 |
# Add an item. |
61 |
# Add an item. |
62 |
my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, itype => $itemtype->{itemtype} } , $bibnum); |
62 |
my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, itype => $itemtype->{itemtype} } , $biblio->biblionumber); |
63 |
cmp_ok($item_bibnum, '==', $bibnum, "New item is linked to correct biblionumber."); |
63 |
cmp_ok($item_bibnum, '==', $biblio->biblionumber, "New item is linked to correct biblionumber."); |
64 |
cmp_ok($item_bibitemnum, '==', $bibitemnum, "New item is linked to correct biblioitemnumber."); |
64 |
cmp_ok($item_bibitemnum, '==', $biblio->biblioitem->biblioitemnumber, "New item is linked to correct biblioitemnumber."); |
65 |
|
65 |
|
66 |
# Get item. |
66 |
# Get item. |
67 |
my $getitem = GetItem($itemnumber); |
67 |
my $getitem = GetItem($itemnumber); |
Lines 74-102
subtest 'General Add, Get and Del tests' => sub {
Link Here
|
74 |
# Do not modify anything, and do not explode! |
74 |
# Do not modify anything, and do not explode! |
75 |
my $dbh = C4::Context->dbh; |
75 |
my $dbh = C4::Context->dbh; |
76 |
local $dbh->{RaiseError} = 1; |
76 |
local $dbh->{RaiseError} = 1; |
77 |
ModItem({}, $bibnum, $itemnumber); |
77 |
ModItem({}, $biblio->biblionumber, $itemnumber); |
78 |
|
78 |
|
79 |
# Modify item; setting barcode. |
79 |
# Modify item; setting barcode. |
80 |
ModItem({ barcode => '987654321' }, $bibnum, $itemnumber); |
80 |
ModItem({ barcode => '987654321' }, $biblio->biblionumber, $itemnumber); |
81 |
my $moditem = GetItem($itemnumber); |
81 |
my $moditem = GetItem($itemnumber); |
82 |
cmp_ok($moditem->{'barcode'}, '==', '987654321', 'Modified item barcode successfully to: '.$moditem->{'barcode'} . '.'); |
82 |
cmp_ok($moditem->{'barcode'}, '==', '987654321', 'Modified item barcode successfully to: '.$moditem->{'barcode'} . '.'); |
83 |
|
83 |
|
84 |
# Delete item. |
84 |
# Delete item. |
85 |
DelItem({ biblionumber => $bibnum, itemnumber => $itemnumber }); |
85 |
DelItem({ biblionumber => $biblio->biblionumber, itemnumber => $itemnumber }); |
86 |
my $getdeleted = GetItem($itemnumber); |
86 |
my $getdeleted = GetItem($itemnumber); |
87 |
is($getdeleted->{'itemnumber'}, undef, "Item deleted as expected."); |
87 |
is($getdeleted->{'itemnumber'}, undef, "Item deleted as expected."); |
88 |
|
88 |
|
89 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, permanent_location => 'my permanent location', itype => $itemtype->{itemtype} } , $bibnum); |
89 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, permanent_location => 'my permanent location', itype => $itemtype->{itemtype} } , $biblio->biblionumber); |
90 |
$getitem = GetItem($itemnumber); |
90 |
$getitem = GetItem($itemnumber); |
91 |
is( $getitem->{location}, $location, "The location should not have been modified" ); |
91 |
is( $getitem->{location}, $location, "The location should not have been modified" ); |
92 |
is( $getitem->{permanent_location}, 'my permanent location', "The permanent_location should not have modified" ); |
92 |
is( $getitem->{permanent_location}, 'my permanent location', "The permanent_location should not have modified" ); |
93 |
|
93 |
|
94 |
ModItem({ location => $location }, $bibnum, $itemnumber); |
94 |
ModItem({ location => $location }, $biblio->biblionumber, $itemnumber); |
95 |
$getitem = GetItem($itemnumber); |
95 |
$getitem = GetItem($itemnumber); |
96 |
is( $getitem->{location}, $location, "The location should have been set to correct location" ); |
96 |
is( $getitem->{location}, $location, "The location should have been set to correct location" ); |
97 |
is( $getitem->{permanent_location}, $location, "The permanent_location should have been set to location" ); |
97 |
is( $getitem->{permanent_location}, $location, "The permanent_location should have been set to location" ); |
98 |
|
98 |
|
99 |
ModItem({ location => 'CART' }, $bibnum, $itemnumber); |
99 |
ModItem({ location => 'CART' }, $biblio->biblionumber, $itemnumber); |
100 |
$getitem = GetItem($itemnumber); |
100 |
$getitem = GetItem($itemnumber); |
101 |
is( $getitem->{location}, 'CART', "The location should have been set to CART" ); |
101 |
is( $getitem->{location}, 'CART', "The location should have been set to CART" ); |
102 |
is( $getitem->{permanent_location}, $location, "The permanent_location should not have been set to CART" ); |
102 |
is( $getitem->{permanent_location}, $location, "The permanent_location should not have been set to CART" ); |
Lines 168-174
subtest 'GetHiddenItemnumbers tests' => sub {
Link Here
|
168 |
|
168 |
|
169 |
# Create a new biblio |
169 |
# Create a new biblio |
170 |
t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); |
170 |
t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); |
171 |
my ($biblionumber, $biblioitemnumber) = get_biblio(); |
171 |
my $biblio = $builder->gimme_a_biblio(); |
172 |
|
172 |
|
173 |
# Add two items |
173 |
# Add two items |
174 |
my ( $item1_bibnum, $item1_bibitemnum, $item1_itemnumber ) = AddItem( |
174 |
my ( $item1_bibnum, $item1_bibitemnum, $item1_itemnumber ) = AddItem( |
Lines 178-184
subtest 'GetHiddenItemnumbers tests' => sub {
Link Here
|
178 |
withdrawn => 1, |
178 |
withdrawn => 1, |
179 |
itype => $itemtype->{itemtype}, |
179 |
itype => $itemtype->{itemtype}, |
180 |
}, |
180 |
}, |
181 |
$biblionumber |
181 |
$biblio->biblionumber |
182 |
); |
182 |
); |
183 |
my ( $item2_bibnum, $item2_bibitemnum, $item2_itemnumber ) = AddItem( |
183 |
my ( $item2_bibnum, $item2_bibitemnum, $item2_itemnumber ) = AddItem( |
184 |
{ |
184 |
{ |
Lines 187-193
subtest 'GetHiddenItemnumbers tests' => sub {
Link Here
|
187 |
withdrawn => 0, |
187 |
withdrawn => 0, |
188 |
itype => $itemtype->{itemtype}, |
188 |
itype => $itemtype->{itemtype}, |
189 |
}, |
189 |
}, |
190 |
$biblionumber |
190 |
$biblio->biblionumber |
191 |
); |
191 |
); |
192 |
|
192 |
|
193 |
my $opachiddenitems; |
193 |
my $opachiddenitems; |
Lines 266-272
subtest 'GetItemsInfo tests' => sub {
Link Here
|
266 |
}); |
266 |
}); |
267 |
|
267 |
|
268 |
# Add a biblio |
268 |
# Add a biblio |
269 |
my ($biblionumber, $biblioitemnumber) = get_biblio(); |
269 |
my $biblio = $builder->gimme_a_biblio(); |
270 |
# Add an item |
270 |
# Add an item |
271 |
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem( |
271 |
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem( |
272 |
{ |
272 |
{ |
Lines 274-280
subtest 'GetItemsInfo tests' => sub {
Link Here
|
274 |
holdingbranch => $library2->{branchcode}, |
274 |
holdingbranch => $library2->{branchcode}, |
275 |
itype => $itemtype->{itemtype}, |
275 |
itype => $itemtype->{itemtype}, |
276 |
}, |
276 |
}, |
277 |
$biblionumber |
277 |
$biblio->biblionumber |
278 |
); |
278 |
); |
279 |
|
279 |
|
280 |
my $library = Koha::Libraries->find( $library1->{branchcode} ); |
280 |
my $library = Koha::Libraries->find( $library1->{branchcode} ); |
Lines 285-291
subtest 'GetItemsInfo tests' => sub {
Link Here
|
285 |
$library->opac_info("holdingbranch OPAC info"); |
285 |
$library->opac_info("holdingbranch OPAC info"); |
286 |
$library->store; |
286 |
$library->store; |
287 |
|
287 |
|
288 |
my @results = GetItemsInfo( $biblionumber ); |
288 |
my @results = GetItemsInfo( $biblio->biblionumber ); |
289 |
ok( @results, 'GetItemsInfo returns results'); |
289 |
ok( @results, 'GetItemsInfo returns results'); |
290 |
is( $results[0]->{ home_branch_opac_info }, "homebranch OPAC info", |
290 |
is( $results[0]->{ home_branch_opac_info }, "homebranch OPAC info", |
291 |
'GetItemsInfo returns the correct home branch OPAC info notice' ); |
291 |
'GetItemsInfo returns the correct home branch OPAC info notice' ); |
Lines 357-363
subtest 'SearchItems test' => sub {
Link Here
|
357 |
t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); |
357 |
t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); |
358 |
my $cpl_items_before = SearchItemsByField( 'homebranch', $library1->{branchcode}); |
358 |
my $cpl_items_before = SearchItemsByField( 'homebranch', $library1->{branchcode}); |
359 |
|
359 |
|
360 |
my ($biblionumber) = get_biblio(); |
360 |
my $biblio = $builder->gimme_a_biblio(); |
361 |
|
361 |
|
362 |
my (undef, $initial_items_count) = SearchItems(undef, {rows => 1}); |
362 |
my (undef, $initial_items_count) = SearchItems(undef, {rows => 1}); |
363 |
|
363 |
|
Lines 366-377
subtest 'SearchItems test' => sub {
Link Here
|
366 |
homebranch => $library1->{branchcode}, |
366 |
homebranch => $library1->{branchcode}, |
367 |
holdingbranch => $library1->{branchcode}, |
367 |
holdingbranch => $library1->{branchcode}, |
368 |
itype => $itemtype->{itemtype}, |
368 |
itype => $itemtype->{itemtype}, |
369 |
}, $biblionumber); |
369 |
}, $biblio->biblionumber); |
370 |
my (undef, undef, $item2_itemnumber) = AddItem({ |
370 |
my (undef, undef, $item2_itemnumber) = AddItem({ |
371 |
homebranch => $library2->{branchcode}, |
371 |
homebranch => $library2->{branchcode}, |
372 |
holdingbranch => $library2->{branchcode}, |
372 |
holdingbranch => $library2->{branchcode}, |
373 |
itype => $itemtype->{itemtype}, |
373 |
itype => $itemtype->{itemtype}, |
374 |
}, $biblionumber); |
374 |
}, $biblio->biblionumber); |
375 |
|
375 |
|
376 |
my ($items, $total_results); |
376 |
my ($items, $total_results); |
377 |
|
377 |
|
Lines 476-482
subtest 'SearchItems test' => sub {
Link Here
|
476 |
) |
476 |
) |
477 |
); |
477 |
); |
478 |
my (undef, undef, $item3_itemnumber) = AddItemFromMarc($item3_record, |
478 |
my (undef, undef, $item3_itemnumber) = AddItemFromMarc($item3_record, |
479 |
$biblionumber); |
479 |
$biblio->biblionumber); |
480 |
|
480 |
|
481 |
# Search item where item subfield z is "foobar" |
481 |
# Search item where item subfield z is "foobar" |
482 |
$filter = { |
482 |
$filter = { |
Lines 498-504
subtest 'SearchItems test' => sub {
Link Here
|
498 |
$cache->clear_from_cache("default_value_for_mod_marc-"); |
498 |
$cache->clear_from_cache("default_value_for_mod_marc-"); |
499 |
$cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode"); |
499 |
$cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode"); |
500 |
|
500 |
|
501 |
ModItemFromMarc($item3_record, $biblionumber, $item3_itemnumber); |
501 |
ModItemFromMarc($item3_record, $biblio->biblionumber, $item3_itemnumber); |
502 |
|
502 |
|
503 |
# Make sure the link is used |
503 |
# Make sure the link is used |
504 |
my $item3 = GetItem($item3_itemnumber); |
504 |
my $item3 = GetItem($item3_itemnumber); |
Lines 534-547
subtest 'Koha::Item(s) tests' => sub {
Link Here
|
534 |
|
534 |
|
535 |
# Create a biblio and item for testing |
535 |
# Create a biblio and item for testing |
536 |
t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); |
536 |
t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); |
537 |
my ($bibnum, $bibitemnum) = get_biblio(); |
537 |
my $biblio = $builder->gimme_a_biblio(); |
538 |
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem( |
538 |
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem( |
539 |
{ |
539 |
{ |
540 |
homebranch => $library1->{branchcode}, |
540 |
homebranch => $library1->{branchcode}, |
541 |
holdingbranch => $library2->{branchcode}, |
541 |
holdingbranch => $library2->{branchcode}, |
542 |
itype => $itemtype->{itemtype}, |
542 |
itype => $itemtype->{itemtype}, |
543 |
}, |
543 |
}, |
544 |
$bibnum |
544 |
$biblio->biblionumber |
545 |
); |
545 |
); |
546 |
|
546 |
|
547 |
# Get item. |
547 |
# Get item. |
Lines 575-581
subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub {
Link Here
|
575 |
source => 'Itemtype', |
575 |
source => 'Itemtype', |
576 |
}); |
576 |
}); |
577 |
|
577 |
|
578 |
my ( $biblionumber, $biblioitemnumber ) = get_biblio(); |
578 |
my $biblio = $builder->gimme_a_biblio(); |
579 |
my $item_infos = [ |
579 |
my $item_infos = [ |
580 |
{ homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} }, |
580 |
{ homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} }, |
581 |
{ homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} }, |
581 |
{ homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} }, |
Lines 598-604
subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub {
Link Here
|
598 |
holdingbranch => $item_info->{holdingbanch}, |
598 |
holdingbranch => $item_info->{holdingbanch}, |
599 |
itype => $itemtype->{itemtype}, |
599 |
itype => $itemtype->{itemtype}, |
600 |
}, |
600 |
}, |
601 |
$biblionumber |
601 |
$biblio->biblionumber |
602 |
); |
602 |
); |
603 |
push @itemnumbers, $itemnumber; |
603 |
push @itemnumbers, $itemnumber; |
604 |
} |
604 |
} |
Lines 608-639
subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub {
Link Here
|
608 |
|
608 |
|
609 |
my ($itemfield) = |
609 |
my ($itemfield) = |
610 |
C4::Biblio::GetMarcFromKohaField( 'items.itemnumber', '' ); |
610 |
C4::Biblio::GetMarcFromKohaField( 'items.itemnumber', '' ); |
611 |
my $record = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber }); |
611 |
my $record = C4::Biblio::GetMarcBiblio({ biblionumber => $biblio->biblionumber }); |
612 |
warning_is { C4::Biblio::EmbedItemsInMarcBiblio() } |
612 |
warning_is { C4::Biblio::EmbedItemsInMarcBiblio() } |
613 |
{ carped => 'EmbedItemsInMarcBiblio: No MARC record passed' }, |
613 |
{ carped => 'EmbedItemsInMarcBiblio: No MARC record passed' }, |
614 |
'Should carp is no record passed.'; |
614 |
'Should carp is no record passed.'; |
615 |
|
615 |
|
616 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
616 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
617 |
marc_record => $record, |
617 |
marc_record => $record, |
618 |
biblionumber => $biblionumber }); |
618 |
biblionumber => $biblio->biblionumber }); |
619 |
my @items = $record->field($itemfield); |
619 |
my @items = $record->field($itemfield); |
620 |
is( scalar @items, $number_of_items, 'Should return all items' ); |
620 |
is( scalar @items, $number_of_items, 'Should return all items' ); |
621 |
|
621 |
|
622 |
my $marc_with_items = C4::Biblio::GetMarcBiblio({ |
622 |
my $marc_with_items = C4::Biblio::GetMarcBiblio({ |
623 |
biblionumber => $biblionumber, |
623 |
biblionumber => $biblio->biblionumber, |
624 |
embed_items => 1 }); |
624 |
embed_items => 1 }); |
625 |
is_deeply( $record, $marc_with_items, 'A direct call to GetMarcBiblio with items matches'); |
625 |
is_deeply( $record, $marc_with_items, 'A direct call to GetMarcBiblio with items matches'); |
626 |
|
626 |
|
627 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
627 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
628 |
marc_record => $record, |
628 |
marc_record => $record, |
629 |
biblionumber => $biblionumber, |
629 |
biblionumber => $biblio->biblionumber, |
630 |
item_numbers => [ $itemnumbers[1], $itemnumbers[3] ] }); |
630 |
item_numbers => [ $itemnumbers[1], $itemnumbers[3] ] }); |
631 |
@items = $record->field($itemfield); |
631 |
@items = $record->field($itemfield); |
632 |
is( scalar @items, 2, 'Should return all items present in the list' ); |
632 |
is( scalar @items, 2, 'Should return all items present in the list' ); |
633 |
|
633 |
|
634 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
634 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
635 |
marc_record => $record, |
635 |
marc_record => $record, |
636 |
biblionumber => $biblionumber, |
636 |
biblionumber => $biblio->biblionumber, |
637 |
opac => 1 }); |
637 |
opac => 1 }); |
638 |
@items = $record->field($itemfield); |
638 |
@items = $record->field($itemfield); |
639 |
is( scalar @items, $number_of_items, 'Should return all items for opac' ); |
639 |
is( scalar @items, $number_of_items, 'Should return all items for opac' ); |
Lines 644-650
subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub {
Link Here
|
644 |
|
644 |
|
645 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
645 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
646 |
marc_record => $record, |
646 |
marc_record => $record, |
647 |
biblionumber => $biblionumber }); |
647 |
biblionumber => $biblio->biblionumber }); |
648 |
@items = $record->field($itemfield); |
648 |
@items = $record->field($itemfield); |
649 |
is( scalar @items, |
649 |
is( scalar @items, |
650 |
$number_of_items, |
650 |
$number_of_items, |
Lines 652-658
subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub {
Link Here
|
652 |
|
652 |
|
653 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
653 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
654 |
marc_record => $record, |
654 |
marc_record => $record, |
655 |
biblionumber => $biblionumber, |
655 |
biblionumber => $biblio->biblionumber, |
656 |
opac => 1 }); |
656 |
opac => 1 }); |
657 |
@items = $record->field($itemfield); |
657 |
@items = $record->field($itemfield); |
658 |
is( |
658 |
is( |
Lines 666-672
subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub {
Link Here
|
666 |
t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems ); |
666 |
t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems ); |
667 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
667 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
668 |
marc_record => $record, |
668 |
marc_record => $record, |
669 |
biblionumber => $biblionumber, |
669 |
biblionumber => $biblio->biblionumber, |
670 |
opac => 1 }); |
670 |
opac => 1 }); |
671 |
@items = $record->field($itemfield); |
671 |
@items = $record->field($itemfield); |
672 |
is( |
672 |
is( |
Lines 702-708
subtest 'C4::Items::_build_default_values_for_mod_marc' => sub {
Link Here
|
702 |
my $itemtype = $builder->build({ source => 'Itemtype' })->{itemtype}; |
702 |
my $itemtype = $builder->build({ source => 'Itemtype' })->{itemtype}; |
703 |
|
703 |
|
704 |
# Create a record with a barcode |
704 |
# Create a record with a barcode |
705 |
my ($biblionumber) = get_biblio( $framework->{frameworkcode} ); |
705 |
my $biblio = $builder->gimme_a_biblio({ frameworkcode => $framework->{frameworkcode} }); |
706 |
my $item_record = new MARC::Record; |
706 |
my $item_record = new MARC::Record; |
707 |
my $a_barcode = 'a barcode'; |
707 |
my $a_barcode = 'a barcode'; |
708 |
my $barcode_field = MARC::Field->new( |
708 |
my $barcode_field = MARC::Field->new( |
Lines 715-721
subtest 'C4::Items::_build_default_values_for_mod_marc' => sub {
Link Here
|
715 |
y => $itemtype |
715 |
y => $itemtype |
716 |
); |
716 |
); |
717 |
$item_record->append_fields( $barcode_field ); |
717 |
$item_record->append_fields( $barcode_field ); |
718 |
my (undef, undef, $item_itemnumber) = AddItemFromMarc($item_record, $biblionumber); |
718 |
my (undef, undef, $item_itemnumber) = AddItemFromMarc($item_record, $biblio->biblionumber); |
719 |
|
719 |
|
720 |
# Make sure everything has been set up |
720 |
# Make sure everything has been set up |
721 |
my $item = GetItem($item_itemnumber); |
721 |
my $item = GetItem($item_itemnumber); |
Lines 724-736
subtest 'C4::Items::_build_default_values_for_mod_marc' => sub {
Link Here
|
724 |
# Delete the barcode field and save the record |
724 |
# Delete the barcode field and save the record |
725 |
$item_record->delete_fields( $barcode_field ); |
725 |
$item_record->delete_fields( $barcode_field ); |
726 |
$item_record->append_fields( $itemtype_field ); # itemtype is mandatory |
726 |
$item_record->append_fields( $itemtype_field ); # itemtype is mandatory |
727 |
ModItemFromMarc($item_record, $biblionumber, $item_itemnumber); |
727 |
ModItemFromMarc($item_record, $biblio->biblionumber, $item_itemnumber); |
728 |
$item = GetItem($item_itemnumber); |
728 |
$item = GetItem($item_itemnumber); |
729 |
is( $item->{barcode}, undef, 'The default value should have been set to the barcode, the field is mapped to a kohafield' ); |
729 |
is( $item->{barcode}, undef, 'The default value should have been set to the barcode, the field is mapped to a kohafield' ); |
730 |
|
730 |
|
731 |
# Re-add the barcode field and save the record |
731 |
# Re-add the barcode field and save the record |
732 |
$item_record->append_fields( $barcode_field ); |
732 |
$item_record->append_fields( $barcode_field ); |
733 |
ModItemFromMarc($item_record, $biblionumber, $item_itemnumber); |
733 |
ModItemFromMarc($item_record, $biblio->biblionumber, $item_itemnumber); |
734 |
$item = GetItem($item_itemnumber); |
734 |
$item = GetItem($item_itemnumber); |
735 |
is( $item->{barcode}, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' ); |
735 |
is( $item->{barcode}, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' ); |
736 |
|
736 |
|
Lines 751-757
subtest 'C4::Items::_build_default_values_for_mod_marc' => sub {
Link Here
|
751 |
); |
751 |
); |
752 |
$item_record->append_fields( $another_barcode_field ); |
752 |
$item_record->append_fields( $another_barcode_field ); |
753 |
# The DB value should not have been updated |
753 |
# The DB value should not have been updated |
754 |
ModItemFromMarc($item_record, $biblionumber, $item_itemnumber); |
754 |
ModItemFromMarc($item_record, $biblio->biblionumber, $item_itemnumber); |
755 |
$item = GetItem($item_itemnumber); |
755 |
$item = GetItem($item_itemnumber); |
756 |
is ( $item->{barcode}, $a_barcode, 'items.barcode is not mapped anymore, so the DB column has not been updated' ); |
756 |
is ( $item->{barcode}, $a_barcode, 'items.barcode is not mapped anymore, so the DB column has not been updated' ); |
757 |
|
757 |
|
Lines 848-871
subtest 'Test logging for ModItem' => sub {
Link Here
|
848 |
|
848 |
|
849 |
# Create a biblio instance for testing |
849 |
# Create a biblio instance for testing |
850 |
t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); |
850 |
t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); |
851 |
my ($bibnum, $bibitemnum) = get_biblio(); |
851 |
my $biblio = $builder->gimme_a_biblio(); |
852 |
|
852 |
|
853 |
# Add an item. |
853 |
# Add an item. |
854 |
my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, itype => $itemtype->{itemtype} } , $bibnum); |
854 |
my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, itype => $itemtype->{itemtype} } , $biblio->biblionumber); |
855 |
|
855 |
|
856 |
# False means no logging |
856 |
# False means no logging |
857 |
$schema->resultset('ActionLog')->search()->delete(); |
857 |
$schema->resultset('ActionLog')->search()->delete(); |
858 |
ModItem({ location => $location }, $bibnum, $itemnumber, { log_action => 0 }); |
858 |
ModItem({ location => $location }, $biblio->biblionumber, $itemnumber, { log_action => 0 }); |
859 |
is( $schema->resultset('ActionLog')->count(), 0, 'False value does not trigger logging' ); |
859 |
is( $schema->resultset('ActionLog')->count(), 0, 'False value does not trigger logging' ); |
860 |
|
860 |
|
861 |
# True means logging |
861 |
# True means logging |
862 |
$schema->resultset('ActionLog')->search()->delete(); |
862 |
$schema->resultset('ActionLog')->search()->delete(); |
863 |
ModItem({ location => $location }, $bibnum, $itemnumber, { log_action => 1 }); |
863 |
ModItem({ location => $location }, $biblio->biblionumber, $itemnumber, { log_action => 1 }); |
864 |
is( $schema->resultset('ActionLog')->count(), 1, 'True value does trigger logging' ); |
864 |
is( $schema->resultset('ActionLog')->count(), 1, 'True value does trigger logging' ); |
865 |
|
865 |
|
866 |
# Undefined defaults to true |
866 |
# Undefined defaults to true |
867 |
$schema->resultset('ActionLog')->search()->delete(); |
867 |
$schema->resultset('ActionLog')->search()->delete(); |
868 |
ModItem({ location => $location }, $bibnum, $itemnumber); |
868 |
ModItem({ location => $location }, $biblio->biblionumber, $itemnumber); |
869 |
is( $schema->resultset('ActionLog')->count(), 1, 'Undefined value defaults to true, triggers logging' ); |
869 |
is( $schema->resultset('ActionLog')->count(), 1, 'Undefined value defaults to true, triggers logging' ); |
870 |
|
870 |
|
871 |
$schema->storage->txn_rollback; |
871 |
$schema->storage->txn_rollback; |
Lines 955-970
subtest 'Split subfields in Item2Marc (Bug 21774)' => sub {
Link Here
|
955 |
|
955 |
|
956 |
$schema->storage->txn_rollback; |
956 |
$schema->storage->txn_rollback; |
957 |
}; |
957 |
}; |
958 |
|
|
|
959 |
# Helper method to set up a Biblio. |
960 |
sub get_biblio { |
961 |
my ( $frameworkcode ) = @_; |
962 |
$frameworkcode //= ''; |
963 |
my $bib = MARC::Record->new(); |
964 |
$bib->append_fields( |
965 |
MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'), |
966 |
MARC::Field->new('245', ' ', ' ', a => 'Silence in the library'), |
967 |
); |
968 |
my ($bibnum, $bibitemnum) = AddBiblio($bib, $frameworkcode); |
969 |
return ($bibnum, $bibitemnum); |
970 |
} |