Lines 26-32
use Koha::Library;
Link Here
|
26 |
use t::lib::Mocks; |
26 |
use t::lib::Mocks; |
27 |
use t::lib::TestBuilder; |
27 |
use t::lib::TestBuilder; |
28 |
|
28 |
|
29 |
use Test::More tests => 9; |
29 |
use Test::More tests => 10; |
30 |
|
30 |
|
31 |
use Test::Warn; |
31 |
use Test::Warn; |
32 |
|
32 |
|
Lines 424-429
subtest 'SearchItems test' => sub {
Link Here
|
424 |
$schema->storage->txn_rollback; |
424 |
$schema->storage->txn_rollback; |
425 |
}; |
425 |
}; |
426 |
|
426 |
|
|
|
427 |
subtest 'ModItemFromMarc tests' => sub { |
428 |
|
429 |
plan tests => 3; |
430 |
|
431 |
my $dbh = C4::Context->dbh; |
432 |
my $builder = t::lib::TestBuilder->new; |
433 |
|
434 |
$schema->storage->txn_begin; |
435 |
|
436 |
my $branchcode = $builder->build({ |
437 |
source => 'Branch', |
438 |
})->{ branchcode }; |
439 |
|
440 |
my $frameworkcode = $builder->build({ |
441 |
source => 'BiblioFramework' |
442 |
})->{ frameworkcode }; |
443 |
|
444 |
my $msfstructure = $builder->build({ |
445 |
source => 'MarcSubfieldStructure', |
446 |
value => { |
447 |
frameworkcode => $frameworkcode, |
448 |
tagfield => 952, |
449 |
tagsubfield => 'k', |
450 |
kohafield => 'materials' |
451 |
} |
452 |
}); |
453 |
|
454 |
my $materials_value = 'materials_value'; |
455 |
my ($itemfield) = GetMarcFromKohaField('items.itemnumber', ''); |
456 |
my ($biblionumber) = get_biblio(); |
457 |
# Make sure the default framework has 952$3 => items.materials |
458 |
$dbh->do(q{ DELETE FROM marc_subfield_structure |
459 |
WHERE kohafield="items.materials" AND |
460 |
frameworkcode=""}, undef, $itemfield); |
461 |
$dbh->do(q{ UPDATE marc_subfield_structure |
462 |
SET kohafield="items.materials" |
463 |
WHERE tagfield=? AND |
464 |
tagsubfield="3" AND |
465 |
frameworkcode=""}, undef, $itemfield); |
466 |
|
467 |
# Make sure cache is clean (TODO: change after bug 13074) |
468 |
$C4::Items::default_values_for_mod_from_marc; |
469 |
|
470 |
# Add an item with a fixed materials value |
471 |
my $item_record = MARC::Record->new; |
472 |
$item_record->append_fields( |
473 |
MARC::Field->new( |
474 |
$itemfield, '', '', |
475 |
'3' => $materials_value |
476 |
) |
477 |
); |
478 |
my ( undef, undef, $itemnumber ) = AddItemFromMarc( $item_record, $biblionumber ); |
479 |
my $item = Koha::Items->find( $itemnumber ); |
480 |
is( $item->materials, $materials_value, 'Materials is correctly mapped on the default framework' ); |
481 |
|
482 |
# Change the biblio's framework |
483 |
ModBiblioframework( $biblionumber, $frameworkcode ); |
484 |
ModItemFromMarc( $item_record, $biblionumber, $itemnumber ); |
485 |
$item = Koha::Items->find( $itemnumber ); |
486 |
is( $item->materials, undef, 'Subfield 3 is not mapped on the new framework' ); |
487 |
|
488 |
# Now have the right subfield |
489 |
$item_record = MARC::Record->new; |
490 |
$item_record->append_fields( |
491 |
MARC::Field->new( |
492 |
$itemfield, '', '', |
493 |
'k' => $materials_value |
494 |
) |
495 |
); |
496 |
ModItemFromMarc( $item_record, $biblionumber, $itemnumber ); |
497 |
$item = Koha::Items->find( $itemnumber ); |
498 |
is( $item->materials, $materials_value, 'Subfield mapping is taken from the biblio\'s framework' ); |
499 |
|
500 |
$schema->storage->txn_rollback; |
501 |
}; |
502 |
|
427 |
subtest 'Koha::Item(s) tests' => sub { |
503 |
subtest 'Koha::Item(s) tests' => sub { |
428 |
|
504 |
|
429 |
plan tests => 5; |
505 |
plan tests => 5; |
Lines 563-565
sub get_biblio {
Link Here
|
563 |
my ($bibnum, $bibitemnum) = AddBiblio($bib, ''); |
639 |
my ($bibnum, $bibitemnum) = AddBiblio($bib, ''); |
564 |
return ($bibnum, $bibitemnum); |
640 |
return ($bibnum, $bibitemnum); |
565 |
} |
641 |
} |
566 |
- |
642 |
|
|
|
643 |
1; |