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