Bug 18951: Create data for TransformKohaToMarc.t
[koha.git] / t / db_dependent / Biblio / TransformKohaToMarc.t
1 use Modern::Perl;
2 use Test::More tests => 1;
3 use MARC::Record;
4
5 use t::lib::Mocks;
6 use Koha::Database;
7 use Koha::Caches;
8 use Koha::MarcSubfieldStructures;
9 use C4::Biblio;
10
11 my $schema  = Koha::Database->new->schema;
12 $schema->storage->txn_begin;
13
14 # Create/overwrite some Koha to MARC mappings in default framework
15 my $mapping1 = Koha::MarcSubfieldStructures->find('','300','a') // Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '300', tagsubfield => 'a' });
16 $mapping1->kohafield( "mytable.nicepages" );
17 $mapping1->store;
18 my $mapping2 = Koha::MarcSubfieldStructures->find('','300','b') // Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '300', tagsubfield => 'b' });
19 $mapping2->kohafield( "mytable2.goodillustrations" );
20 $mapping2->store;
21 Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
22
23 my $record = C4::Biblio::TransformKohaToMarc({
24     "mytable2.goodillustrations"   => "Other physical details", # 300$b
25     "mytable.nicepages"            => "Extent",                 # 300$a
26 });
27 my @subfields = $record->field('300')->subfields();
28 is_deeply( \@subfields, [
29           [
30             'a',
31             'Extent'
32           ],
33           [
34             'b',
35             'Other physical details'
36           ],
37         ],
38 'TransformKohaToMarc should return sorted subfields (regression test for bug 12343)' );
39
40 # Cleanup
41 Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
42 $schema->storage->txn_rollback;