Bugzilla – Attachment 175939 Details for
Bug 33268
Overlay rules don't work correctly when source is set to *
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33268: Add tests
Bug-33268-Add-tests.patch (text/plain), 10.24 KB, created by
Victor Grousset/tuxayo
on 2024-12-25 23:25:25 UTC
(
hide
)
Description:
Bug 33268: Add tests
Filename:
MIME Type:
Creator:
Victor Grousset/tuxayo
Created:
2024-12-25 23:25:25 UTC
Size:
10.24 KB
patch
obsolete
>From 459390ea7e191286317b38c4f6c97a5ecc63d2a1 Mon Sep 17 00:00:00 2001 >From: David Gustafsson <david.gustafsson@ub.gu.se> >Date: Tue, 14 Nov 2023 19:56:32 +0100 >Subject: [PATCH] Bug 33268: Add tests > >Sponsored-by: Gothenburg University Library >Signed-off-by: David Nind <david@davidnind.com> >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Signed-off-by: Jan Kissig <bibliothek@th-wildau.de> >Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> >--- > t/db_dependent/Biblio/MarcOverlayRules.t | 195 +++++++++++++++++++++-- > 1 file changed, 182 insertions(+), 13 deletions(-) > >diff --git a/t/db_dependent/Biblio/MarcOverlayRules.t b/t/db_dependent/Biblio/MarcOverlayRules.t >index 9ba27a93b9..d53b0dc15c 100755 >--- a/t/db_dependent/Biblio/MarcOverlayRules.t >+++ b/t/db_dependent/Biblio/MarcOverlayRules.t >@@ -64,19 +64,16 @@ my $orig_record = build_record([ > [ '250', 'a', '250 bottles of beer on the wall' ], > [ '250', 'a', '256 bottles of beer on the wall' ], > [ '500', 'a', 'One bottle of beer in the fridge' ], >-] >-); >+]); > >-my $incoming_record = build_record( >- [ >+my $incoming_record = build_record([ > ['250', 'a', '256 bottles of beer on the wall'], # Unchanged > ['250', 'a', '251 bottles of beer on the wall'], # Appended > #['250', 'a', '250 bottles of beer on the wall'], # Removed > #['500', 'a', 'One bottle of beer in the fridge'], # Deleted > ['501', 'a', 'One cold bottle of beer in the fridge'], # Added > ['501', 'a', 'Two cold bottles of beer in the fridge'], # Added >-] >-); >+]); > > # Test default behavior when MARCOverlayRules is enabled, but no rules defined (overwrite) > subtest 'No rule defined' => sub { >@@ -685,24 +682,195 @@ subtest '"5XX" fields has been protected when rule matching on regexp "5\d{2}" i > > $skip_all_rule->delete(); > >-# Test module specificity, the 0 all rule should no longer be included in set of applied rules >-subtest 'Record fields has been overwritten when non wild card rule with filter match is add = 1, append = 1, remove = 1, delete = 1' => sub { >- plan tests => 1; >+# Test module filter specificity >+subtest 'Module filter precedence tests' => sub { >+ plan tests => 7; > > $rule->set( > { >- 'filter' => 'test', >+ tag => '*', >+ module => 'source', >+ filter => '*', >+ add => 0, >+ append => 0, >+ remove => 0, >+ delete => 0, > } > )->store(); > >+ my $matching_filter_rule_overwrite = Koha::MarcOverlayRules->find_or_create( >+ { >+ tag => '*', >+ module => 'source', >+ filter => 'test', >+ add => 1, >+ append => 1, >+ remove => 1, >+ delete => 1 >+ } >+ ); >+ >+ # Current rules: >+ # source: *, tag: *, add: 0, append: 0, remove: 0, delete: 0 >+ # source: test, tag: *, add: 1, append: 1, remove: 1, delete: 1 > my $merged_record = Koha::MarcOverlayRules->merge_records($orig_record, $incoming_record, { 'source' => 'test' }); > > is( > $merged_record->as_formatted, > $incoming_record->as_formatted, >- 'Only existing rule is not for us, erasing' # FIXME Is this comment correct? >+ 'Non wildcard rule with wildcard tag matches and overrides wildcard rule with wildcard tag' >+ ); >+ >+ $rule->set( >+ { >+ tag => '5\d{2}' >+ } >+ )->store(); >+ >+ # Current rules: >+ # source: *, tag: 5\d{2}, add: 0, append: 0, remove: 0, delete: 0 >+ # source: test, tag: *, add: 1, append: 1, remove: 1, delete: 1 >+ $merged_record = Koha::MarcOverlayRules->merge_records($orig_record, $incoming_record, { 'source' => 'test' }); >+ >+ is( >+ $merged_record->as_formatted, >+ $incoming_record->as_formatted, >+ 'Non wildcard rule with wildcard tag matches and overrides wildcard rules with regexp tags' >+ ); >+ >+ $rule->set( >+ { >+ tag => '501' >+ } >+ )->store(); >+ >+ # Current rules: >+ # source: *, tag: 501, add: 0, append: 0, remove: 0, delete: 0 >+ # source: test, tag: *, add: 1, append: 1, remove: 1, delete: 1 >+ $merged_record = Koha::MarcOverlayRules->merge_records($orig_record, $incoming_record, { 'source' => 'test' }); >+ >+ is( >+ $merged_record->as_formatted, >+ $incoming_record->as_formatted, >+ 'Non wildcard rule with wildcard tag matches and overrides wildcard rules with specific tags' > ); > >+ $rule->set( >+ { >+ tag => '*' >+ } >+ )->store(); >+ >+ my $wildcard_filter_rule_overwrite = Koha::MarcOverlayRules->find_or_create( >+ { >+ tag => '501', >+ module => 'source', >+ filter => '*', >+ add => 1, >+ append => 1, >+ remove => 1, >+ delete => 1, >+ } >+ ); >+ >+ $matching_filter_rule_overwrite->set( >+ { >+ tag => '250' >+ } >+ )->store(); >+ >+ # Current rules: >+ # source: *, tag: *, add: 0, append: 0, remove: 0, delete: 0 >+ # source: *, tag: 501, add: 1, append: 1, remove: 1, delete: 1 >+ # source: test, tag: 250, add: 1, append: 1, remove: 1, delete: 1 >+ $merged_record = Koha::MarcOverlayRules->merge_records($orig_record, $incoming_record, { 'source' => 'test' }); >+ >+ my $expected_record = build_record([ >+ ['250', 'a', '256 bottles of beer on the wall'], # Unchanged >+ ['250', 'a', '251 bottles of beer on the wall'], # Appended >+ #['250', 'a', '250 bottles of beer on the wall'], # Removed >+ ['500', 'a', 'One bottle of beer in the fridge'], # Protected >+ ['501', 'a', 'One cold bottle of beer in the fridge'], # Added >+ ['501', 'a', 'Two cold bottles of beer in the fridge'], # Added >+ ]); >+ >+ is( >+ $merged_record->as_formatted, >+ $expected_record->as_formatted, >+ 'Rules have been merged when non wildcard filter context does not contain any wildcard tag rules' >+ ); >+ >+ my $matching_filter_rule_protect = Koha::MarcOverlayRules->find_or_create( >+ { >+ tag => '501', >+ module => 'source', >+ filter => 'test', >+ add => 0, >+ append => 0, >+ remove => 0, >+ delete => 0 >+ } >+ ); >+ >+ # Current rules: >+ # source: *, tag: *, add: 0, append: 0, remove: 0, delete: 0 >+ # source: *, tag: 501, add: 1, append: 1, remove: 1, delete: 1 >+ # source: test, tag: 250, add: 1, append: 1, remove: 1, delete: 1 >+ # source: test, tag: 501, add: 0, append: 0, remove: 0, delete: 0 >+ $merged_record = Koha::MarcOverlayRules->merge_records($orig_record, $incoming_record, { 'source' => 'test' }); >+ >+ $expected_record = build_record([ >+ ['250', 'a', '256 bottles of beer on the wall'], # Unchanged >+ ['250', 'a', '251 bottles of beer on the wall'], # Appended >+ #['250', 'a', '250 bottles of beer on the wall'], # Removed >+ ['500', 'a', 'One bottle of beer in the fridge'], # Protected >+ #['501', 'a', 'One cold bottle of beer in the fridge'], # Protected >+ #['501', 'a', 'Two cold bottles of beer in the fridge'], # Protected >+ ]); >+ >+ is( >+ $merged_record->as_formatted, >+ $expected_record->as_formatted, >+ 'Wildcard filter rule has been overridden by non wildcard filter rule with same tag' >+ ); >+ >+ $matching_filter_rule_protect->set({ >+ tag => '5\d{2}', >+ })->store(); >+ >+ # Current rules: >+ # source: *, tag: *, add: 0, append: 0, remove: 0, delete: 0 >+ # source: *, tag: 501, 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 >+ $merged_record = Koha::MarcOverlayRules->merge_records($orig_record, $incoming_record, { 'source' => 'test' }); >+ >+ is( >+ $merged_record->as_formatted, >+ $expected_record->as_formatted, >+ 'Wildcard filter rules with tags that matches tag regexps for non wildcard filter rules has been overridden' >+ ); >+ >+ $wildcard_filter_rule_overwrite->set({ >+ tag => '5\d{2}', >+ })->store(); >+ >+ # 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 >+ $merged_record = Koha::MarcOverlayRules->merge_records($orig_record, $incoming_record, { 'source' => 'test' }); >+ >+ is( >+ $merged_record->as_formatted, >+ $expected_record->as_formatted, >+ 'Wildcard filter rules with tags with tag regexps matching the same tag as regexps for non wildcard filter rules has been overridden' >+ ); >+ >+ $wildcard_filter_rule_overwrite->delete(); >+ $matching_filter_rule_overwrite->delete(); >+ $matching_filter_rule_protect->delete(); > }; > > subtest 'An exception is thrown when append = 1, remove = 0 is set for control field rule' => sub { >@@ -765,7 +933,7 @@ subtest 'context option in ModBiblio is handled correctly' => sub { > my $expected_record = build_record([ > # "250" field has been appended > [ '250', 'a', '250 bottles of beer on the wall' ], # original >- [ '250', 'a', '256 bottles of beer on the wall' ], # incoming >+ [ '250', 'a', '256 bottles of beer on the wall' ], # original > [ '500', 'a', 'One bottle of beer in the fridge' ], # original > [ '999', 'c', $biblionumber, 'd', $biblioitemnumber ], # created by AddBiblio > ]); >@@ -791,10 +959,11 @@ subtest 'context option in ModBiblio is handled correctly' => sub { > my $updated_record = $biblio->get_from_storage->metadata->record; > > $expected_record = build_record([ >- # "250" field has been appended >+ # "250" field has been protected > [ '250', 'a', '250 bottles of beer on the wall' ], > [ '250', 'a', '256 bottles of beer on the wall' ], > [ '500', 'a', 'One bottle of beer in the fridge' ], >+ # "500" field has been appended > [ '500', 'a', 'One cold bottle of beer in the fridge' ], > [ '999', 'c', $biblionumber, 'd', $biblioitemnumber ], # created by AddBiblio > ]); >-- >2.47.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 33268
:
158956
|
159004
|
159058
|
159160
|
159161
|
159518
|
159519
|
160017
|
160018
|
162764
|
162766
|
162767
|
162785
|
162786
|
162796
|
162797
|
162798
|
162799
|
162800
|
162801
|
162802
|
162803
|
162804
|
162805
|
162936
|
162937
|
162938
|
162939
|
162940
|
175659
|
175660
|
175661
|
175662
|
175663
|
175939
|
175940
|
175941
|
175942
|
175943
|
176201
|
176202
|
176203
|
176204
|
176205