Marcel de Rooy
e9a4e52077
GetMarcSubfieldStructure: In Biblio.t we are adding a subtest that checks the structure returned by this routine. Is it a hashref pointing to arrayrefs of hashrefs? ;) In Search.t this routine was mocked. The change in the returned structure is now applied to this mock too (moving the marc tag hashes into arrayrefs). GetMarcFromKohaField: In Biblio.t we add a subtest for it. We are checking if it returns multiple mappings (per kohafield) and calling it in scalar context too. GetMarcSubfieldStructureFromKohaField: The existing subtest in Biblio.t is expanded to also test the call in list context. TransformKohaToMarc: This sub has its own test script. We are adding a subtest in TransformKohaToMarc.t for a test with multiple mappings, and for mapping to a control field in another framework. This also tests the additional framework parameter. Additionally, we add a test for the new no_split option used for items. TransformMarcToKoha: This implicitly tests its helper sub _get_inverted. This patch adds a new test script for this routine. TransformMarcToKohaOneField: A few tests are added to the previous new test script. Test plan: [1] Run t/db_dependent/Biblio.t [2] Run t/db_dependent/Biblio/TransformKohaToMarc.t [3] Run t/db_dependent/Biblio/TransformMarcToKoha.t [4] Run t/db_dependent/Search.t Signed-off-by: Josef Moravec <josef.moravec@gmail.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
116 lines
4.8 KiB
Perl
116 lines
4.8 KiB
Perl
use Modern::Perl;
|
|
use Test::More tests => 4;
|
|
use MARC::Record;
|
|
|
|
use t::lib::Mocks;
|
|
use t::lib::TestBuilder;
|
|
|
|
use Koha::Database;
|
|
use Koha::Caches;
|
|
use Koha::MarcSubfieldStructures;
|
|
use C4::Biblio;
|
|
|
|
my $schema = Koha::Database->new->schema;
|
|
$schema->storage->txn_begin;
|
|
|
|
# Create/overwrite some Koha to MARC mappings in default framework
|
|
my $mapping1 = Koha::MarcSubfieldStructures->find('','300','a') // Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '300', tagsubfield => 'a' });
|
|
$mapping1->kohafield( "mytable.nicepages" );
|
|
$mapping1->store;
|
|
my $mapping2 = Koha::MarcSubfieldStructures->find('','300','b') // Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '300', tagsubfield => 'b' });
|
|
$mapping2->kohafield( "mytable2.goodillustrations" );
|
|
$mapping2->store;
|
|
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
|
|
|
|
my $record = C4::Biblio::TransformKohaToMarc({
|
|
"mytable2.goodillustrations" => "Other physical details", # 300$b
|
|
"mytable.nicepages" => "Extent", # 300$a
|
|
});
|
|
my @subfields = $record->field('300')->subfields();
|
|
is_deeply( \@subfields, [
|
|
[
|
|
'a',
|
|
'Extent'
|
|
],
|
|
[
|
|
'b',
|
|
'Other physical details'
|
|
],
|
|
],
|
|
'TransformKohaToMarc should return sorted subfields (regression test for bug 12343)' );
|
|
|
|
|
|
# Now test multiple mappings per kohafield too
|
|
subtest "Multiple Koha to MARC mappings (BZ 10306)" => sub {
|
|
plan tests => 4;
|
|
|
|
# 300a and 260d mapped to mytable.nicepages
|
|
my $mapping3 = Koha::MarcSubfieldStructures->find('','260','d') // Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '260', tagsubfield => 'd' });
|
|
$mapping3->kohafield( "mytable.nicepages" );
|
|
$mapping3->store;
|
|
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
|
|
|
|
# Include two values in goodillustrations too: should result in two
|
|
# subfields.
|
|
my $record = C4::Biblio::TransformKohaToMarc({
|
|
"mytable2.goodillustrations" => "good | better",
|
|
"mytable.nicepages" => "nice",
|
|
});
|
|
is( $record->subfield('260','d'), "nice", "Check 260d" );
|
|
is( $record->subfield('300','a'), "nice", "Check 300a" );
|
|
is( $record->subfield('300','b'), "good", "Check first 300b" );
|
|
is( ($record->field('300')->subfield('b'))[1], "better",
|
|
"Check second 300b" );
|
|
};
|
|
|
|
subtest "Working with control fields in another framework" => sub {
|
|
plan tests => 2;
|
|
|
|
# Add a new framework
|
|
my $fw = t::lib::TestBuilder->new->build_object({
|
|
class => 'Koha::BiblioFrameworks'
|
|
});
|
|
|
|
# Map a controlfield to 'fullcontrol'
|
|
my $mapping = Koha::MarcSubfieldStructure->new({ frameworkcode => $fw->frameworkcode, tagfield => '001', tagsubfield => '@', kohafield => 'fullcontrol' });
|
|
$mapping->store;
|
|
|
|
# First test in the wrong framework
|
|
my @cols = ( notexist => 'i am not here', fullcontrol => 'all' );
|
|
my $record = C4::Biblio::TransformKohaToMarc( { @cols } );
|
|
is( $record->field('001'), undef,
|
|
'With default framework we should not find a 001 controlfield' );
|
|
# Now include the framework parameter and test 001
|
|
$record = C4::Biblio::TransformKohaToMarc( { @cols }, $fw->frameworkcode );
|
|
is( $record->field('001')->data, "all", "Check controlfield 001 with right frameworkcode" );
|
|
|
|
# Remove from cache
|
|
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-".$fw->frameworkcode );
|
|
};
|
|
|
|
subtest "Add test for no_split option" => sub {
|
|
plan tests => 4;
|
|
|
|
my $fwc = t::lib::TestBuilder->new->build({ source => 'MarcSubfieldStructure' })->{frameworkcode};
|
|
Koha::MarcSubfieldStructure->new({ frameworkcode => $fwc, tagfield => '952', tagsubfield => 'a', kohafield => 'items.fld1' })->store;
|
|
Koha::MarcSubfieldStructure->new({ frameworkcode => $fwc, tagfield => '952', tagsubfield => 'b', kohafield => 'items.fld1' })->store;
|
|
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-$fwc" );
|
|
|
|
# Test single value in fld1
|
|
my @cols = ( 'items.fld1' => '01' );
|
|
my $record = C4::Biblio::TransformKohaToMarc( { @cols }, $fwc, { no_split => 1 } );
|
|
is( $record->subfield( '952', 'a' ), '01', 'Check single in 952a' );
|
|
is( $record->subfield( '952', 'b' ), '01', 'Check single in 952b' );
|
|
|
|
# Test glued (composite) value in fld1
|
|
@cols = ( 'items.fld1' => '01 | 02' );
|
|
$record = C4::Biblio::TransformKohaToMarc( { @cols }, $fwc, { no_split => 1 } );
|
|
is( $record->subfield( '952', 'a' ), '01 | 02', 'Check composite in 952a' );
|
|
is( $record->subfield( '952', 'b' ), '01 | 02', 'Check composite in 952b' );
|
|
|
|
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-$fwc" );
|
|
};
|
|
|
|
# Cleanup
|
|
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
|
|
$schema->storage->txn_rollback;
|