Lines 35-119
my $zoom_obj = Test::MockObject->new;
Link Here
|
35 |
my $zoom_record_obj = Test::MockObject->new; |
35 |
my $zoom_record_obj = Test::MockObject->new; |
36 |
set_mocks(); |
36 |
set_mocks(); |
37 |
|
37 |
|
|
|
38 |
# Framework operations |
39 |
my ( $authtype1, $authtype2 ) = modify_framework(); |
40 |
|
38 |
subtest 'Test merge A1 to A2 (withing same authtype)' => sub { |
41 |
subtest 'Test merge A1 to A2 (withing same authtype)' => sub { |
39 |
# Tests originate from bug 11700 |
42 |
# Tests originate from bug 11700 |
40 |
plan tests => 5; |
43 |
plan tests => 9; |
41 |
|
44 |
|
42 |
# Create authority type TEST_PERSO |
45 |
# Add two authority records |
43 |
$dbh->do("INSERT INTO auth_types(authtypecode, authtypetext, auth_tag_to_report, summary) VALUES('TEST_PERSO', 'Personal Name', '109', 'Personal Names');"); |
46 |
my $auth1 = MARC::Record->new; |
44 |
$dbh->do("INSERT INTO auth_tag_structure (authtypecode, tagfield, liblibrarian, libopac, repeatable, mandatory, authorised_value) VALUES('TEST_PERSO', '109', 'HEADING--PERSONAL NAME', 'HEADING--PERSONAL NAME', 0, 0, NULL)"); |
47 |
$auth1->append_fields( MARC::Field->new( '109', '0', '0', 'a' => 'George Orwell' )); |
45 |
$dbh->do("INSERT INTO auth_subfield_structure (authtypecode, tagfield, tagsubfield, liblibrarian, libopac, repeatable, mandatory, tab, authorised_value, value_builder, seealso, isurl, hidden, linkid, kohafield, frameworkcode) VALUES ('TEST_PERSO', '109', 'a', 'Personal name', 'Personal name', 0, 0, 1, NULL, NULL, '', 0, 0, '', '', '')"); |
48 |
my $authid1 = AddAuthority( $auth1, undef, $authtype1 ); |
46 |
|
49 |
my $auth2 = MARC::Record->new; |
47 |
my $auth1 = new MARC::Record; |
50 |
$auth2->append_fields( MARC::Field->new( '109', '0', '0', 'a' => 'G. Orwell' )); |
48 |
$auth1->append_fields(new MARC::Field('109', '0', '0', 'a' => 'George Orwell')); |
51 |
my $authid2 = AddAuthority( $auth2, undef, $authtype1 ); |
49 |
my $authid1 = AddAuthority($auth1, undef, 'TEST_PERSO'); |
52 |
|
50 |
my $auth2 = new MARC::Record; |
53 |
# Add two biblio records |
51 |
$auth2->append_fields(new MARC::Field('109', '0', '0', 'a' => 'G. Orwell')); |
54 |
my $biblio1 = MARC::Record->new; |
52 |
my $authid2 = AddAuthority($auth2, undef, 'TEST_PERSO'); |
55 |
$biblio1->append_fields( MARC::Field->new( '609', '0', '0', '9' => $authid1, 'a' => 'George Orwell' )); |
53 |
|
|
|
54 |
$dbh->do("INSERT IGNORE INTO marc_subfield_structure(tagfield, tagsubfield, liblibrarian, libopac, repeatable, mandatory, kohafield, tab, authorised_value, authtypecode, value_builder, isurl, hidden, frameworkcode, seealso, link, defaultvalue) VALUES('609', 'a', 'Personal name', 'Personal name', 0, 0, '', 6, '', 'TEST_PERSO', '', NULL, 0, '', '', '', NULL)"); |
55 |
$dbh->do("UPDATE marc_subfield_structure SET authtypecode = 'TEST_PERSO' WHERE tagfield='609' AND tagsubfield='a' AND frameworkcode='';"); |
56 |
my $tagfields = $dbh->selectcol_arrayref("select distinct tagfield from marc_subfield_structure where authtypecode='TEST_PERSO'"); |
57 |
my $biblio1 = new MARC::Record; |
58 |
$biblio1->append_fields( |
59 |
new MARC::Field('609', '0', '0', '9' => $authid1, 'a' => 'George Orwell') |
60 |
); |
61 |
my ( $biblionumber1 ) = AddBiblio($biblio1, ''); |
56 |
my ( $biblionumber1 ) = AddBiblio($biblio1, ''); |
62 |
my $biblio2 = new MARC::Record; |
57 |
my $biblio2 = MARC::Record->new; |
63 |
$biblio2->append_fields( |
58 |
$biblio2->append_fields( MARC::Field->new( '609', '0', '0', '9' => $authid2, 'a' => 'G. Orwell' )); |
64 |
new MARC::Field('609', '0', '0', '9' => $authid2, 'a' => 'G. Orwell') |
|
|
65 |
); |
66 |
my ( $biblionumber2 ) = AddBiblio($biblio2, ''); |
59 |
my ( $biblionumber2 ) = AddBiblio($biblio2, ''); |
67 |
|
60 |
|
|
|
61 |
# Time to merge |
68 |
@zebrarecords = ( $biblio1, $biblio2 ); |
62 |
@zebrarecords = ( $biblio1, $biblio2 ); |
69 |
$index = 0; |
63 |
$index = 0; |
70 |
my $rv = C4::AuthoritiesMarc::merge( $authid2, $auth2, $authid1, $auth1 ); |
64 |
my $rv = C4::AuthoritiesMarc::merge( $authid2, $auth2, $authid1, $auth1 ); |
71 |
is( $rv, 1, 'We expect one biblio record (out of two) to be updated' ); |
65 |
is( $rv, 1, 'We expect one biblio record (out of two) to be updated' ); |
72 |
|
66 |
|
73 |
$biblio1 = GetMarcBiblio($biblionumber1); |
67 |
# Check the results |
74 |
is($biblio1->subfield('609', '9'), $authid1, 'Check biblio1 609$9' ); |
68 |
my $newbiblio1 = GetMarcBiblio($biblionumber1); |
75 |
is($biblio1->subfield('609', 'a'), 'George Orwell', |
69 |
compare_field_count( $biblio1, $newbiblio1, 1 ); |
|
|
70 |
compare_field_order( $biblio1, $newbiblio1, 1 ); |
71 |
is( $newbiblio1->subfield('609', '9'), $authid1, 'Check biblio1 609$9' ); |
72 |
is( $newbiblio1->subfield('609', 'a'), 'George Orwell', |
76 |
'Check biblio1 609$a' ); |
73 |
'Check biblio1 609$a' ); |
77 |
$biblio2 = GetMarcBiblio($biblionumber2); |
74 |
my $newbiblio2 = GetMarcBiblio($biblionumber2); |
78 |
is($biblio2->subfield('609', '9'), $authid1, 'Check biblio2 609$9' ); |
75 |
compare_field_count( $biblio2, $newbiblio2, 1 ); |
79 |
is($biblio2->subfield('609', 'a'), 'George Orwell', |
76 |
compare_field_order( $biblio2, $newbiblio2, 1 ); |
|
|
77 |
is( $newbiblio2->subfield('609', '9'), $authid1, 'Check biblio2 609$9' ); |
78 |
is( $newbiblio2->subfield('609', 'a'), 'George Orwell', |
80 |
'Check biblio2 609$a' ); |
79 |
'Check biblio2 609$a' ); |
81 |
}; |
80 |
}; |
82 |
|
81 |
|
83 |
subtest 'Test merge A1 to modified A1' => sub { |
82 |
subtest 'Test merge A1 to modified A1' => sub { |
84 |
# Tests originate from bug 11700 |
83 |
# Tests originate from bug 11700 |
85 |
plan tests => 4; |
84 |
plan tests => 8; |
86 |
|
|
|
87 |
$dbh->do("INSERT IGNORE INTO marc_subfield_structure(tagfield, tagsubfield, liblibrarian, libopac, repeatable, mandatory, kohafield, tab, authorised_value, authtypecode, value_builder, isurl, hidden, frameworkcode, seealso, link, defaultvalue) VALUES('109', 'a', 'Personal name', 'Personal name', 0, 0, '', 6, '', 'TEST_PERSO', '', NULL, 0, '', '', '', NULL)"); |
88 |
$dbh->do("UPDATE marc_subfield_structure SET authtypecode = 'TEST_PERSO' WHERE tagfield='109' AND tagsubfield='a' AND frameworkcode='';"); |
89 |
|
85 |
|
|
|
86 |
# Simulate modifying an authority from auth1old to auth1new |
90 |
my $auth1old = MARC::Record->new; |
87 |
my $auth1old = MARC::Record->new; |
91 |
$auth1old->append_fields( MARC::Field->new( '109', '0', '0', 'a' => 'Bruce Wayne' )); |
88 |
$auth1old->append_fields( MARC::Field->new( '109', '0', '0', 'a' => 'Bruce Wayne' )); |
92 |
my $auth1new = $auth1old->clone; |
89 |
my $auth1new = $auth1old->clone; |
93 |
$auth1new->field('109')->update( a => 'Batman' ); |
90 |
$auth1new->field('109')->update( a => 'Batman' ); |
94 |
my $authid1 = AddAuthority( $auth1new, undef, 'TEST_PERSO' ); |
91 |
my $authid1 = AddAuthority( $auth1new, undef, $authtype1 ); |
95 |
|
92 |
|
96 |
my $MARC1 = MARC::Record->new(); |
93 |
# Add two biblio records |
97 |
$MARC1->append_fields( MARC::Field->new( '245', '', '', 'a' => 'From the depths' )); |
94 |
my $MARC1 = MARC::Record->new; |
98 |
$MARC1->append_fields( MARC::Field->new( '109', '', '', 'a' => 'Bruce Wayne', 'b' => '2014', '9' => $authid1 )); |
95 |
$MARC1->append_fields( MARC::Field->new( '109', '', '', 'a' => 'Bruce Wayne', 'b' => '2014', '9' => $authid1 )); |
99 |
my $MARC2 = MARC::Record->new(); |
96 |
$MARC1->append_fields( MARC::Field->new( '245', '', '', 'a' => 'From the depths' )); |
100 |
$MARC2->append_fields( MARC::Field->new( '245', '', '', 'a' => 'All the way to heaven' )); |
97 |
my $MARC2 = MARC::Record->new; |
101 |
$MARC2->append_fields( MARC::Field->new( '109', '', '', 'a' => 'Batman', '9' => $authid1 )); |
98 |
$MARC2->append_fields( MARC::Field->new( '109', '', '', 'a' => 'Batman', '9' => $authid1 )); |
|
|
99 |
$MARC2->append_fields( MARC::Field->new( '245', '', '', 'a' => 'All the way to heaven' )); |
102 |
my ( $biblionumber1 ) = AddBiblio( $MARC1, ''); |
100 |
my ( $biblionumber1 ) = AddBiblio( $MARC1, ''); |
103 |
my ( $biblionumber2 ) = AddBiblio( $MARC2, ''); |
101 |
my ( $biblionumber2 ) = AddBiblio( $MARC2, ''); |
104 |
|
102 |
|
|
|
103 |
# Time to merge |
105 |
@zebrarecords = ( $MARC1, $MARC2 ); |
104 |
@zebrarecords = ( $MARC1, $MARC2 ); |
106 |
$index = 0; |
105 |
$index = 0; |
107 |
|
|
|
108 |
my $rv = C4::AuthoritiesMarc::merge( $authid1, $auth1old, $authid1, $auth1new ); |
106 |
my $rv = C4::AuthoritiesMarc::merge( $authid1, $auth1old, $authid1, $auth1new ); |
109 |
is( $rv, 2, 'Both records are updated now' ); |
107 |
is( $rv, 2, 'Both records are updated now' ); |
110 |
|
108 |
|
|
|
109 |
#Check the results |
111 |
my $biblio1 = GetMarcBiblio($biblionumber1); |
110 |
my $biblio1 = GetMarcBiblio($biblionumber1); |
|
|
111 |
compare_field_count( $MARC1, $biblio1, 1 ); |
112 |
compare_field_order( $MARC1, $biblio1, 1 ); |
113 |
is( $auth1new->field(109)->subfield('a'), $biblio1->field(109)->subfield('a'), 'Record1 values updated correctly' ); |
112 |
my $biblio2 = GetMarcBiblio($biblionumber1); |
114 |
my $biblio2 = GetMarcBiblio($biblionumber1); |
113 |
|
115 |
compare_field_count( $MARC2, $biblio2, 1 ); |
114 |
my $auth_field = $auth1new->field(109)->subfield('a'); |
116 |
compare_field_order( $MARC2, $biblio2, 1 ); |
115 |
is( $auth_field, $biblio1->field(109)->subfield('a'), 'Record1 values updated correctly' ); |
117 |
is( $auth1new->field(109)->subfield('a'), $biblio2->field(109)->subfield('a'), 'Record2 values updated correctly' ); |
116 |
is( $auth_field, $biblio2->field(109)->subfield('a'), 'Record2 values updated correctly' ); |
|
|
117 |
|
118 |
|
118 |
# TODO Following test will change when we improve merge |
119 |
# TODO Following test will change when we improve merge |
119 |
# Will depend on a preference |
120 |
# Will depend on a preference |
Lines 126-167
subtest 'Test merge A1 to B1 (changing authtype)' => sub {
Link Here
|
126 |
# The merge routine still needs the fixes on bug 17913 |
127 |
# The merge routine still needs the fixes on bug 17913 |
127 |
plan tests => 8; |
128 |
plan tests => 8; |
128 |
|
129 |
|
129 |
# create another authtype |
130 |
# create two auth recs of different type |
130 |
my $authtype2 = $builder->build({ |
|
|
131 |
source => 'AuthType', |
132 |
value => { |
133 |
auth_tag_to_report => '112', |
134 |
}, |
135 |
}); |
136 |
# create two fields linked to this auth type |
137 |
$schema->resultset('MarcSubfieldStructure')->search({ tagfield => [ '112', '712' ] })->delete; |
138 |
$builder->build({ |
139 |
source => 'MarcSubfieldStructure', |
140 |
value => { |
141 |
tagfield => '112', |
142 |
tagsubfield => 'a', |
143 |
authtypecode => $authtype2->{authtypecode}, |
144 |
frameworkcode => '', |
145 |
}, |
146 |
}); |
147 |
$builder->build({ |
148 |
source => 'MarcSubfieldStructure', |
149 |
value => { |
150 |
tagfield => '712', |
151 |
tagsubfield => 'a', |
152 |
authtypecode => $authtype2->{authtypecode}, |
153 |
frameworkcode => '', |
154 |
}, |
155 |
}); |
156 |
|
157 |
# create auth1 (from the earlier type) |
158 |
my $auth1 = MARC::Record->new; |
131 |
my $auth1 = MARC::Record->new; |
159 |
$auth1->append_fields( MARC::Field->new( '109', '0', '0', 'a' => 'George Orwell', b => 'bb' )); |
132 |
$auth1->append_fields( MARC::Field->new( '109', '0', '0', 'a' => 'George Orwell', b => 'bb' )); |
160 |
my $authid1 = AddAuthority($auth1, undef, 'TEST_PERSO'); |
133 |
my $authid1 = AddAuthority( $auth1, undef, $authtype1 ); |
161 |
# create auth2 (new type) |
|
|
162 |
my $auth2 = MARC::Record->new; |
134 |
my $auth2 = MARC::Record->new; |
163 |
$auth2->append_fields( MARC::Field->new( '112', '0', '0', 'a' => 'Batman', c => 'cc' )); |
135 |
$auth2->append_fields( MARC::Field->new( '112', '0', '0', 'a' => 'Batman', c => 'cc' )); |
164 |
my $authid2 = AddAuthority($auth1, undef, $authtype2->{authtypecode} ); |
136 |
my $authid2 = AddAuthority($auth1, undef, $authtype2 ); |
165 |
|
137 |
|
166 |
# create a biblio with one 109 and two 609s to be touched |
138 |
# create a biblio with one 109 and two 609s to be touched |
167 |
# seems exceptional see bug 13760 comment10 |
139 |
# seems exceptional see bug 13760 comment10 |
Lines 178-183
subtest 'Test merge A1 to B1 (changing authtype)' => sub {
Link Here
|
178 |
my ( $biblionumber ) = C4::Biblio::AddBiblio( $marc, '' ); |
150 |
my ( $biblionumber ) = C4::Biblio::AddBiblio( $marc, '' ); |
179 |
my $oldbiblio = C4::Biblio::GetMarcBiblio( $biblionumber ); |
151 |
my $oldbiblio = C4::Biblio::GetMarcBiblio( $biblionumber ); |
180 |
|
152 |
|
|
|
153 |
# Time to merge |
181 |
@zebrarecords = ( $marc ); |
154 |
@zebrarecords = ( $marc ); |
182 |
$index = 0; |
155 |
$index = 0; |
183 |
my $retval = C4::AuthoritiesMarc::merge( $authid1, $auth1, $authid2, $auth2 ); |
156 |
my $retval = C4::AuthoritiesMarc::merge( $authid1, $auth1, $authid2, $auth2 ); |
Lines 225-230
sub set_mocks {
Link Here
|
225 |
$zoom_record_obj->mock( 'raw', sub {} ); |
198 |
$zoom_record_obj->mock( 'raw', sub {} ); |
226 |
} |
199 |
} |
227 |
|
200 |
|
|
|
201 |
sub modify_framework { |
202 |
# create two auth types |
203 |
my $authtype1 = $builder->build({ |
204 |
source => 'AuthType', |
205 |
value => { |
206 |
auth_tag_to_report => '109', |
207 |
}, |
208 |
}); |
209 |
my $authtype2 = $builder->build({ |
210 |
source => 'AuthType', |
211 |
value => { |
212 |
auth_tag_to_report => '112', |
213 |
}, |
214 |
}); |
215 |
|
216 |
# Link 109/609 to the first authtype |
217 |
$builder->build({ |
218 |
source => 'MarcSubfieldStructure', |
219 |
value => { |
220 |
tagfield => '109', |
221 |
tagsubfield => 'a', |
222 |
authtypecode => $authtype1->{authtypecode}, |
223 |
frameworkcode => '', |
224 |
}, |
225 |
}); |
226 |
$builder->build({ |
227 |
source => 'MarcSubfieldStructure', |
228 |
value => { |
229 |
tagfield => '609', |
230 |
tagsubfield => 'a', |
231 |
authtypecode => $authtype1->{authtypecode}, |
232 |
frameworkcode => '', |
233 |
}, |
234 |
}); |
235 |
|
236 |
# Link 112/712 to the second authtype |
237 |
$builder->build({ |
238 |
source => 'MarcSubfieldStructure', |
239 |
value => { |
240 |
tagfield => '112', |
241 |
tagsubfield => 'a', |
242 |
authtypecode => $authtype2->{authtypecode}, |
243 |
frameworkcode => '', |
244 |
}, |
245 |
}); |
246 |
$builder->build({ |
247 |
source => 'MarcSubfieldStructure', |
248 |
value => { |
249 |
tagfield => '712', |
250 |
tagsubfield => 'a', |
251 |
authtypecode => $authtype2->{authtypecode}, |
252 |
frameworkcode => '', |
253 |
}, |
254 |
}); |
255 |
|
256 |
return ( $authtype1->{authtypecode}, $authtype2->{authtypecode} ); |
257 |
} |
258 |
|
228 |
sub compare_field_count { |
259 |
sub compare_field_count { |
229 |
my ( $oldmarc, $newmarc, $pass ) = @_; |
260 |
my ( $oldmarc, $newmarc, $pass ) = @_; |
230 |
my $t; |
261 |
my $t; |
231 |
- |
|
|