use Test::More tests => 3;
use Test::MockModule;
-use t::lib::TestBuilder;
+use Test::Warn;
use t::lib::Mocks;
+use t::lib::TestBuilder;
+
use C4::Biblio;
use C4::Circulation;
use C4::Items;
subtest "AddReturn logging on statistics table (item-level_itypes=1)" => sub {
- plan tests => 2;
+ plan tests => 4;
# Set item-level item types
t::lib::Mocks::mock_preference( "item-level_itypes", 1 );
is( $stat->itemtype, $ilevel_itemtype,
"item-level itype recorded on statistics for return");
-
- AddIssue( $borrower, $item_without_itemtype->{ barcode } );
- AddReturn( $item_without_itemtype->{ barcode }, $branch );
+ warning_like { AddIssue( $borrower, $item_without_itemtype->{ barcode } ) }
+ qr/^item-level_itypes set but no itemtype set for item/,
+ 'Item without itemtype set raises warning on AddIssue';
+ warning_like { AddReturn( $item_without_itemtype->{ barcode }, $branch ) }
+ qr/^item-level_itypes set but no itemtype set for item/,
+ 'Item without itemtype set raises warning on AddReturn';
# Test biblio-level itemtype was recorded on the 'statistics' table
$stat = $schema->resultset('Statistic')->search({
branch => $branch,
my $item3_record = new MARC::Record;
$item3_record->append_fields(
- new MARC::Field($itemfield, '', '', 'z' => 'foobar')
+ new MARC::Field(
+ $itemfield, '', '',
+ 'z' => 'foobar',
+ 'y' => $itemtype->{itemtype}
+ )
);
my (undef, undef, $item3_itemnumber) = AddItemFromMarc($item3_record,
$biblionumber);
}
});
+ my $mss_itemtype = $builder->build({
+ source => 'MarcSubfieldStructure',
+ value => {
+ frameworkcode => $framework->{frameworkcode},
+ kohafield => 'items.itype',
+ tagfield => '952',
+ tagsubfield => 'y',
+ }
+ });
+
+ my $itemtype = $builder->build({ source => 'Itemtype' })->{itemtype};
+
# Create a record with a barcode
my ($biblionumber) = get_biblio( $framework->{frameworkcode} );
my $item_record = new MARC::Record;
my $barcode_field = MARC::Field->new(
'952', ' ', ' ',
p => $a_barcode,
+ y => $itemtype
+ );
+ my $itemtype_field = MARC::Field->new(
+ '952', ' ', ' ',
+ y => $itemtype
);
$item_record->append_fields( $barcode_field );
my (undef, undef, $item_itemnumber) = AddItemFromMarc($item_record, $biblionumber);
-
+ use Data::Printer colored => 1;
# Make sure everything has been set up
my $item = GetItem($item_itemnumber);
is( $item->{barcode}, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' );
# Delete the barcode field and save the record
$item_record->delete_fields( $barcode_field );
+ $item_record->append_fields( $itemtype_field ); # itemtype is mandatory
ModItemFromMarc($item_record, $biblionumber, $item_itemnumber);
$item = GetItem($item_itemnumber);
is( $item->{barcode}, undef, 'The default value should have been set to the barcode, the field is mapped to a kohafield' );