Lines 18-24
Link Here
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::NoWarnings; |
20 |
use Test::NoWarnings; |
21 |
use Test::More tests => 41; |
21 |
use Test::More tests => 42; |
22 |
use Test::Exception; |
22 |
use Test::Exception; |
23 |
use Test::Warn; |
23 |
use Test::Warn; |
24 |
|
24 |
|
Lines 1228-1233
subtest 'generate_marc_host_field' => sub {
Link Here
|
1228 |
t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); |
1228 |
t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); |
1229 |
}; |
1229 |
}; |
1230 |
|
1230 |
|
|
|
1231 |
subtest 'generate_marc_host_field with item parameter' => sub { |
1232 |
plan tests => 16; |
1233 |
|
1234 |
$schema->storage->txn_begin; |
1235 |
|
1236 |
# Create a host biblio with a basic record |
1237 |
my $host_biblio = $builder->build_sample_biblio(); |
1238 |
my $host_record = MARC::Record->new(); |
1239 |
$host_record->leader('00000nam a22000007a 4500'); |
1240 |
$host_record->append_fields( |
1241 |
MARC::Field->new( '001', '12345' ), |
1242 |
MARC::Field->new( '100', '1', ' ', a => 'Test Author' ), |
1243 |
MARC::Field->new( '245', '1', '0', a => 'Test Title' ), |
1244 |
); |
1245 |
C4::Biblio::ModBiblio( $host_record, $host_biblio->biblionumber ); |
1246 |
$host_biblio = Koha::Biblios->find( $host_biblio->biblionumber ); |
1247 |
|
1248 |
# Create an item for the host biblio |
1249 |
my $item = $builder->build_sample_item( |
1250 |
{ |
1251 |
biblionumber => $host_biblio->biblionumber, |
1252 |
barcode => '123456789' |
1253 |
} |
1254 |
); |
1255 |
|
1256 |
# Test 1: MARC21 with item parameter when EasyAnalyticalRecords is enabled |
1257 |
t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); |
1258 |
t::lib::Mocks::mock_preference( 'EasyAnalyticalRecords', 1 ); |
1259 |
|
1260 |
my $link = $host_biblio->generate_marc_host_field( { item => $item } ); |
1261 |
is( $link->tag, '773', 'MARC21 link field is 773' ); |
1262 |
is( $link->subfield('0'), $host_biblio->biblionumber, 'Subfield 0 contains host biblionumber when item provided' ); |
1263 |
is( $link->subfield('9'), $item->itemnumber, 'Subfield 9 contains host itemnumber when item provided' ); |
1264 |
is( $link->subfield('o'), $item->barcode, 'Subfield o contains barcode when item provided' ); |
1265 |
is( $link->subfield('a'), 'Test Author', 'Subfield a still contains author' ); |
1266 |
is( $link->subfield('t'), 'Test Title', 'Subfield t still contains title' ); |
1267 |
|
1268 |
# Test 2: MARC21 with item parameter when EasyAnalyticalRecords is disabled |
1269 |
t::lib::Mocks::mock_preference( 'EasyAnalyticalRecords', 0 ); |
1270 |
|
1271 |
$link = $host_biblio->generate_marc_host_field( { item => $item } ); |
1272 |
is( $link->tag, '773', 'MARC21 link field is 773' ); |
1273 |
is( $link->subfield('0'), undef, 'Subfield 0 is not present when EasyAnalyticalRecords disabled' ); |
1274 |
is( $link->subfield('9'), undef, 'Subfield 9 is not present when EasyAnalyticalRecords disabled' ); |
1275 |
is( $link->subfield('o'), undef, 'Subfield o is not present when EasyAnalyticalRecords disabled' ); |
1276 |
is( $link->subfield('a'), 'Test Author', 'Subfield a still contains author' ); |
1277 |
is( $link->subfield('t'), 'Test Title', 'Subfield t still contains title' ); |
1278 |
|
1279 |
# Test 3: UNIMARC with item parameter when EasyAnalyticalRecords is enabled |
1280 |
t::lib::Mocks::mock_preference( 'marcflavour', 'UNIMARC' ); |
1281 |
t::lib::Mocks::mock_preference( 'EasyAnalyticalRecords', 1 ); |
1282 |
|
1283 |
# Create a fresh UNIMARC biblio to avoid metadata conflicts |
1284 |
my $unimarc_biblio = $builder->build_sample_biblio(); |
1285 |
my $unimarc_record = MARC::Record->new(); |
1286 |
$unimarc_record->leader('00000nam a22000007a 4500'); |
1287 |
$unimarc_record->append_fields( |
1288 |
MARC::Field->new( '001', '12345' ), |
1289 |
MARC::Field->new( '200', '1', ' ', a => 'Test UNIMARC Title' ), |
1290 |
MARC::Field->new( '700', '1', ' ', a => 'Test UNIMARC Author' ), |
1291 |
); |
1292 |
C4::Biblio::ModBiblio( $unimarc_record, $unimarc_biblio->biblionumber ); |
1293 |
$unimarc_biblio = Koha::Biblios->find( $unimarc_biblio->biblionumber ); |
1294 |
|
1295 |
# Create item for the UNIMARC biblio |
1296 |
my $unimarc_item = $builder->build_sample_item( |
1297 |
{ |
1298 |
biblionumber => $unimarc_biblio->biblionumber, |
1299 |
barcode => '987654321' |
1300 |
} |
1301 |
); |
1302 |
|
1303 |
$link = $unimarc_biblio->generate_marc_host_field( { item => $unimarc_item } ); |
1304 |
is( $link->tag, '461', 'UNIMARC link field is 461' ); |
1305 |
is( |
1306 |
$link->subfield('0'), $unimarc_biblio->biblionumber, |
1307 |
'UNIMARC subfield 0 contains host biblionumber when item provided' |
1308 |
); |
1309 |
is( |
1310 |
$link->subfield('9'), $unimarc_item->itemnumber, |
1311 |
'UNIMARC subfield 9 contains host itemnumber when item provided' |
1312 |
); |
1313 |
is( $link->subfield('t'), 'Test UNIMARC Title', 'UNIMARC subfield t still contains title' ); |
1314 |
|
1315 |
$schema->storage->txn_rollback; |
1316 |
t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); |
1317 |
t::lib::Mocks::mock_preference( 'EasyAnalyticalRecords', 0 ); |
1318 |
}; |
1319 |
|
1231 |
subtest 'link_marc_host' => sub { |
1320 |
subtest 'link_marc_host' => sub { |
1232 |
plan tests => 6; |
1321 |
plan tests => 6; |
1233 |
$schema->storage->txn_begin; |
1322 |
$schema->storage->txn_begin; |
1234 |
- |
|
|