Lines 42-48
Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '500', tagsu
Link Here
|
42 |
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" ); |
42 |
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" ); |
43 |
|
43 |
|
44 |
subtest 'Test a few mappings' => sub { |
44 |
subtest 'Test a few mappings' => sub { |
45 |
plan tests => 7; |
45 |
plan tests => 6; |
46 |
|
46 |
|
47 |
my $marc = MARC::Record->new; |
47 |
my $marc = MARC::Record->new; |
48 |
$marc->append_fields( |
48 |
$marc->append_fields( |
Lines 50-56
subtest 'Test a few mappings' => sub {
Link Here
|
50 |
MARC::Field->new( '300', '', '', a => 'a2', b => 'b2' ), |
50 |
MARC::Field->new( '300', '', '', a => 'a2', b => 'b2' ), |
51 |
MARC::Field->new( '500', '', '', a => 'note1', a => 'note2' ), |
51 |
MARC::Field->new( '500', '', '', a => 'note1', a => 'note2' ), |
52 |
); |
52 |
); |
53 |
my $result = C4::Biblio::TransformMarcToKoha( $marc ); |
53 |
my $result = C4::Biblio::TransformMarcToKoha({ record => $marc }); |
54 |
# Note: TransformMarcToKoha stripped the table prefix biblio. |
54 |
# Note: TransformMarcToKoha stripped the table prefix biblio. |
55 |
is( keys %{$result}, 3, 'Found all three mappings' ); |
55 |
is( keys %{$result}, 3, 'Found all three mappings' ); |
56 |
is( $result->{field1}, 'a1 | a2', 'Check field1 results' ); |
56 |
is( $result->{field1}, 'a1 | a2', 'Check field1 results' ); |
Lines 62-73
subtest 'Test a few mappings' => sub {
Link Here
|
62 |
is( C4::Biblio::TransformMarcToKohaOneField( 'field4', $marc ), |
62 |
is( C4::Biblio::TransformMarcToKohaOneField( 'field4', $marc ), |
63 |
undef, 'TransformMarcToKohaOneField returns undef' ); |
63 |
undef, 'TransformMarcToKohaOneField returns undef' ); |
64 |
|
64 |
|
65 |
# Bug 19096 Default is authoritative now |
|
|
66 |
# Test passing another framework |
67 |
# CAUTION: This parameter of TransformMarcToKoha will be removed later |
68 |
my $new_fw = t::lib::TestBuilder->new->build({source => 'BiblioFramework'}); |
69 |
$result = C4::Biblio::TransformMarcToKoha($marc, $new_fw->{frameworkcode}); |
70 |
is( keys %{$result}, 3, 'Still found all three mappings' ); |
71 |
}; |
65 |
}; |
72 |
|
66 |
|
73 |
subtest 'Multiple mappings for one kohafield' => sub { |
67 |
subtest 'Multiple mappings for one kohafield' => sub { |
Lines 80-92
subtest 'Multiple mappings for one kohafield' => sub {
Link Here
|
80 |
|
74 |
|
81 |
my $marc = MARC::Record->new; |
75 |
my $marc = MARC::Record->new; |
82 |
$marc->append_fields( MARC::Field->new( '300', '', '', a => '3a' ) ); |
76 |
$marc->append_fields( MARC::Field->new( '300', '', '', a => '3a' ) ); |
83 |
my $result = C4::Biblio::TransformMarcToKoha( $marc ); |
77 |
my $result = C4::Biblio::TransformMarcToKoha({ record => $marc }); |
84 |
is_deeply( $result, { field1 => '3a' }, 'Simple start' ); |
78 |
is_deeply( $result, { field1 => '3a' }, 'Simple start' ); |
85 |
$marc->append_fields( MARC::Field->new( '510', '', '', a => '' ) ); |
79 |
$marc->append_fields( MARC::Field->new( '510', '', '', a => '' ) ); |
86 |
$result = C4::Biblio::TransformMarcToKoha( $marc ); |
80 |
$result = C4::Biblio::TransformMarcToKoha({ record => $marc }); |
87 |
is_deeply( $result, { field1 => '3a' }, 'An empty 510a makes no difference' ); |
81 |
is_deeply( $result, { field1 => '3a' }, 'An empty 510a makes no difference' ); |
88 |
$marc->append_fields( MARC::Field->new( '510', '', '', a => '51' ) ); |
82 |
$marc->append_fields( MARC::Field->new( '510', '', '', a => '51' ) ); |
89 |
$result = C4::Biblio::TransformMarcToKoha( $marc ); |
83 |
$result = C4::Biblio::TransformMarcToKoha({ record => $marc }); |
90 |
is_deeply( $result, { field1 => '3a | 51' }, 'Got 300a and 510a' ); |
84 |
is_deeply( $result, { field1 => '3a | 51' }, 'Got 300a and 510a' ); |
91 |
|
85 |
|
92 |
is( C4::Biblio::TransformMarcToKohaOneField( 'biblio.field1', $marc ), |
86 |
is( C4::Biblio::TransformMarcToKohaOneField( 'biblio.field1', $marc ), |
Lines 128-134
subtest 'Test repeatable subfields' => sub {
Link Here
|
128 |
|
122 |
|
129 |
my $marc = MARC::Record->new; |
123 |
my $marc = MARC::Record->new; |
130 |
$marc->append_fields( MARC::Field->new( '510', '', '', x => '1', x => '2', y => '3 | 4', y => '5' ) ); # actually, we should only have one $y (BZ 24652) |
124 |
$marc->append_fields( MARC::Field->new( '510', '', '', x => '1', x => '2', y => '3 | 4', y => '5' ) ); # actually, we should only have one $y (BZ 24652) |
131 |
my $result = C4::Biblio::TransformMarcToKoha( $marc ); |
125 |
my $result = C4::Biblio::TransformMarcToKoha({ record => $marc }); |
132 |
is( $result->{test}, '1 | 2', 'Check 510x for two values' ); |
126 |
is( $result->{test}, '1 | 2', 'Check 510x for two values' ); |
133 |
is( $result->{norepeat}, '3 | 4 | 5', 'Check 510y too' ); |
127 |
is( $result->{norepeat}, '3 | 4 | 5', 'Check 510y too' ); |
134 |
|
128 |
|
Lines 136-142
subtest 'Test repeatable subfields' => sub {
Link Here
|
136 |
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" ); |
130 |
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" ); |
137 |
$marc->append_fields( MARC::Field->new( '510', '', '', a => '1' ) ); # actually, we should only have one $y (BZ 24652) |
131 |
$marc->append_fields( MARC::Field->new( '510', '', '', a => '1' ) ); # actually, we should only have one $y (BZ 24652) |
138 |
|
132 |
|
139 |
$result = C4::Biblio::TransformMarcToKoha( $marc, '', 'no_items' ); |
133 |
$result = C4::Biblio::TransformMarcToKoha({ record => $marc, limit_table => 'no_items' }); |
140 |
is( $result->{test}, undef, 'Item field not returned when "no_items" passed' ); |
134 |
is( $result->{test}, undef, 'Item field not returned when "no_items" passed' ); |
141 |
is( $result->{norepeat}, undef, 'Item field not returned when "no_items" passed' ); |
135 |
is( $result->{norepeat}, undef, 'Item field not returned when "no_items" passed' ); |
142 |
is( $result->{field1}, 1, 'Biblio field returned when "no_items" passed' ); |
136 |
is( $result->{field1}, 1, 'Biblio field returned when "no_items" passed' ); |
143 |
- |
|
|