Lines 13-22
use Test::MockModule;
Link Here
|
13 |
use t::lib::Mocks; |
13 |
use t::lib::Mocks; |
14 |
use t::lib::TestBuilder; |
14 |
use t::lib::TestBuilder; |
15 |
|
15 |
|
16 |
use C4::Biblio qw( AddBiblio GetMarcBiblio ModBiblio ); |
16 |
use C4::Biblio qw( AddBiblio ModBiblio ); |
17 |
use Koha::Authorities; |
17 |
use Koha::Authorities; |
18 |
use Koha::Authority::ControlledIndicators; |
18 |
use Koha::Authority::ControlledIndicators; |
19 |
use Koha::Authority::MergeRequests; |
19 |
use Koha::Authority::MergeRequests; |
|
|
20 |
use Koha::Biblios; |
20 |
use Koha::Database; |
21 |
use Koha::Database; |
21 |
|
22 |
|
22 |
BEGIN { |
23 |
BEGIN { |
Lines 95-107
subtest 'Test merge A1 to A2 (within same authtype)' => sub {
Link Here
|
95 |
is( $rv, 1, 'We expect one biblio record (out of two) to be updated' ); |
96 |
is( $rv, 1, 'We expect one biblio record (out of two) to be updated' ); |
96 |
|
97 |
|
97 |
# Check the results |
98 |
# Check the results |
98 |
my $newbiblio1 = GetMarcBiblio({ biblionumber => $biblionumber1 }); |
99 |
my $newbiblio1 = Koha::Biblios->find($biblionumber1)->metadata->record; |
99 |
compare_fields( $biblio1, $newbiblio1, {}, 'count' ); |
100 |
compare_fields( $biblio1, $newbiblio1, {}, 'count' ); |
100 |
compare_fields( $biblio1, $newbiblio1, {}, 'order' ); |
101 |
compare_fields( $biblio1, $newbiblio1, {}, 'order' ); |
101 |
is( $newbiblio1->subfield('609', '9'), $authid1, 'Check biblio1 609$9' ); |
102 |
is( $newbiblio1->subfield('609', '9'), $authid1, 'Check biblio1 609$9' ); |
102 |
is( $newbiblio1->subfield('609', 'a'), 'George Orwell', |
103 |
is( $newbiblio1->subfield('609', 'a'), 'George Orwell', |
103 |
'Check biblio1 609$a' ); |
104 |
'Check biblio1 609$a' ); |
104 |
my $newbiblio2 = GetMarcBiblio({ biblionumber => $biblionumber2 }); |
105 |
my $newbiblio2 = Koha::Biblios->find($biblionumber2)->metadata->record; |
105 |
compare_fields( $biblio2, $newbiblio2, {}, 'count' ); |
106 |
compare_fields( $biblio2, $newbiblio2, {}, 'count' ); |
106 |
compare_fields( $biblio2, $newbiblio2, {}, 'order' ); |
107 |
compare_fields( $biblio2, $newbiblio2, {}, 'order' ); |
107 |
is( $newbiblio2->subfield('609', '9'), $authid1, 'Check biblio2 609$9' ); |
108 |
is( $newbiblio2->subfield('609', '9'), $authid1, 'Check biblio2 609$9' ); |
Lines 139-149
subtest 'Test merge A1 to modified A1, test strict mode' => sub {
Link Here
|
139 |
is( $rv, 2, 'Both records are updated now' ); |
140 |
is( $rv, 2, 'Both records are updated now' ); |
140 |
|
141 |
|
141 |
#Check the results |
142 |
#Check the results |
142 |
my $biblio1 = GetMarcBiblio({ biblionumber => $biblionumber1 }); |
143 |
my $biblio1 = Koha::Biblios->find($biblionumber1)->metadata->record; |
143 |
compare_fields( $MARC1, $biblio1, {}, 'count' ); |
144 |
compare_fields( $MARC1, $biblio1, {}, 'count' ); |
144 |
compare_fields( $MARC1, $biblio1, {}, 'order' ); |
145 |
compare_fields( $MARC1, $biblio1, {}, 'order' ); |
145 |
is( $auth1new->field(109)->subfield('a'), $biblio1->field(109)->subfield('a'), 'Record1 values updated correctly' ); |
146 |
is( $auth1new->field(109)->subfield('a'), $biblio1->field(109)->subfield('a'), 'Record1 values updated correctly' ); |
146 |
my $biblio2 = GetMarcBiblio({ biblionumber => $biblionumber2 }); |
147 |
my $biblio2 = Koha::Biblios->find($biblionumber2)->metadata->record; |
147 |
compare_fields( $MARC2, $biblio2, {}, 'count' ); |
148 |
compare_fields( $MARC2, $biblio2, {}, 'count' ); |
148 |
compare_fields( $MARC2, $biblio2, {}, 'order' ); |
149 |
compare_fields( $MARC2, $biblio2, {}, 'order' ); |
149 |
is( $auth1new->field(109)->subfield('a'), $biblio2->field(109)->subfield('a'), 'Record2 values updated correctly' ); |
150 |
is( $auth1new->field(109)->subfield('a'), $biblio2->field(109)->subfield('a'), 'Record2 values updated correctly' ); |
Lines 155-161
subtest 'Test merge A1 to modified A1, test strict mode' => sub {
Link Here
|
155 |
ModBiblio( $MARC1, $biblionumber1, '' ); |
156 |
ModBiblio( $MARC1, $biblionumber1, '' ); |
156 |
@linkedrecords = ( $biblionumber1 ); |
157 |
@linkedrecords = ( $biblionumber1 ); |
157 |
$rv = C4::AuthoritiesMarc::merge({ mergefrom => $authid1, MARCfrom => $auth1old, mergeto => $authid1, MARCto => $auth1new }); |
158 |
$rv = C4::AuthoritiesMarc::merge({ mergefrom => $authid1, MARCfrom => $auth1old, mergeto => $authid1, MARCto => $auth1new }); |
158 |
$biblio1 = GetMarcBiblio({ biblionumber => $biblionumber1 }); |
159 |
$biblio1 = Koha::Biblios->find($biblionumber1)->metadata->record; |
159 |
is( $biblio1->field(109)->subfield('b'), undef, 'Subfield overwritten in strict mode' ); |
160 |
is( $biblio1->field(109)->subfield('b'), undef, 'Subfield overwritten in strict mode' ); |
160 |
compare_fields( $MARC1, $biblio1, { 609 => 1 }, 'count' ); |
161 |
compare_fields( $MARC1, $biblio1, { 609 => 1 }, 'count' ); |
161 |
my @old609 = $MARC1->field('609'); |
162 |
my @old609 = $MARC1->field('609'); |
Lines 196-202
subtest 'Test merge A1 to B1 (changing authtype)' => sub {
Link Here
|
196 |
MARC::Field->new( '612', '', '', a => 'unrelated', 9 => 'other' ), |
197 |
MARC::Field->new( '612', '', '', a => 'unrelated', 9 => 'other' ), |
197 |
); |
198 |
); |
198 |
my ( $biblionumber ) = C4::Biblio::AddBiblio( $marc, '' ); |
199 |
my ( $biblionumber ) = C4::Biblio::AddBiblio( $marc, '' ); |
199 |
my $oldbiblio = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber }); |
200 |
my $oldbiblio = Koha::Biblios->find($biblionumber)->metadata->record; |
200 |
|
201 |
|
201 |
# Time to merge |
202 |
# Time to merge |
202 |
@linkedrecords = ( $biblionumber ); |
203 |
@linkedrecords = ( $biblionumber ); |
Lines 204-210
subtest 'Test merge A1 to B1 (changing authtype)' => sub {
Link Here
|
204 |
is( $retval, 1, 'We touched only one biblio' ); |
205 |
is( $retval, 1, 'We touched only one biblio' ); |
205 |
|
206 |
|
206 |
# Get new marc record for compares |
207 |
# Get new marc record for compares |
207 |
my $newbiblio = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber }); |
208 |
my $newbiblio = Koha::Biblios->find($biblionumber)->metadata->record; |
208 |
compare_fields( $oldbiblio, $newbiblio, {}, 'count' ); |
209 |
compare_fields( $oldbiblio, $newbiblio, {}, 'count' ); |
209 |
# Exclude 109/609 and 112/612 in comparing order |
210 |
# Exclude 109/609 and 112/612 in comparing order |
210 |
my $excl = { '109' => 1, '112' => 1, '609' => 1, '612' => 1 }; |
211 |
my $excl = { '109' => 1, '112' => 1, '609' => 1, '612' => 1 }; |
Lines 261-267
subtest 'Merging authorities should handle deletes (BZ 18070)' => sub {
Link Here
|
261 |
DelAuthority({ authid => $authid1 }); # this triggers a merge call |
262 |
DelAuthority({ authid => $authid1 }); # this triggers a merge call |
262 |
|
263 |
|
263 |
# See what happened in the biblio record |
264 |
# See what happened in the biblio record |
264 |
my $marc1 = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber }); |
265 |
my $marc1 = Koha::Biblios->find($biblionumber)->metadata->record; |
265 |
is( $marc1->field('609'), undef, 'Field 609 should be gone too' ); |
266 |
is( $marc1->field('609'), undef, 'Field 609 should be gone too' ); |
266 |
|
267 |
|
267 |
# Now we simulate the delete as done in the cron job |
268 |
# Now we simulate the delete as done in the cron job |
Lines 283-289
subtest 'Merging authorities should handle deletes (BZ 18070)' => sub {
Link Here
|
283 |
$mocks->{auth_mod}->unmock_all; |
284 |
$mocks->{auth_mod}->unmock_all; |
284 |
merge({ mergefrom => $authid1, biblionumbers => [ $biblionumber ] }); |
285 |
merge({ mergefrom => $authid1, biblionumbers => [ $biblionumber ] }); |
285 |
# Final check |
286 |
# Final check |
286 |
$marc1 = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber }); |
287 |
$marc1 = Koha::Biblios->find($biblionumber)->metadata->record; |
287 |
is( $marc1->field('609'), undef, 'Merge removed the 609 again even after deleting the authority record' ); |
288 |
is( $marc1->field('609'), undef, 'Merge removed the 609 again even after deleting the authority record' ); |
288 |
}; |
289 |
}; |
289 |
|
290 |
|
Lines 307-320
subtest "Test some specific postponed merge issues" => sub {
Link Here
|
307 |
# This proves the !authtypefrom condition in sub merge |
308 |
# This proves the !authtypefrom condition in sub merge |
308 |
# Additionally, we test clearing subfield |
309 |
# Additionally, we test clearing subfield |
309 |
merge({ mergefrom => $id + 1, MARCfrom => $oldauthmarc, mergeto => $id, MARCto => $authmarc, biblionumbers => [ $biblionumber ] }); |
310 |
merge({ mergefrom => $id + 1, MARCfrom => $oldauthmarc, mergeto => $id, MARCto => $authmarc, biblionumbers => [ $biblionumber ] }); |
310 |
$biblio = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber }); |
311 |
$biblio = Koha::Biblios->find($biblionumber)->metadata->record; |
311 |
is( $biblio->subfield('609', '9'), $id, '612 moved to 609' ); |
312 |
is( $biblio->subfield('609', '9'), $id, '612 moved to 609' ); |
312 |
is( $biblio->subfield('609', 'c'), undef, '609c cleared correctly' ); |
313 |
is( $biblio->subfield('609', 'c'), undef, '609c cleared correctly' ); |
313 |
|
314 |
|
314 |
# Merge A to B postponed, delete B immediately (hits B < hits A) |
315 |
# Merge A to B postponed, delete B immediately (hits B < hits A) |
315 |
# This proves the !@record_to test in sub merge |
316 |
# This proves the !@record_to test in sub merge |
316 |
merge({ mergefrom => $id + 2, mergeto => $id + 1, MARCto => undef, biblionumbers => [ $biblionumber ] }); |
317 |
merge({ mergefrom => $id + 2, mergeto => $id + 1, MARCto => undef, biblionumbers => [ $biblionumber ] }); |
317 |
$biblio = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber }); |
318 |
$biblio = Koha::Biblios->find($biblionumber)->metadata->record; |
318 |
is( $biblio->field('612'), undef, 'Last 612 must be gone' ); |
319 |
is( $biblio->field('612'), undef, 'Last 612 must be gone' ); |
319 |
|
320 |
|
320 |
# Show that we 'need' skip_merge; this example is far-fetched. |
321 |
# Show that we 'need' skip_merge; this example is far-fetched. |
Lines 326-332
subtest "Test some specific postponed merge issues" => sub {
Link Here
|
326 |
my $restored_mocks = set_mocks(); |
327 |
my $restored_mocks = set_mocks(); |
327 |
DelAuthority({ authid => $id, skip_merge => 1 }); # delete A |
328 |
DelAuthority({ authid => $id, skip_merge => 1 }); # delete A |
328 |
$restored_mocks->{auth_mod}->unmock_all; |
329 |
$restored_mocks->{auth_mod}->unmock_all; |
329 |
$biblio = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber }); |
330 |
$biblio = Koha::Biblios->find($biblionumber)->metadata->record; |
330 |
is( $biblio->subfield('109', '9'), $id, 'If the 109 is no longer present, another modify merge would not bring it back' ); |
331 |
is( $biblio->subfield('109', '9'), $id, 'If the 109 is no longer present, another modify merge would not bring it back' ); |
331 |
|
332 |
|
332 |
# Bug 22437 now removes older postponed A->A merges in DelAuthority |
333 |
# Bug 22437 now removes older postponed A->A merges in DelAuthority |
Lines 367-373
subtest "Graceful resolution of missing reporting tag" => sub {
Link Here
|
367 |
|
368 |
|
368 |
# Merge |
369 |
# Merge |
369 |
merge({ mergefrom => $id1, MARCfrom => $authmarc, mergeto => $id2, MARCto => $authmarc, biblionumbers => [ $biblionumber ] }); |
370 |
merge({ mergefrom => $id1, MARCfrom => $authmarc, mergeto => $id2, MARCto => $authmarc, biblionumbers => [ $biblionumber ] }); |
370 |
$biblio = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber }); |
371 |
$biblio = Koha::Biblios->find($biblionumber)->metadata->record; |
371 |
is( $biblio->subfield('612', '9'), $id2, 'id2 saved in $9' ); |
372 |
is( $biblio->subfield('612', '9'), $id2, 'id2 saved in $9' ); |
372 |
is( $biblio->subfield('612', 'a'), ' ', 'Kept an empty $a too' ); |
373 |
is( $biblio->subfield('612', 'a'), ' ', 'Kept an empty $a too' ); |
373 |
|
374 |
|
Lines 392-398
subtest 'merge should not reorder too much' => sub {
Link Here
|
392 |
|
393 |
|
393 |
# Merge 109 and 609 and check order of subfields |
394 |
# Merge 109 and 609 and check order of subfields |
394 |
merge({ mergefrom => $id, MARCfrom => $authmarc, mergeto => $id, MARCto => $authmarc, biblionumbers => [ $biblionumber ] }); |
395 |
merge({ mergefrom => $id, MARCfrom => $authmarc, mergeto => $id, MARCto => $authmarc, biblionumbers => [ $biblionumber ] }); |
395 |
my $biblio2 = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber }); |
396 |
my $biblio2 = Koha::Biblios->find($biblionumber)->metadata->record; |
396 |
my $subfields = [ map { $_->[0] } $biblio2->field('109')->subfields ]; |
397 |
my $subfields = [ map { $_->[0] } $biblio2->field('109')->subfields ]; |
397 |
is_deeply( $subfields, [ 'i', 'a', 'b', 'c', '9' ], 'Merge only moved $9' ); |
398 |
is_deeply( $subfields, [ 'i', 'a', 'b', 'c', '9' ], 'Merge only moved $9' ); |
398 |
$subfields = [ map { $_->[0] } $biblio2->field('609')->subfields ]; |
399 |
$subfields = [ map { $_->[0] } $biblio2->field('609')->subfields ]; |
Lines 422-428
subtest 'Test how merge handles controlled indicators' => sub {
Link Here
|
422 |
|
423 |
|
423 |
# Merge and check indicators and $2 |
424 |
# Merge and check indicators and $2 |
424 |
merge({ mergefrom => $id, MARCfrom => $authmarc, mergeto => $id, MARCto => $authmarc, biblionumbers => [ $biblionumber ] }); |
425 |
merge({ mergefrom => $id, MARCfrom => $authmarc, mergeto => $id, MARCto => $authmarc, biblionumbers => [ $biblionumber ] }); |
425 |
my $biblio2 = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber }); |
426 |
my $biblio2 = Koha::Biblios->find($biblionumber)->metadata->record; |
426 |
is( $biblio2->field('609')->indicator(1), '7', 'Indicator1 OK' ); |
427 |
is( $biblio2->field('609')->indicator(1), '7', 'Indicator1 OK' ); |
427 |
is( $biblio2->field('609')->indicator(2), '7', 'Indicator2 OK' ); |
428 |
is( $biblio2->field('609')->indicator(2), '7', 'Indicator2 OK' ); |
428 |
is( $biblio2->subfield('609', '2'), 'aat', 'Subfield $2 OK' ); |
429 |
is( $biblio2->subfield('609', '2'), 'aat', 'Subfield $2 OK' ); |
Lines 431-437
subtest 'Test how merge handles controlled indicators' => sub {
Link Here
|
431 |
$authmarc->field('008')->update( (' 'x11).'a' ); # LOC, no $2 needed |
432 |
$authmarc->field('008')->update( (' 'x11).'a' ); # LOC, no $2 needed |
432 |
AddAuthority( $authmarc, $id, $authtype1 ); # modify |
433 |
AddAuthority( $authmarc, $id, $authtype1 ); # modify |
433 |
merge({ mergefrom => $id, MARCfrom => $authmarc, mergeto => $id, MARCto => $authmarc, biblionumbers => [ $biblionumber ] }); |
434 |
merge({ mergefrom => $id, MARCfrom => $authmarc, mergeto => $id, MARCto => $authmarc, biblionumbers => [ $biblionumber ] }); |
434 |
$biblio2 = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber }); |
435 |
$biblio2 = Koha::Biblios->find($biblionumber)->metadata->record; |
435 |
is( $biblio2->subfield('609', '2'), undef, 'No subfield $2 left' ); |
436 |
is( $biblio2->subfield('609', '2'), undef, 'No subfield $2 left' ); |
436 |
}; |
437 |
}; |
437 |
|
438 |
|