Lines 4-10
Link Here
|
4 |
|
4 |
|
5 |
use Modern::Perl; |
5 |
use Modern::Perl; |
6 |
|
6 |
|
7 |
use Test::More tests => 6; |
7 |
use Test::More tests => 7; |
8 |
|
8 |
|
9 |
use Getopt::Long; |
9 |
use Getopt::Long; |
10 |
use MARC::Record; |
10 |
use MARC::Record; |
Lines 286-291
subtest 'Merging authorities should handle deletes (BZ 18070)' => sub {
Link Here
|
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 |
|
|
|
289 |
subtest "Test some specific postponed merge issues" => sub { |
290 |
plan tests => 4; |
291 |
|
292 |
my $authmarc = MARC::Record->new; |
293 |
$authmarc->append_fields( MARC::Field->new( '109', '', '', 'a' => 'aa', b => 'bb' )); |
294 |
my $oldauthmarc = MARC::Record->new; |
295 |
$oldauthmarc->append_fields( MARC::Field->new( '112', '', '', c => 'cc' )); |
296 |
my $id = AddAuthority( $authmarc, undef, $authtype1 ); |
297 |
my $biblio = MARC::Record->new; |
298 |
$biblio->append_fields( |
299 |
MARC::Field->new( '109', '', '', a => 'a1', 9 => $id ), |
300 |
MARC::Field->new( '612', '', '', a => 'a2', c => 'cc', 9 => $id+1 ), |
301 |
MARC::Field->new( '612', '', '', a => 'a3', 9 => $id+2 ), |
302 |
); |
303 |
my ( $biblionumber ) = C4::Biblio::AddBiblio( $biblio, '' ); |
304 |
|
305 |
# Merge A to B postponed, A is deleted (simulated by id+1) |
306 |
# This proves the !authtypefrom condition in sub merge |
307 |
# Additionally, we test clearing subfield |
308 |
merge({ mergefrom => $id + 1, MARCfrom => $oldauthmarc, mergeto => $id, MARCto => $authmarc, biblionumbers => [ $biblionumber ] }); |
309 |
$biblio = C4::Biblio::GetMarcBiblio( $biblionumber ); |
310 |
is( $biblio->subfield('609', '9'), $id, '612 moved to 609' ); |
311 |
is( $biblio->subfield('609', 'c'), undef, '609c cleared correctly' ); |
312 |
|
313 |
# Merge A to B postponed, delete B immediately (hits B < hits A) |
314 |
# This proves the !@record_to test in sub merge |
315 |
merge({ mergefrom => $id + 2, mergeto => $id + 1, MARCto => undef, biblionumbers => [ $biblionumber ] }); |
316 |
$biblio = C4::Biblio::GetMarcBiblio( $biblionumber ); |
317 |
is( $biblio->field('612'), undef, 'Last 612 must be gone' ); |
318 |
|
319 |
# Show that we 'need' skip_merge; this example is far-fetched. |
320 |
# We *prove* by contradiction. |
321 |
# Suppose: Merge A to B postponed, and delete A would merge rightaway. |
322 |
# (You would need some special race condition with merge.pl to do so.) |
323 |
# The modify merge would be useless after that. |
324 |
@linkedrecords = ( $biblionumber ); |
325 |
my $restored_mocks = set_mocks(); |
326 |
DelAuthority({ authid => $id }); # delete A |
327 |
$restored_mocks->{auth_mod}->unmock_all; |
328 |
$biblio = C4::Biblio::GetMarcBiblio( $biblionumber ); |
329 |
is( $biblio->subfield('109', '9'), $id, 'If the 109 is no longer present, another modify merge would not bring it back' ); |
330 |
}; |
331 |
|
289 |
sub set_mocks { |
332 |
sub set_mocks { |
290 |
# After we removed the Zebra code from merge, we only need to mock |
333 |
# After we removed the Zebra code from merge, we only need to mock |
291 |
# get_usage_count and linked_biblionumbers here. |
334 |
# get_usage_count and linked_biblionumbers here. |
292 |
- |
|
|