From fb95871809570acab02b002ec182116b75e6a551 Mon Sep 17 00:00:00 2001 From: David Gustafsson Date: Thu, 16 Nov 2023 18:24:07 +0100 Subject: [PATCH] Bug 33268: Add tests for context module priority Signed-off-by: David Nind --- t/db_dependent/Biblio/MarcOverlayRules.t | 65 +++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Biblio/MarcOverlayRules.t b/t/db_dependent/Biblio/MarcOverlayRules.t index 4156907645..7bd4249320 100755 --- a/t/db_dependent/Biblio/MarcOverlayRules.t +++ b/t/db_dependent/Biblio/MarcOverlayRules.t @@ -684,7 +684,7 @@ $skip_all_rule->delete(); # Test module filter specificity subtest 'Module filter precedence tests' => sub { - plan tests => 7; + plan tests => 9; $rule->set( { @@ -868,6 +868,69 @@ subtest 'Module filter precedence tests' => sub { 'Wildcard filter rules with tags with tag regexps matching the same tag as regexps for non wildcard filter rules has been overridden' ); + my $categorycode_matching_filter_rule_protect = Koha::MarcOverlayRules->find_or_create( + { + tag => '*', + module => 'categorycode', + filter => 'C', + add => 0, + append => 0, + remove => 0, + delete => 0 + } + ); + + # Current rules: + # source: *, tag: *, add: 0, append: 0, remove: 0, delete: 0 + # source: *, tag: 5\d{2}, add: 1, append: 1, remove: 1, delete: 1 + # source: test, tag: 250, add: 1, append: 1, remove: 1, delete: 1 + # source: test, tag: 5\d{2}, add: 0, append: 0, remove: 0, delete: 0 + # categorycode: C, tag: *, add: 0, append: 0, remove: 0, delete: 0 + $merged_record = Koha::MarcOverlayRules->merge_records( + $orig_record, + $incoming_record, + { 'source' => 'test', 'categorycode' => 'C' } + ); + + is( + $merged_record->as_formatted, + $orig_record->as_formatted, + 'If both categorycode and source module contexts matches, rules from categorycode module context are used' + ); + + my $userid_matching_filter_rule_protect = Koha::MarcOverlayRules->find_or_create( + { + tag => '*', + module => 'userid', + filter => '123', + add => 1, + append => 1, + remove => 1, + delete => 1 + } + ); + + # Current rules: + # source: *, tag: *, add: 0, append: 0, remove: 0, delete: 0 + # source: *, tag: 5\d{2}, add: 1, append: 1, remove: 1, delete: 1 + # source: test, tag: 250, add: 1, append: 1, remove: 1, delete: 1 + # source: test, tag: 5\d{2}, add: 0, append: 0, remove: 0, delete: 0 + # categorycode: C, tag: *, add: 0, append: 0, remove: 0, delete: 0 + # userid: 123, tag: *, add: 1, append: 1, remove: 1, delete: 1 + $merged_record = Koha::MarcOverlayRules->merge_records( + $orig_record, + $incoming_record, + { 'source' => 'test', 'categorycode' => 'C', 'userid' => '123' } + ); + + is( + $merged_record->as_formatted, + $incoming_record->as_formatted, + 'If both userid, categorycode and source module contexts matches, rules from userid module context are used' + ); + + $categorycode_matching_filter_rule_protect->delete(); + $userid_matching_filter_rule_protect->delete(); $wildcard_filter_rule_overwrite->delete(); $matching_filter_rule_overwrite->delete(); $matching_filter_rule_protect->delete(); -- 2.30.2