|
Lines 24-30
use C4::Context;
Link Here
|
| 24 |
use C4::Biblio; |
24 |
use C4::Biblio; |
| 25 |
use Koha::Database; #?? |
25 |
use Koha::Database; #?? |
| 26 |
|
26 |
|
| 27 |
use Test::More tests => 22; |
27 |
use Test::More tests => 23; |
| 28 |
use Test::MockModule; |
28 |
use Test::MockModule; |
| 29 |
|
29 |
|
| 30 |
use Koha::MarcMergeRules; |
30 |
use Koha::MarcMergeRules; |
|
Lines 86-92
subtest 'Record fields has been overwritten when no merge rules are defined' =>
Link Here
|
| 86 |
|
86 |
|
| 87 |
my $rule = Koha::MarcMergeRules->find_or_create({ |
87 |
my $rule = Koha::MarcMergeRules->find_or_create({ |
| 88 |
tag => '*', |
88 |
tag => '*', |
| 89 |
module => $modules[0]->id, |
89 |
module => $modules[0]->name, |
| 90 |
filter => '*', |
90 |
filter => '*', |
| 91 |
add => 0, |
91 |
add => 0, |
| 92 |
append => 0, |
92 |
append => 0, |
|
Lines 585-591
subtest 'Record fields has been overwritten when add = 1, append = 1, remove = 1
Link Here
|
| 585 |
# Protect field 500 with more specific tag value |
585 |
# Protect field 500 with more specific tag value |
| 586 |
my $skip_all_rule = Koha::MarcMergeRules->find_or_create({ |
586 |
my $skip_all_rule = Koha::MarcMergeRules->find_or_create({ |
| 587 |
tag => '500', |
587 |
tag => '500', |
| 588 |
module => $modules[0]->id, |
588 |
module => $modules[0]->name, |
| 589 |
filter => '*', |
589 |
filter => '*', |
| 590 |
add => 0, |
590 |
add => 0, |
| 591 |
append => 0, |
591 |
append => 0, |
|
Lines 712-717
subtest 'An exception is thrown when rule tag is set to invalid regexp' => sub {
Link Here
|
| 712 |
ok($exception->isa('Koha::Exceptions::MarcMergeRule::InvalidTagRegExp'), "Exception is of correct class"); |
712 |
ok($exception->isa('Koha::Exceptions::MarcMergeRule::InvalidTagRegExp'), "Exception is of correct class"); |
| 713 |
}; |
713 |
}; |
| 714 |
|
714 |
|
|
|
715 |
$skip_all_rule->delete(); |
| 716 |
|
| 717 |
subtest 'context option in ModBiblio is handled correctly' => sub { |
| 718 |
plan tests => 6; |
| 719 |
$rule->set( |
| 720 |
{ |
| 721 |
tag => '250', |
| 722 |
module => $modules[0]->name, |
| 723 |
filter => '*', |
| 724 |
'add' => 0, |
| 725 |
'append' => 0, |
| 726 |
'remove' => 0, |
| 727 |
'delete' => 0, |
| 728 |
} |
| 729 |
); |
| 730 |
$rule->store(); |
| 731 |
my ($biblionumber) = AddBiblio($orig_record, ''); |
| 732 |
|
| 733 |
# Since marc merc rules are not run on save, only update |
| 734 |
# saved record should be identical to orig_record |
| 735 |
my $saved_record = GetMarcBiblio({ biblionumber => $biblionumber }); |
| 736 |
|
| 737 |
my @all_fields = $saved_record->fields(); |
| 738 |
# Koha also adds 999c field, therefore 4 not 3 |
| 739 |
cmp_ok(scalar @all_fields, '==', 4, 'Saved record has the expected number of fields'); |
| 740 |
is_deeply( |
| 741 |
[map { $_->subfield('a') } $saved_record->field('250') ], |
| 742 |
['250 bottles of beer on the wall', '256 bottles of beer on the wall'], |
| 743 |
'All "250" fields of saved record are identical to original record passed to AddBiblio' |
| 744 |
); |
| 745 |
|
| 746 |
is_deeply( |
| 747 |
[map { $_->subfield('a') } $saved_record->field('500') ], |
| 748 |
['One bottle of beer in the fridge'], |
| 749 |
'All "500" fields of saved record are identical to original record passed to AddBiblio' |
| 750 |
); |
| 751 |
|
| 752 |
$saved_record->append_fields( |
| 753 |
MARC::Field->new('250', '', '', 'a' => '251 bottles of beer on the wall'), # Appended |
| 754 |
MARC::Field->new('500', '', '', 'a' => 'One cold bottle of beer in the fridge'), # Appended |
| 755 |
); |
| 756 |
|
| 757 |
ModBiblio($saved_record, $biblionumber, '', { context => { $modules[0]->name => 'test' } }); |
| 758 |
|
| 759 |
my $updated_record = GetMarcBiblio({ biblionumber => $biblionumber }); |
| 760 |
|
| 761 |
@all_fields = $updated_record->fields(); |
| 762 |
cmp_ok(scalar @all_fields, '==', 5, 'Updated record has the expected number of fields'); |
| 763 |
is_deeply( |
| 764 |
[map { $_->subfield('a') } $updated_record->field('250') ], |
| 765 |
['250 bottles of beer on the wall', '256 bottles of beer on the wall'], |
| 766 |
'"250" fields have retained their original values' |
| 767 |
); |
| 768 |
|
| 769 |
is_deeply( |
| 770 |
[map { $_->subfield('a') } $updated_record->field('500') ], |
| 771 |
['One bottle of beer in the fridge', 'One cold bottle of beer in the fridge'], |
| 772 |
'"500" field has been appended' |
| 773 |
); |
| 774 |
|
| 775 |
# To trigger removal from search index etc |
| 776 |
DelBiblio($biblionumber); |
| 777 |
}; |
| 778 |
|
| 779 |
# Explicityly delete rule to trigger clearing of cache |
| 780 |
$rule->delete(); |
| 781 |
|
| 715 |
$schema->storage->txn_rollback; |
782 |
$schema->storage->txn_rollback; |
| 716 |
|
783 |
|
| 717 |
1; |
784 |
1; |
| 718 |
- |
|
|