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

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

Return to bug 11700