View | Details | Raw Unified | Return to bug 11700
Collapse All | Expand All

(-)a/t/db_dependent/AuthoritiesMarc.t (-2 / +74 lines)
Lines 6-12 Link Here
6
use strict;
6
use strict;
7
use warnings;
7
use warnings;
8
8
9
use Test::More tests => 8;
9
use C4::Context;
10
use C4::Biblio;
11
use Test::More tests => 15;
10
use Test::MockModule;
12
use Test::MockModule;
11
use Test::Warn;
13
use Test::Warn;
12
use MARC::Record;
14
use MARC::Record;
Lines 190-193 is_deeply( Link Here
190
    'test BuildSummary for UNIMARC'
192
    'test BuildSummary for UNIMARC'
191
);
193
);
192
194
195
$module->unmock_all();
196
197
# Start testing C4::AuthoritiesMarc::merge
198
199
# Create authority type TEST_PERSO
200
$dbh->do("INSERT INTO auth_types(authtypecode, authtypetext, auth_tag_to_report, summary) VALUES('TEST_PERSO', 'Personal Name', '109', 'Personal Names');");
201
$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)");
202
$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, '', '', '')");
203
204
my $auth1 = new MARC::Record;
205
$auth1->append_fields(new MARC::Field('109', '0', '0', 'a' => 'George Orwell'));
206
my $authid1 = AddAuthority($auth1, undef, 'TEST_PERSO');
207
my $auth2 = new MARC::Record;
208
$auth2->append_fields(new MARC::Field('109', '0', '0', 'a' => 'G. Orwell'));
209
my $authid2 = AddAuthority($auth2, undef, 'TEST_PERSO');
210
211
$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)");
212
$dbh->do("UPDATE marc_subfield_structure SET authtypecode = 'TEST_PERSO' WHERE tagfield='609' AND tagsubfield='a' AND frameworkcode='';");
213
my $tagfields = $dbh->selectcol_arrayref("select distinct tagfield from marc_subfield_structure where authtypecode='TEST_PERSO'");
214
my $biblio1 = new MARC::Record;
215
$biblio1->append_fields(
216
    new MARC::Field('609', '0', '0', '9' => $authid1, 'a' => 'George Orwell')
217
);
218
my $biblionumber1 = AddBiblio($biblio1, '');
219
my $biblio2 = new MARC::Record;
220
$biblio2->append_fields(
221
    new MARC::Field('609', '0', '0', '9' => $authid2, 'a' => 'G. Orwell')
222
);
223
my $biblionumber2 = AddBiblio($biblio2, '');
224
225
# Mock ZOOM objects
226
my $zoom_connection = new Test::MockModule('ZOOM::Connection', no_auto => 1);
227
$zoom_connection->mock('search', sub {
228
    return _new ZOOM::ResultSet(shift, shift, [$biblionumber2]);
229
});
230
my $zoom_resultset = new Test::MockModule('ZOOM::ResultSet', no_auto => 1);
231
$zoom_resultset->mock('size', sub {
232
    my $this = shift;
233
    return scalar @{ $this->{_rs} };
234
});
235
$zoom_resultset->mock('record', sub {
236
    my ($this, $which) = @_;
237
    my $_rec = { biblionumber => $this->{_rs}->[$which] };
238
    return ZOOM::Record->_new($this, $which, $_rec);
239
});
240
$zoom_resultset->mock('destroy', undef);
241
my $zoom_record = new Test::MockModule('ZOOM::Record', no_auto => 1);
242
$zoom_record->mock('raw', sub {
243
    my $this = shift;
244
    my $index_mode = C4::Context->config('zebra_bib_index_mode') // 'dom';
245
    my $sqlfield = $index_mode eq 'dom' ? 'marcxml' : 'marc';
246
    my $marcs = $dbh->selectcol_arrayref(
247
        "SELECT $sqlfield FROM biblioitems WHERE biblionumber = ?", {},
248
        $this->{_rec}->{biblionumber});
249
    return $marcs->[0];
250
});
251
252
my @biblios = C4::AuthoritiesMarc::merge($authid2, undef, $authid1, undef);
253
254
is_deeply(\@biblios, [$biblionumber2]);
255
$biblio1 = GetMarcBiblio($biblionumber1);
256
is($biblio1->subfield('609', '9'), $authid1);
257
is($biblio1->subfield('609', 'a'), 'George Orwell');
258
$biblio2 = GetMarcBiblio($biblionumber2);
259
is($biblio2->subfield('609', '9'), $authid1);
260
is($biblio2->subfield('609', 'a'), 'George Orwell');
261
262
ok(defined(GetAuthority($authid1)));
263
ok(!defined(GetAuthority($authid2)));
264
# End testing C4::AuthoritiesMarc::merge
265
193
$dbh->rollback;
266
$dbh->rollback;
194
- 

Return to bug 11700