use Koha::Database;
use Koha::Caches;
use Koha::MarcSubfieldStructures;
-use C4::Biblio;
+use C4::Biblio qw( TransformMarcToKoha TransformMarcToKohaOneField );
my $schema = Koha::Database->new->schema;
$schema->storage->txn_begin;
};
subtest 'Testing _adjust_pubyear' => sub {
- plan tests => 10;
+ plan tests => 12;
is( C4::Biblio::_adjust_pubyear('2004 c2000 2007'), 2000, 'First cYEAR' );
is( C4::Biblio::_adjust_pubyear('2004 2000 2007'), 2004, 'First year' );
is( C4::Biblio::_adjust_pubyear('197X'), 1970, '197X on its own' );
is( C4::Biblio::_adjust_pubyear('1...'), 1000, '1... on its own' );
is( C4::Biblio::_adjust_pubyear('12?? 13xx'), 1200, '12?? first' );
- is( C4::Biblio::_adjust_pubyear('12? 1x'), '12? 1x', 'Too short' );
- is( C4::Biblio::_adjust_pubyear('198-'), '198-', 'Missing question mark' );
+ is( C4::Biblio::_adjust_pubyear('12? 1x'), undef, 'Too short return nothing as data must be int' );
+ is( C4::Biblio::_adjust_pubyear('198-'), undef, 'Missing question mark, nothing is returned as data must be int' );
is( C4::Biblio::_adjust_pubyear('198-?'), '1980', '198-?' );
+ is( C4::Biblio::_adjust_pubyear('1981-'), '1981', 'Date range returns first date' );
+ is( C4::Biblio::_adjust_pubyear('broken'), undef, 'Non-matchign data returns nothing as the field must be int' );
};
subtest 'Test repeatable subfields' => sub {
- plan tests => 2;
+ plan tests => 5;
# Make 510x repeatable and 510y not
Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '510' })->delete;
my $result = C4::Biblio::TransformMarcToKoha( $marc );
is( $result->{test}, '1 | 2', 'Check 510x for two values' );
is( $result->{norepeat}, '3 | 4 | 5', 'Check 510y too' );
+
+ Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '510', tagsubfield => 'a', kohafield => 'biblio.field1' })->store;
+ Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
+ $marc->append_fields( MARC::Field->new( '510', '', '', a => '1' ) ); # actually, we should only have one $y (BZ 24652)
+
+ $result = C4::Biblio::TransformMarcToKoha( $marc, '', 'no_items' );
+ is( $result->{test}, undef, 'Item field not returned when "no_items" passed' );
+ is( $result->{norepeat}, undef, 'Item field not returned when "no_items" passed' );
+ is( $result->{field1}, 1, 'Biblio field returned when "no_items" passed' );
};
# Cleanup