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

(-)a/t/db_dependent/Heading.t (-14 / +54 lines)
Lines 21-26 use warnings; Link Here
21
use Test::More tests => 4;
21
use Test::More tests => 4;
22
22
23
use t::lib::Mocks;
23
use t::lib::Mocks;
24
use Test::MockModule;;
24
25
25
BEGIN {
26
BEGIN {
26
    use_ok('C4::Heading', qw( field valid_heading_subfield ));
27
    use_ok('C4::Heading', qw( field valid_heading_subfield ));
Lines 63-102 subtest "UNIMARC tests" => sub { Link Here
63
};
64
};
64
65
65
subtest "_search tests" => sub {
66
subtest "_search tests" => sub {
66
    plan tests => 3;
67
68
    plan tests => 6;
67
69
68
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
70
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
69
    t::lib::Mocks::mock_preference('SearchEngine', 'Elasticsearch');
71
    t::lib::Mocks::mock_preference('SearchEngine', 'Elasticsearch');
70
    my $search = Test::MockModule->new('Koha::SearchEngine::Elasticsearch::Search');
72
    my $search = Test::MockModule->new('Koha::SearchEngine::Elasticsearch::Search');
71
73
72
    $search->mock(
74
    $search->mock('search_auth_compat', sub {
73
        'search_auth_compat',
75
        my $self = shift;
74
        sub {
76
        my $search_query = shift;
75
            my $self         = shift;
77
        return $search_query;
76
            my $search_query = shift;
78
    });
77
            return $search_query;
78
        }
79
    );
80
79
81
    my ( $field, $heading, $search_query, $terms );
82
80
83
    $field = MARC::Field->new( '100', ' ', '', a => 'Yankovic, Al', d => '1959-,' );
81
    my $field = MARC::Field->new( '650', ' ', '0', a => 'Uncles', x => 'Fiction' );
82
    my $heading = C4::Heading->new_from_field($field);
83
    my $search_query = $heading->_search( 'match-heading' );
84
    my $terms = $search_query->{query}->{bool}->{must};
85
    my $expected_terms = [
86
        { term => { 'match-heading.ci_raw' => 'Uncles generalsubdiv Fiction' } },
87
        { term => { 'subject-heading-thesaurus.ci_raw' => 'a' } },
88
    ];
89
    is_deeply( $terms, $expected_terms, "Search formed as expected for a subject with second indicator 0");
90
91
    $field = MARC::Field->new( '650', ' ', '3', a => 'Uncles', x => 'Fiction' );
84
    $heading = C4::Heading->new_from_field($field);
92
    $heading = C4::Heading->new_from_field($field);
85
    $search_query = $heading->_search( 'match-heading' );
93
    $search_query = $heading->_search( 'match-heading' );
86
    $terms = $search_query->{query}->{bool}->{must};
94
    $terms = $search_query->{query}->{bool}->{must};
87
    is_deeply( $terms->[0], { term => { 'match-heading.ci_raw' => 'Yankovic, Al 1959' } }, "Search formed as expected for a non-subject field with single punctuation mark");
95
    $expected_terms = [
96
        { term => { 'match-heading.ci_raw' => 'Uncles generalsubdiv Fiction' } },
97
        { term => { 'subject-heading-thesaurus.ci_raw' => 'd' } },
98
    ];
99
    is_deeply( $terms, $expected_terms, "Search formed as expected with second indicator 3");
88
100
101
    $field = MARC::Field->new( '650', ' ', '7', a => 'Uncles', x => 'Fiction', 2 => 'special_sauce' );
102
    $heading = C4::Heading->new_from_field($field);
103
    $search_query = $heading->_search( 'match-heading' );
104
    $terms = $search_query->{query}->{bool}->{must};
105
    $expected_terms = [
106
        { term => { 'match-heading.ci_raw' => 'Uncles generalsubdiv Fiction' } },
107
        { term => { 'subject-heading-thesaurus-conventions.ci_raw' => 'special_sauce' } },
108
        { term => { 'subject-heading-thesaurus.ci_raw' => 'z' } },
109
    ];
110
    is_deeply( $terms, $expected_terms, "Search formed as expected with second indicator 7 and subfield 2");
111
112
    $field = MARC::Field->new( '100', ' ', '', a => 'Yankovic, Al', d => '1959-,' );
113
    $heading = C4::Heading->new_from_field($field);
114
    $search_query = $heading->_search( 'match-heading' );
115
    $terms = $search_query->{query}->{bool}->{must};
116
    $expected_terms = [
117
        { term => { 'match-heading.ci_raw' => 'Yankovic, Al 1959' } },
118
        { term => { 'subject-heading-thesaurus.ci_raw' => 'a' } },
119
    ];
120
    is_deeply( $terms, $expected_terms, "Search formed as expected for a non-subject field with single punctuation mark");
89
121
90
    $field = MARC::Field->new( '100', ' ', '', a => 'Yankovic, Al', d => '1959-,', e => '[author]' );
122
    $field = MARC::Field->new( '100', ' ', '', a => 'Yankovic, Al', d => '1959-,', e => '[author]' );
91
    $heading = C4::Heading->new_from_field($field);
123
    $heading = C4::Heading->new_from_field($field);
92
    $search_query = $heading->_search( 'match-heading' );
124
    $search_query = $heading->_search( 'match-heading' );
93
    $terms = $search_query->{query}->{bool}->{must};
125
    $terms = $search_query->{query}->{bool}->{must};
94
    is_deeply( $terms->[0], { term => { 'match-heading.ci_raw' => 'Yankovic, Al 1959' } }, "Search formed as expected for a non-subject field with double punctuation, hyphen+comma");
126
    $expected_terms = [
127
        { term => { 'match-heading.ci_raw' => 'Yankovic, Al 1959' } },
128
        { term => { 'subject-heading-thesaurus.ci_raw' => 'a' } },
129
    ];
130
    is_deeply( $terms, $expected_terms, "Search formed as expected for a non-subject field with double punctuation, hyphen+comma");
95
131
96
    $field = MARC::Field->new( '100', ' ', '', a => 'Tolkien, J.R.R.,', e => '[author]' );
132
    $field = MARC::Field->new( '100', ' ', '', a => 'Tolkien, J.R.R.,', e => '[author]' );
97
    $heading = C4::Heading->new_from_field($field);
133
    $heading = C4::Heading->new_from_field($field);
98
    $search_query = $heading->_search( 'match-heading' );
134
    $search_query = $heading->_search( 'match-heading' );
99
    $terms = $search_query->{query}->{bool}->{must};
135
    $terms = $search_query->{query}->{bool}->{must};
100
    is_deeply( $terms->[0], { term => { 'match-heading.ci_raw' => 'Tolkien, J.R.R' } }, "Search formed as expected for a non-subject field with double punctuation, period+comma ");
136
    $expected_terms = [
137
        { term => { 'match-heading.ci_raw' => 'Tolkien, J.R.R' } },
138
        { term => { 'subject-heading-thesaurus.ci_raw' => 'a' } },
139
    ];
140
    is_deeply( $terms, $expected_terms, "Search formed as expected for a non-subject field with double punctuation, period+comma ");
101
141
102
};
142
};
(-)a/t/db_dependent/Heading_MARC21.t (-3 / +10 lines)
Lines 6-12 Link Here
6
use strict;
6
use strict;
7
use warnings;
7
use warnings;
8
8
9
use Test::More tests => 5;
9
use Test::More tests => 10;
10
use C4::Context;
10
use C4::Context;
11
11
12
BEGIN {
12
BEGIN {
Lines 15-28 BEGIN { Link Here
15
15
16
SKIP: {
16
SKIP: {
17
    skip "MARC21 heading tests not applicable to UNIMARC", 2 if C4::Context->preference('marcflavour') eq 'UNIMARC';
17
    skip "MARC21 heading tests not applicable to UNIMARC", 2 if C4::Context->preference('marcflavour') eq 'UNIMARC';
18
    my $field = MARC::Field->new( '650', ' ', '0', a => 'Uncles', x => 'Fiction' );
18
    my $field = MARC::Field->new( '650', ' ', '2', a => 'Uncles', x => 'Fiction' );
19
    my $heading = C4::Heading->new_from_field($field);
19
    my $heading = C4::Heading->new_from_field($field);
20
    is($heading->display_form(), 'Uncles--Fiction', 'Display form generation');
20
    is($heading->display_form(), 'Uncles--Fiction', 'Display form generation');
21
    is($heading->search_form(), 'Uncles generalsubdiv Fiction', 'Search form generation');
21
    is($heading->search_form(), 'Uncles generalsubdiv Fiction', 'Search form generation');
22
    is($heading->{thesaurus}, 'mesh', 'Thesaurus generation');
22
23
23
    $field = MARC::Field->new( '830', ' ', '4', a => 'The dark is rising ;', v => '3' );
24
    $field = MARC::Field->new( '830', ' ', '4', a => 'The dark is rising ;', v => '3' );
24
    $heading = C4::Heading->new_from_field($field);
25
    $heading = C4::Heading->new_from_field($field);
25
    is($heading->display_form(), 'The dark is rising ;', 'Display form generation');
26
    is($heading->display_form(), 'The dark is rising ;', 'Display form generation');
26
    is($heading->search_form(), 'The dark is rising', 'Search form generation');
27
    is($heading->search_form(), 'The dark is rising', 'Search form generation');
28
    is($heading->{thesaurus}, 'lcsh', 'Thesaurus generation');
29
30
    $field = MARC::Field->new( '100', '1', '', a => 'Yankovic, Al', d => '1959-' );
31
    $heading = C4::Heading->new_from_field($field);
32
    is($heading->display_form(), 'Yankovic, Al 1959-', 'Display form generation');
33
    is($heading->search_form(), 'Yankovic, Al 1959', 'Search form generation');
34
    is($heading->{thesaurus}, 'lcsh', 'Thesaurus generation');
27
35
28
}
36
}
29
- 

Return to bug 33159