|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 1; |
22 |
use Test::More tests => 2; |
| 23 |
|
23 |
|
| 24 |
use Koha::MarcSubfieldStructure; |
24 |
use Koha::MarcSubfieldStructure; |
| 25 |
use Koha::MarcSubfieldStructures; |
25 |
use Koha::MarcSubfieldStructures; |
|
Lines 56-59
subtest 'Trivial tests' => sub {
Link Here
|
| 56 |
is( Koha::MarcSubfieldStructures->search->count, $nb_of_fields + 1, 'Delete should have deleted the field' ); |
56 |
is( Koha::MarcSubfieldStructures->search->count, $nb_of_fields + 1, 'Delete should have deleted the field' ); |
| 57 |
}; |
57 |
}; |
| 58 |
|
58 |
|
|
|
59 |
subtest 'get_kohafield_exceptions / sync_kohafield' => sub { |
| 60 |
plan tests => 14; |
| 61 |
|
| 62 |
# start from scratch again, add a new framework |
| 63 |
Koha::MarcSubfieldStructures->delete; |
| 64 |
my $builder = t::lib::TestBuilder->new; |
| 65 |
my $fwc = $builder->build({ source => 'BiblioFramework' })->{frameworkcode}; |
| 66 |
|
| 67 |
# 100a mapped in Default, unmapped in other |
| 68 |
Koha::MarcSubfieldStructure->new({ frameworkcode => q{}, tagfield => '100', tagsubfield => 'a', kohafield => 'biblio.author' })->store; |
| 69 |
Koha::MarcSubfieldStructure->new({ frameworkcode => $fwc, tagfield => '100', tagsubfield => 'a', kohafield => '' })->store; |
| 70 |
my $res = Koha::MarcSubfieldStructures->get_kohafield_exceptions; |
| 71 |
is( @$res, 1, 'Found one exception' ); |
| 72 |
is( $res->[0]->[1] . $res->[0]->[2], '100a', '100a was reported' ); |
| 73 |
Koha::MarcSubfieldStructures->sync_kohafield; |
| 74 |
$res = Koha::MarcSubfieldStructures->get_kohafield_exceptions; |
| 75 |
is( @$res, 0, 'Found no exceptions after syncing' ); |
| 76 |
is( Koha::MarcSubfieldStructures->find($fwc, '100', 'a')->kohafield, |
| 77 |
'biblio.author', '100a in added framework adjusted' ); |
| 78 |
|
| 79 |
# 245a unmapped in Default, mapped in other |
| 80 |
# 300a not in Default, mapped in other |
| 81 |
Koha::MarcSubfieldStructure->new({ frameworkcode => q{}, tagfield => '245', tagsubfield => 'a', kohafield => q{} })->store; |
| 82 |
Koha::MarcSubfieldStructure->new({ frameworkcode => $fwc, tagfield => '245', tagsubfield => 'a', kohafield => 'biblio.title' })->store; |
| 83 |
Koha::MarcSubfieldStructure->new({ frameworkcode => $fwc, tagfield => '300', tagsubfield => 'a', kohafield => 'biblioitems.pages' })->store; |
| 84 |
$res = Koha::MarcSubfieldStructures->get_kohafield_exceptions; |
| 85 |
is( @$res, 2, 'Found two exceptions' ); |
| 86 |
is( $res->[0]->[1] . $res->[0]->[2], '245a', '245a was reported' ); |
| 87 |
is( $res->[1]->[1] . $res->[1]->[2], '300a', '300a was reported' ); |
| 88 |
Koha::MarcSubfieldStructures->sync_kohafield; |
| 89 |
$res = Koha::MarcSubfieldStructures->get_kohafield_exceptions; |
| 90 |
is( @$res, 0, 'Found no exceptions after syncing again' ); |
| 91 |
is( Koha::MarcSubfieldStructures->find($fwc, '245', 'a')->kohafield, |
| 92 |
undef, '245a in added framework cleared' ); |
| 93 |
is( Koha::MarcSubfieldStructures->find($fwc, '300', 'a')->kohafield, |
| 94 |
undef, '300a in added framework cleared' ); |
| 95 |
|
| 96 |
# 300a mapped in Default to another field than in other framework |
| 97 |
Koha::MarcSubfieldStructure->new({ frameworkcode => q{}, tagfield => '300', tagsubfield => 'a', kohafield => 'something_else' })->store; |
| 98 |
Koha::MarcSubfieldStructures->find($fwc, '300', 'a')->update({ kohafield => 'biblioitems.pages' }); |
| 99 |
$res = Koha::MarcSubfieldStructures->get_kohafield_exceptions; |
| 100 |
is( @$res, 1, 'Found one exception' ); |
| 101 |
is( $res->[0]->[1] . $res->[0]->[2], '300a', '300a was reported again' ); |
| 102 |
Koha::MarcSubfieldStructures->sync_kohafield; |
| 103 |
$res = Koha::MarcSubfieldStructures->get_kohafield_exceptions; |
| 104 |
is( @$res, 0, 'Found no exceptions after third syncing' ); |
| 105 |
is( Koha::MarcSubfieldStructures->find($fwc, '300', 'a')->kohafield, |
| 106 |
'something_else', '300a in added framework adjusted' ); |
| 107 |
}; |
| 108 |
|
| 59 |
$schema->storage->txn_rollback; |
109 |
$schema->storage->txn_rollback; |
| 60 |
- |
|
|