View | Details | Raw Unified | Return to bug 33268
Collapse All | Expand All

(-)a/t/db_dependent/Biblio/MarcOverlayRules.t (-67 / +123 lines)
Lines 66-79 my $orig_record = build_record([ Link Here
66
    [ '500', 'a', 'One bottle of beer in the fridge' ],
66
    [ '500', 'a', 'One bottle of beer in the fridge' ],
67
]);
67
]);
68
68
69
my $incoming_record = build_record([
69
my $incoming_record = build_record(
70
    ['250', 'a', '256 bottles of beer on the wall'], # Unchanged
70
    [
71
    ['250', 'a', '251 bottles of beer on the wall'], # Appended
71
        [ '250', 'a', '256 bottles of beer on the wall' ],        # Unchanged
72
    #['250', 'a', '250 bottles of beer on the wall'], # Removed
72
        [ '250', 'a', '251 bottles of beer on the wall' ],        # Appended
73
    #['500', 'a', 'One bottle of beer in the fridge'], # Deleted
73
      # ['250', 'a', '250 bottles of beer on the wall'],          # Removed
74
    ['501', 'a', 'One cold bottle of beer in the fridge'], # Added
74
      # ['500', 'a', 'One bottle of beer in the fridge'],         # Deleted
75
    ['501', 'a', 'Two cold bottles of beer in the fridge'], # Added
75
        [ '501', 'a', 'One cold bottle of beer in the fridge' ],  # Added
76
]);
76
        [ '501', 'a', 'Two cold bottles of beer in the fridge' ], # Added
77
    ]
78
);
77
79
78
# Test default behavior when MARCOverlayRules is enabled, but no rules defined (overwrite)
80
# Test default behavior when MARCOverlayRules is enabled, but no rules defined (overwrite)
79
subtest 'No rule defined' => sub {
81
subtest 'No rule defined' => sub {
Lines 684-697 $skip_all_rule->delete(); Link Here
684
686
685
# Test module filter specificity
687
# Test module filter specificity
686
subtest 'Module filter precedence tests' => sub {
688
subtest 'Module filter precedence tests' => sub {
687
    plan tests => 7;
689
    plan tests => 9;
688
690
689
    $rule->set(
691
    $rule->set(
690
        {
692
        {
691
            tag => '*',
693
            tag    => '*',
692
            module => 'source',
694
            module => 'source',
693
            filter => '*',
695
            filter => '*',
694
            add => 0,
696
            add    => 0,
695
            append => 0,
697
            append => 0,
696
            remove => 0,
698
            remove => 0,
697
            delete => 0,
699
            delete => 0,
Lines 700-709 subtest 'Module filter precedence tests' => sub { Link Here
700
702
701
    my $matching_filter_rule_overwrite = Koha::MarcOverlayRules->find_or_create(
703
    my $matching_filter_rule_overwrite = Koha::MarcOverlayRules->find_or_create(
702
        {
704
        {
703
            tag => '*',
705
            tag    => '*',
704
            module => 'source',
706
            module => 'source',
705
            filter => 'test',
707
            filter => 'test',
706
            add => 1,
708
            add    => 1,
707
            append => 1,
709
            append => 1,
708
            remove => 1,
710
            remove => 1,
709
            delete => 1
711
            delete => 1
Lines 713-719 subtest 'Module filter precedence tests' => sub { Link Here
713
    # Current rules:
715
    # Current rules:
714
    # source: *, tag: *, add: 0, append: 0, remove: 0, delete: 0
716
    # source: *, tag: *, add: 0, append: 0, remove: 0, delete: 0
715
    # source: test, tag: *, add: 1, append: 1, remove: 1, delete: 1
717
    # source: test, tag: *, add: 1, append: 1, remove: 1, delete: 1
716
    my $merged_record = Koha::MarcOverlayRules->merge_records($orig_record, $incoming_record, { 'source' => 'test' });
718
    my $merged_record = Koha::MarcOverlayRules->merge_records( $orig_record, $incoming_record, { 'source' => 'test' } );
717
719
718
    is(
720
    is(
719
        $merged_record->as_formatted,
721
        $merged_record->as_formatted,
Lines 721-736 subtest 'Module filter precedence tests' => sub { Link Here
721
        'Non wildcard rule with wildcard tag matches and overrides wildcard rule with wildcard tag'
723
        'Non wildcard rule with wildcard tag matches and overrides wildcard rule with wildcard tag'
722
    );
724
    );
723
725
724
    $rule->set(
726
    $rule->set( { tag => '5\d{2}' } )->store();
725
        {
726
            tag => '5\d{2}'
727
        }
728
    )->store();
729
727
730
    # Current rules:
728
    # Current rules:
731
    # source: *, tag: 5\d{2}, add: 0, append: 0, remove: 0, delete: 0
729
    # source: *, tag: 5\d{2}, add: 0, append: 0, remove: 0, delete: 0
732
    # source: test, tag: *, add: 1, append: 1, remove: 1, delete: 1
730
    # source: test, tag: *, add: 1, append: 1, remove: 1, delete: 1
733
    $merged_record = Koha::MarcOverlayRules->merge_records($orig_record, $incoming_record, { 'source' => 'test' });
731
    $merged_record = Koha::MarcOverlayRules->merge_records( $orig_record, $incoming_record, { 'source' => 'test' } );
734
732
735
    is(
733
    is(
736
        $merged_record->as_formatted,
734
        $merged_record->as_formatted,
Lines 738-753 subtest 'Module filter precedence tests' => sub { Link Here
738
        'Non wildcard rule with wildcard tag matches and overrides wildcard rules with regexp tags'
736
        'Non wildcard rule with wildcard tag matches and overrides wildcard rules with regexp tags'
739
    );
737
    );
740
738
741
    $rule->set(
739
    $rule->set( { tag => '501' } )->store();
742
        {
743
            tag => '501'
744
        }
745
    )->store();
746
740
747
    # Current rules:
741
    # Current rules:
748
    # source: *, tag: 501, add: 0, append: 0, remove: 0, delete: 0
742
    # source: *, tag: 501, add: 0, append: 0, remove: 0, delete: 0
749
    # source: test, tag: *, add: 1, append: 1, remove: 1, delete: 1
743
    # source: test, tag: *, add: 1, append: 1, remove: 1, delete: 1
750
    $merged_record = Koha::MarcOverlayRules->merge_records($orig_record, $incoming_record, { 'source' => 'test' });
744
    $merged_record = Koha::MarcOverlayRules->merge_records( $orig_record, $incoming_record, { 'source' => 'test' } );
751
745
752
    is(
746
    is(
753
        $merged_record->as_formatted,
747
        $merged_record->as_formatted,
Lines 755-798 subtest 'Module filter precedence tests' => sub { Link Here
755
        'Non wildcard rule with wildcard tag matches and overrides wildcard rules with specific tags'
749
        'Non wildcard rule with wildcard tag matches and overrides wildcard rules with specific tags'
756
    );
750
    );
757
751
758
    $rule->set(
752
    $rule->set( { tag => '*' } )->store();
759
        {
760
            tag => '*'
761
        }
762
    )->store();
763
753
764
    my $wildcard_filter_rule_overwrite = Koha::MarcOverlayRules->find_or_create(
754
    my $wildcard_filter_rule_overwrite = Koha::MarcOverlayRules->find_or_create(
765
        {
755
        {
766
            tag => '501',
756
            tag    => '501',
767
            module => 'source',
757
            module => 'source',
768
            filter => '*',
758
            filter => '*',
769
            add => 1,
759
            add    => 1,
770
            append => 1,
760
            append => 1,
771
            remove => 1,
761
            remove => 1,
772
            delete => 1,
762
            delete => 1,
773
        }
763
        }
774
    );
764
    );
775
765
776
    $matching_filter_rule_overwrite->set(
766
    $matching_filter_rule_overwrite->set( { tag => '250' } )->store();
777
        {
778
            tag => '250'
779
        }
780
    )->store();
781
767
782
    # Current rules:
768
    # Current rules:
783
    # source: *, tag: *, add: 0, append: 0, remove: 0, delete: 0
769
    # source: *, tag: *, add: 0, append: 0, remove: 0, delete: 0
784
    # source: *, tag: 501, add: 1, append: 1, remove: 1, delete: 1
770
    # source: *, tag: 501, add: 1, append: 1, remove: 1, delete: 1
785
    # source: test, tag: 250, add: 1, append: 1, remove: 1, delete: 1
771
    # source: test, tag: 250, add: 1, append: 1, remove: 1, delete: 1
786
    $merged_record = Koha::MarcOverlayRules->merge_records($orig_record, $incoming_record, { 'source' => 'test' });
772
    $merged_record = Koha::MarcOverlayRules->merge_records( $orig_record, $incoming_record, { 'source' => 'test' } );
787
773
788
    my $expected_record = build_record([
774
    my $expected_record = build_record(
789
        ['250', 'a', '256 bottles of beer on the wall'], # Unchanged
775
        [
790
        ['250', 'a', '251 bottles of beer on the wall'], # Appended
776
            [ '250', 'a', '256 bottles of beer on the wall' ],    # Unchanged
791
        #['250', 'a', '250 bottles of beer on the wall'], # Removed
777
            [ '250', 'a', '251 bottles of beer on the wall' ],    # Appended
792
        ['500', 'a', 'One bottle of beer in the fridge'], # Protected
778
                #['250', 'a', '250 bottles of beer on the wall'], # Removed
793
        ['501', 'a', 'One cold bottle of beer in the fridge'], # Added
779
            [ '500', 'a', 'One bottle of beer in the fridge' ],          # Protected
794
        ['501', 'a', 'Two cold bottles of beer in the fridge'], # Added
780
            [ '501', 'a', 'One cold bottle of beer in the fridge' ],     # Added
795
    ]);
781
            [ '501', 'a', 'Two cold bottles of beer in the fridge' ],    # Added
782
        ]
783
    );
796
784
797
    is(
785
    is(
798
        $merged_record->as_formatted,
786
        $merged_record->as_formatted,
Lines 802-811 subtest 'Module filter precedence tests' => sub { Link Here
802
790
803
    my $matching_filter_rule_protect = Koha::MarcOverlayRules->find_or_create(
791
    my $matching_filter_rule_protect = Koha::MarcOverlayRules->find_or_create(
804
        {
792
        {
805
            tag => '501',
793
            tag    => '501',
806
            module => 'source',
794
            module => 'source',
807
            filter => 'test',
795
            filter => 'test',
808
            add => 0,
796
            add    => 0,
809
            append => 0,
797
            append => 0,
810
            remove => 0,
798
            remove => 0,
811
            delete => 0
799
            delete => 0
Lines 817-832 subtest 'Module filter precedence tests' => sub { Link Here
817
    # source: *, tag: 501, add: 1, append: 1, remove: 1, delete: 1
805
    # source: *, tag: 501, add: 1, append: 1, remove: 1, delete: 1
818
    # source: test, tag: 250, add: 1, append: 1, remove: 1, delete: 1
806
    # source: test, tag: 250, add: 1, append: 1, remove: 1, delete: 1
819
    # source: test, tag: 501, add: 0, append: 0, remove: 0, delete: 0
807
    # source: test, tag: 501, add: 0, append: 0, remove: 0, delete: 0
820
    $merged_record = Koha::MarcOverlayRules->merge_records($orig_record, $incoming_record, { 'source' => 'test' });
808
    $merged_record = Koha::MarcOverlayRules->merge_records( $orig_record, $incoming_record, { 'source' => 'test' } );
821
809
822
    $expected_record = build_record([
810
    $expected_record = build_record(
823
        ['250', 'a', '256 bottles of beer on the wall'], # Unchanged
811
        [
824
        ['250', 'a', '251 bottles of beer on the wall'], # Appended
812
            [ '250', 'a', '256 bottles of beer on the wall' ],    # Unchanged
825
        #['250', 'a', '250 bottles of beer on the wall'], # Removed
813
            [ '250', 'a', '251 bottles of beer on the wall' ],    # Appended
826
        ['500', 'a', 'One bottle of beer in the fridge'], # Protected
814
                #['250', 'a', '250 bottles of beer on the wall'], # Removed
827
        #['501', 'a', 'One cold bottle of beer in the fridge'], # Protected
815
            [ '500', 'a', 'One bottle of beer in the fridge' ],    # Protected
828
        #['501', 'a', 'Two cold bottles of beer in the fridge'], # Protected
816
                #['501', 'a', 'One cold bottle of beer in the fridge'], # Protected
829
    ]);
817
                #['501', 'a', 'Two cold bottles of beer in the fridge'], # Protected
818
        ]
819
    );
830
820
831
    is(
821
    is(
832
        $merged_record->as_formatted,
822
        $merged_record->as_formatted,
Lines 834-849 subtest 'Module filter precedence tests' => sub { Link Here
834
        'Wildcard filter rule has been overridden by non wildcard filter rule with same tag'
824
        'Wildcard filter rule has been overridden by non wildcard filter rule with same tag'
835
    );
825
    );
836
826
837
    $matching_filter_rule_protect->set({
827
    $matching_filter_rule_protect->set(
838
        tag => '5\d{2}',
828
        {
839
    })->store();
829
            tag => '5\d{2}',
830
        }
831
    )->store();
840
832
841
    # Current rules:
833
    # Current rules:
842
    # source: *, tag: *, add: 0, append: 0, remove: 0, delete: 0
834
    # source: *, tag: *, add: 0, append: 0, remove: 0, delete: 0
843
    # source: *, tag: 501, add: 1, append: 1, remove: 1, delete: 1
835
    # source: *, tag: 501, add: 1, append: 1, remove: 1, delete: 1
844
    # source: test, tag: 250, add: 1, append: 1, remove: 1, delete: 1
836
    # source: test, tag: 250, add: 1, append: 1, remove: 1, delete: 1
845
    # source: test, tag: 5\d{2}, add: 0, append: 0, remove: 0, delete: 0
837
    # source: test, tag: 5\d{2}, add: 0, append: 0, remove: 0, delete: 0
846
    $merged_record = Koha::MarcOverlayRules->merge_records($orig_record, $incoming_record, { 'source' => 'test' });
838
    $merged_record = Koha::MarcOverlayRules->merge_records( $orig_record, $incoming_record, { 'source' => 'test' } );
847
839
848
    is(
840
    is(
849
        $merged_record->as_formatted,
841
        $merged_record->as_formatted,
Lines 851-866 subtest 'Module filter precedence tests' => sub { Link Here
851
        'Wildcard filter rules with tags that matches tag regexps for non wildcard filter rules has been overridden'
843
        'Wildcard filter rules with tags that matches tag regexps for non wildcard filter rules has been overridden'
852
    );
844
    );
853
845
854
    $wildcard_filter_rule_overwrite->set({
846
    $wildcard_filter_rule_overwrite->set(
855
        tag => '5\d{2}',
847
        {
856
    })->store();
848
            tag => '5\d{2}',
849
        }
850
    )->store();
857
851
858
    # Current rules:
852
    # Current rules:
859
    # source: *, tag: *, add: 0, append: 0, remove: 0, delete: 0
853
    # source: *, tag: *, add: 0, append: 0, remove: 0, delete: 0
860
    # source: *, tag: 5\d{2}, add: 1, append: 1, remove: 1, delete: 1
854
    # source: *, tag: 5\d{2}, add: 1, append: 1, remove: 1, delete: 1
861
    # source: test, tag: 250, add: 1, append: 1, remove: 1, delete: 1
855
    # source: test, tag: 250, add: 1, append: 1, remove: 1, delete: 1
862
    # source: test, tag: 5\d{2}, add: 0, append: 0, remove: 0, delete: 0
856
    # source: test, tag: 5\d{2}, add: 0, append: 0, remove: 0, delete: 0
863
    $merged_record = Koha::MarcOverlayRules->merge_records($orig_record, $incoming_record, { 'source' => 'test' });
857
    $merged_record = Koha::MarcOverlayRules->merge_records( $orig_record, $incoming_record, { 'source' => 'test' } );
864
858
865
    is(
859
    is(
866
        $merged_record->as_formatted,
860
        $merged_record->as_formatted,
Lines 868-873 subtest 'Module filter precedence tests' => sub { Link Here
868
        'Wildcard filter rules with tags with tag regexps matching the same tag as regexps for non wildcard filter rules has been overridden'
862
        'Wildcard filter rules with tags with tag regexps matching the same tag as regexps for non wildcard filter rules has been overridden'
869
    );
863
    );
870
864
865
    my $categorycode_matching_filter_rule_protect = Koha::MarcOverlayRules->find_or_create(
866
        {
867
            tag    => '*',
868
            module => 'categorycode',
869
            filter => 'C',
870
            add    => 0,
871
            append => 0,
872
            remove => 0,
873
            delete => 0
874
        }
875
    );
876
877
    # Current rules:
878
    # source: *, tag: *, add: 0, append: 0, remove: 0, delete: 0
879
    # source: *, tag: 5\d{2}, add: 1, append: 1, remove: 1, delete: 1
880
    # source: test, tag: 250, add: 1, append: 1, remove: 1, delete: 1
881
    # source: test, tag: 5\d{2}, add: 0, append: 0, remove: 0, delete: 0
882
    # categorycode: C, tag: *, add: 0, append: 0, remove: 0, delete: 0
883
    $merged_record = Koha::MarcOverlayRules->merge_records(
884
        $orig_record,
885
        $incoming_record,
886
        { 'source' => 'test', 'categorycode' => 'C' }
887
    );
888
889
    is(
890
        $merged_record->as_formatted,
891
        $orig_record->as_formatted,
892
        'If both categorycode and source module contexts matches, rules from categorycode module context are used'
893
    );
894
895
    my $userid_matching_filter_rule_protect = Koha::MarcOverlayRules->find_or_create(
896
        {
897
            tag    => '*',
898
            module => 'userid',
899
            filter => '123',
900
            add    => 1,
901
            append => 1,
902
            remove => 1,
903
            delete => 1
904
        }
905
    );
906
907
    # Current rules:
908
    # source: *, tag: *, add: 0, append: 0, remove: 0, delete: 0
909
    # source: *, tag: 5\d{2}, add: 1, append: 1, remove: 1, delete: 1
910
    # source: test, tag: 250, add: 1, append: 1, remove: 1, delete: 1
911
    # source: test, tag: 5\d{2}, add: 0, append: 0, remove: 0, delete: 0
912
    # categorycode: C, tag: *, add: 0, append: 0, remove: 0, delete: 0
913
    # userid: 123, tag: *, add: 1, append: 1, remove: 1, delete: 1
914
    $merged_record = Koha::MarcOverlayRules->merge_records(
915
        $orig_record,
916
        $incoming_record,
917
        { 'source' => 'test', 'categorycode' => 'C', 'userid' => '123' }
918
    );
919
920
    is(
921
        $merged_record->as_formatted,
922
        $incoming_record->as_formatted,
923
        'If both userid, categorycode and source module contexts matches, rules from userid module context are used'
924
    );
925
926
    $categorycode_matching_filter_rule_protect->delete();
927
    $userid_matching_filter_rule_protect->delete();
871
    $wildcard_filter_rule_overwrite->delete();
928
    $wildcard_filter_rule_overwrite->delete();
872
    $matching_filter_rule_overwrite->delete();
929
    $matching_filter_rule_overwrite->delete();
873
    $matching_filter_rule_protect->delete();
930
    $matching_filter_rule_protect->delete();
874
- 

Return to bug 33268