Lines 6-12
Link Here
|
6 |
use strict; |
6 |
use strict; |
7 |
use warnings; |
7 |
use warnings; |
8 |
|
8 |
|
9 |
use Test::More tests => 5; |
9 |
use Test::More tests => 12; |
10 |
use Test::MockModule; |
10 |
use Test::MockModule; |
11 |
use MARC::Record; |
11 |
use MARC::Record; |
12 |
|
12 |
|
Lines 96-98
$expectedhierarchy = [ [ {
Link Here
|
96 |
'parents' => [] |
96 |
'parents' => [] |
97 |
} ] ]; |
97 |
} ] ]; |
98 |
is_deeply(GenerateHierarchy(4), $expectedhierarchy, "Generated hierarchy data structure for unlinked hierarchy"); |
98 |
is_deeply(GenerateHierarchy(4), $expectedhierarchy, "Generated hierarchy data structure for unlinked hierarchy"); |
99 |
- |
99 |
|
|
|
100 |
$module->unmock_all(); |
101 |
|
102 |
use C4::Context; |
103 |
use C4::Biblio; |
104 |
|
105 |
my $dbh = C4::Context->dbh; |
106 |
$dbh->{AutoCommit} = 0; |
107 |
$dbh->{RaiseError} = 1; |
108 |
|
109 |
# Start testing C4::AuthoritiesMarc::merge |
110 |
|
111 |
# Create authority type TEST_PERSO |
112 |
$dbh->do("INSERT INTO auth_types(authtypecode, authtypetext, auth_tag_to_report, summary) VALUES('TEST_PERSO', 'Personal Name', '109', 'Personal Names');"); |
113 |
$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)"); |
114 |
$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, '', '', '')"); |
115 |
|
116 |
my $auth1 = new MARC::Record; |
117 |
$auth1->append_fields(new MARC::Field('109', '0', '0', 'a' => 'George Orwell')); |
118 |
my $authid1 = AddAuthority($auth1, undef, 'TEST_PERSO'); |
119 |
my $auth2 = new MARC::Record; |
120 |
$auth2->append_fields(new MARC::Field('109', '0', '0', 'a' => 'G. Orwell')); |
121 |
my $authid2 = AddAuthority($auth2, undef, 'TEST_PERSO'); |
122 |
|
123 |
$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)"); |
124 |
$dbh->do("UPDATE marc_subfield_structure SET authtypecode = 'TEST_PERSO' WHERE tagfield='609' AND tagsubfield='a' AND frameworkcode='';"); |
125 |
my $tagfields = $dbh->selectcol_arrayref("select distinct tagfield from marc_subfield_structure where authtypecode='TEST_PERSO'"); |
126 |
my $biblio1 = new MARC::Record; |
127 |
$biblio1->append_fields( |
128 |
new MARC::Field('609', '0', '0', '9' => $authid1, 'a' => 'George Orwell') |
129 |
); |
130 |
my $biblionumber1 = AddBiblio($biblio1, ''); |
131 |
my $biblio2 = new MARC::Record; |
132 |
$biblio2->append_fields( |
133 |
new MARC::Field('609', '0', '0', '9' => $authid2, 'a' => 'G. Orwell') |
134 |
); |
135 |
my $biblionumber2 = AddBiblio($biblio2, ''); |
136 |
|
137 |
# Mock ZOOM objects |
138 |
my $zoom_connection = new Test::MockModule('ZOOM::Connection', no_auto => 1); |
139 |
$zoom_connection->mock('search', sub { |
140 |
return _new ZOOM::ResultSet(shift, shift, [$biblionumber2]); |
141 |
}); |
142 |
my $zoom_resultset = new Test::MockModule('ZOOM::ResultSet', no_auto => 1); |
143 |
$zoom_resultset->mock('size', sub { |
144 |
my $this = shift; |
145 |
return scalar @{ $this->{_rs} }; |
146 |
}); |
147 |
$zoom_resultset->mock('record', sub { |
148 |
my ($this, $which) = @_; |
149 |
my $_rec = { biblionumber => $this->{_rs}->[$which] }; |
150 |
return ZOOM::Record->_new($this, $which, $_rec); |
151 |
}); |
152 |
$zoom_resultset->mock('destroy', undef); |
153 |
my $zoom_record = new Test::MockModule('ZOOM::Record', no_auto => 1); |
154 |
$zoom_record->mock('raw', sub { |
155 |
my $this = shift; |
156 |
my $marcs = $dbh->selectcol_arrayref( |
157 |
'SELECT marc FROM biblioitems WHERE biblionumber = ?', {}, |
158 |
$this->{_rec}->{biblionumber}); |
159 |
return $marcs->[0]; |
160 |
}); |
161 |
|
162 |
my @biblios = C4::AuthoritiesMarc::merge($authid2, undef, $authid1, undef); |
163 |
|
164 |
is_deeply(\@biblios, [$biblionumber2]); |
165 |
$biblio1 = GetMarcBiblio($biblionumber1); |
166 |
is($biblio1->subfield('609', '9'), $authid1); |
167 |
is($biblio1->subfield('609', 'a'), 'George Orwell'); |
168 |
$biblio2 = GetMarcBiblio($biblionumber2); |
169 |
is($biblio2->subfield('609', '9'), $authid1); |
170 |
is($biblio2->subfield('609', 'a'), 'George Orwell'); |
171 |
|
172 |
ok(defined(GetAuthority($authid1))); |
173 |
ok(!defined(GetAuthority($authid2))); |
174 |
# End testing C4::AuthoritiesMarc::merge |
175 |
|
176 |
$dbh->rollback; |