Lines 94-106
subtest 'Test merge A1 to A2 (within same authtype)' => sub {
Link Here
|
94 |
is( $rv, 1, 'We expect one biblio record (out of two) to be updated' ); |
94 |
is( $rv, 1, 'We expect one biblio record (out of two) to be updated' ); |
95 |
|
95 |
|
96 |
# Check the results |
96 |
# Check the results |
97 |
my $newbiblio1 = GetMarcBiblio($biblionumber1); |
97 |
my $newbiblio1 = GetMarcBiblio({ biblionumber => $biblionumber1 }); |
98 |
compare_fields( $biblio1, $newbiblio1, {}, 'count' ); |
98 |
compare_fields( $biblio1, $newbiblio1, {}, 'count' ); |
99 |
compare_fields( $biblio1, $newbiblio1, {}, 'order' ); |
99 |
compare_fields( $biblio1, $newbiblio1, {}, 'order' ); |
100 |
is( $newbiblio1->subfield('609', '9'), $authid1, 'Check biblio1 609$9' ); |
100 |
is( $newbiblio1->subfield('609', '9'), $authid1, 'Check biblio1 609$9' ); |
101 |
is( $newbiblio1->subfield('609', 'a'), 'George Orwell', |
101 |
is( $newbiblio1->subfield('609', 'a'), 'George Orwell', |
102 |
'Check biblio1 609$a' ); |
102 |
'Check biblio1 609$a' ); |
103 |
my $newbiblio2 = GetMarcBiblio($biblionumber2); |
103 |
my $newbiblio2 = GetMarcBiblio({ biblionumber => $biblionumber2 }); |
104 |
compare_fields( $biblio2, $newbiblio2, {}, 'count' ); |
104 |
compare_fields( $biblio2, $newbiblio2, {}, 'count' ); |
105 |
compare_fields( $biblio2, $newbiblio2, {}, 'order' ); |
105 |
compare_fields( $biblio2, $newbiblio2, {}, 'order' ); |
106 |
is( $newbiblio2->subfield('609', '9'), $authid1, 'Check biblio2 609$9' ); |
106 |
is( $newbiblio2->subfield('609', '9'), $authid1, 'Check biblio2 609$9' ); |
Lines 138-148
subtest 'Test merge A1 to modified A1, test strict mode' => sub {
Link Here
|
138 |
is( $rv, 2, 'Both records are updated now' ); |
138 |
is( $rv, 2, 'Both records are updated now' ); |
139 |
|
139 |
|
140 |
#Check the results |
140 |
#Check the results |
141 |
my $biblio1 = GetMarcBiblio($biblionumber1); |
141 |
my $biblio1 = GetMarcBiblio({ biblionumber => $biblionumber1 }); |
142 |
compare_fields( $MARC1, $biblio1, {}, 'count' ); |
142 |
compare_fields( $MARC1, $biblio1, {}, 'count' ); |
143 |
compare_fields( $MARC1, $biblio1, {}, 'order' ); |
143 |
compare_fields( $MARC1, $biblio1, {}, 'order' ); |
144 |
is( $auth1new->field(109)->subfield('a'), $biblio1->field(109)->subfield('a'), 'Record1 values updated correctly' ); |
144 |
is( $auth1new->field(109)->subfield('a'), $biblio1->field(109)->subfield('a'), 'Record1 values updated correctly' ); |
145 |
my $biblio2 = GetMarcBiblio( $biblionumber2 ); |
145 |
my $biblio2 = GetMarcBiblio({ biblionumber => $biblionumber2 }); |
146 |
compare_fields( $MARC2, $biblio2, {}, 'count' ); |
146 |
compare_fields( $MARC2, $biblio2, {}, 'count' ); |
147 |
compare_fields( $MARC2, $biblio2, {}, 'order' ); |
147 |
compare_fields( $MARC2, $biblio2, {}, 'order' ); |
148 |
is( $auth1new->field(109)->subfield('a'), $biblio2->field(109)->subfield('a'), 'Record2 values updated correctly' ); |
148 |
is( $auth1new->field(109)->subfield('a'), $biblio2->field(109)->subfield('a'), 'Record2 values updated correctly' ); |
Lines 154-160
subtest 'Test merge A1 to modified A1, test strict mode' => sub {
Link Here
|
154 |
ModBiblio( $MARC1, $biblionumber1, '' ); |
154 |
ModBiblio( $MARC1, $biblionumber1, '' ); |
155 |
@linkedrecords = ( $biblionumber1 ); |
155 |
@linkedrecords = ( $biblionumber1 ); |
156 |
$rv = C4::AuthoritiesMarc::merge({ mergefrom => $authid1, MARCfrom => $auth1old, mergeto => $authid1, MARCto => $auth1new }); |
156 |
$rv = C4::AuthoritiesMarc::merge({ mergefrom => $authid1, MARCfrom => $auth1old, mergeto => $authid1, MARCto => $auth1new }); |
157 |
$biblio1 = GetMarcBiblio($biblionumber1); |
157 |
$biblio1 = GetMarcBiblio({ biblionumber => $biblionumber1 }); |
158 |
is( $biblio1->field(109)->subfield('b'), undef, 'Subfield overwritten in strict mode' ); |
158 |
is( $biblio1->field(109)->subfield('b'), undef, 'Subfield overwritten in strict mode' ); |
159 |
compare_fields( $MARC1, $biblio1, { 609 => 1 }, 'count' ); |
159 |
compare_fields( $MARC1, $biblio1, { 609 => 1 }, 'count' ); |
160 |
my @old609 = $MARC1->field('609'); |
160 |
my @old609 = $MARC1->field('609'); |
Lines 195-201
subtest 'Test merge A1 to B1 (changing authtype)' => sub {
Link Here
|
195 |
MARC::Field->new( '612', '', '', a => 'unrelated', 9 => 'other' ), |
195 |
MARC::Field->new( '612', '', '', a => 'unrelated', 9 => 'other' ), |
196 |
); |
196 |
); |
197 |
my ( $biblionumber ) = C4::Biblio::AddBiblio( $marc, '' ); |
197 |
my ( $biblionumber ) = C4::Biblio::AddBiblio( $marc, '' ); |
198 |
my $oldbiblio = C4::Biblio::GetMarcBiblio( $biblionumber ); |
198 |
my $oldbiblio = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber }); |
199 |
|
199 |
|
200 |
# Time to merge |
200 |
# Time to merge |
201 |
@linkedrecords = ( $biblionumber ); |
201 |
@linkedrecords = ( $biblionumber ); |
Lines 203-209
subtest 'Test merge A1 to B1 (changing authtype)' => sub {
Link Here
|
203 |
is( $retval, 1, 'We touched only one biblio' ); |
203 |
is( $retval, 1, 'We touched only one biblio' ); |
204 |
|
204 |
|
205 |
# Get new marc record for compares |
205 |
# Get new marc record for compares |
206 |
my $newbiblio = C4::Biblio::GetMarcBiblio( $biblionumber ); |
206 |
my $newbiblio = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber }); |
207 |
compare_fields( $oldbiblio, $newbiblio, {}, 'count' ); |
207 |
compare_fields( $oldbiblio, $newbiblio, {}, 'count' ); |
208 |
# Exclude 109/609 and 112/612 in comparing order |
208 |
# Exclude 109/609 and 112/612 in comparing order |
209 |
my $excl = { '109' => 1, '112' => 1, '609' => 1, '612' => 1 }; |
209 |
my $excl = { '109' => 1, '112' => 1, '609' => 1, '612' => 1 }; |
Lines 260-266
subtest 'Merging authorities should handle deletes (BZ 18070)' => sub {
Link Here
|
260 |
DelAuthority({ authid => $authid1 }); # this triggers a merge call |
260 |
DelAuthority({ authid => $authid1 }); # this triggers a merge call |
261 |
|
261 |
|
262 |
# See what happened in the biblio record |
262 |
# See what happened in the biblio record |
263 |
my $marc1 = C4::Biblio::GetMarcBiblio( $biblionumber ); |
263 |
my $marc1 = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber }); |
264 |
is( $marc1->field('609'), undef, 'Field 609 should be gone too' ); |
264 |
is( $marc1->field('609'), undef, 'Field 609 should be gone too' ); |
265 |
|
265 |
|
266 |
# Now we simulate the delete as done in the cron job |
266 |
# Now we simulate the delete as done in the cron job |
Lines 282-288
subtest 'Merging authorities should handle deletes (BZ 18070)' => sub {
Link Here
|
282 |
$mocks->{auth_mod}->unmock_all; |
282 |
$mocks->{auth_mod}->unmock_all; |
283 |
merge({ mergefrom => $authid1, biblionumbers => [ $biblionumber ] }); |
283 |
merge({ mergefrom => $authid1, biblionumbers => [ $biblionumber ] }); |
284 |
# Final check |
284 |
# Final check |
285 |
$marc1 = C4::Biblio::GetMarcBiblio( $biblionumber ); |
285 |
$marc1 = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber }); |
286 |
is( $marc1->field('609'), undef, 'Merge removed the 609 again even after deleting the authority record' ); |
286 |
is( $marc1->field('609'), undef, 'Merge removed the 609 again even after deleting the authority record' ); |
287 |
}; |
287 |
}; |
288 |
|
288 |
|
Lines 306-319
subtest "Test some specific postponed merge issues" => sub {
Link Here
|
306 |
# This proves the !authtypefrom condition in sub merge |
306 |
# This proves the !authtypefrom condition in sub merge |
307 |
# Additionally, we test clearing subfield |
307 |
# Additionally, we test clearing subfield |
308 |
merge({ mergefrom => $id + 1, MARCfrom => $oldauthmarc, mergeto => $id, MARCto => $authmarc, biblionumbers => [ $biblionumber ] }); |
308 |
merge({ mergefrom => $id + 1, MARCfrom => $oldauthmarc, mergeto => $id, MARCto => $authmarc, biblionumbers => [ $biblionumber ] }); |
309 |
$biblio = C4::Biblio::GetMarcBiblio( $biblionumber ); |
309 |
$biblio = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber }); |
310 |
is( $biblio->subfield('609', '9'), $id, '612 moved to 609' ); |
310 |
is( $biblio->subfield('609', '9'), $id, '612 moved to 609' ); |
311 |
is( $biblio->subfield('609', 'c'), undef, '609c cleared correctly' ); |
311 |
is( $biblio->subfield('609', 'c'), undef, '609c cleared correctly' ); |
312 |
|
312 |
|
313 |
# Merge A to B postponed, delete B immediately (hits B < hits A) |
313 |
# Merge A to B postponed, delete B immediately (hits B < hits A) |
314 |
# This proves the !@record_to test in sub merge |
314 |
# This proves the !@record_to test in sub merge |
315 |
merge({ mergefrom => $id + 2, mergeto => $id + 1, MARCto => undef, biblionumbers => [ $biblionumber ] }); |
315 |
merge({ mergefrom => $id + 2, mergeto => $id + 1, MARCto => undef, biblionumbers => [ $biblionumber ] }); |
316 |
$biblio = C4::Biblio::GetMarcBiblio( $biblionumber ); |
316 |
$biblio = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber }); |
317 |
is( $biblio->field('612'), undef, 'Last 612 must be gone' ); |
317 |
is( $biblio->field('612'), undef, 'Last 612 must be gone' ); |
318 |
|
318 |
|
319 |
# Show that we 'need' skip_merge; this example is far-fetched. |
319 |
# Show that we 'need' skip_merge; this example is far-fetched. |
Lines 325-331
subtest "Test some specific postponed merge issues" => sub {
Link Here
|
325 |
my $restored_mocks = set_mocks(); |
325 |
my $restored_mocks = set_mocks(); |
326 |
DelAuthority({ authid => $id, skip_merge => 1 }); # delete A |
326 |
DelAuthority({ authid => $id, skip_merge => 1 }); # delete A |
327 |
$restored_mocks->{auth_mod}->unmock_all; |
327 |
$restored_mocks->{auth_mod}->unmock_all; |
328 |
$biblio = C4::Biblio::GetMarcBiblio( $biblionumber ); |
328 |
$biblio = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber }); |
329 |
is( $biblio->subfield('109', '9'), $id, 'If the 109 is no longer present, another modify merge would not bring it back' ); |
329 |
is( $biblio->subfield('109', '9'), $id, 'If the 109 is no longer present, another modify merge would not bring it back' ); |
330 |
}; |
330 |
}; |
331 |
|
331 |
|