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

(-)a/t/db_dependent/Heading.t (-9 / +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-69 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');
Lines 75-97 subtest "_search tests" => sub { Link Here
75
        return $search_query;
77
        return $search_query;
76
    });
78
    });
77
79
78
    my $field = MARC::Field->new( '100', ' ', '', a => 'Yankovic, Al', d => '1959-,' );
80
81
    my $field = MARC::Field->new( '650', ' ', '0', a => 'Uncles', x => 'Fiction' );
79
    my $heading = C4::Heading->new_from_field($field);
82
    my $heading = C4::Heading->new_from_field($field);
80
    my $search_query = $heading->_search( 'match-heading' );
83
    my $search_query = $heading->_search( 'match-heading' );
81
    my $terms = $search_query->{query}->{bool}->{must};
84
    my $terms = $search_query->{query}->{bool}->{must};
82
    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");
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");
83
90
91
    $field = MARC::Field->new( '650', ' ', '3', a => 'Uncles', x => 'Fiction' );
92
    $heading = C4::Heading->new_from_field($field);
93
    $search_query = $heading->_search( 'match-heading' );
94
    $terms = $search_query->{query}->{bool}->{must};
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");
84
100
85
    my $field = MARC::Field->new( '100', ' ', '', a => 'Yankovic, Al', d => '1959-,', e => '[author]' );
101
    $field = MARC::Field->new( '650', ' ', '7', a => 'Uncles', x => 'Fiction', 2 => 'special_sauce' );
86
    my $heading = C4::Heading->new_from_field($field);
102
    $heading = C4::Heading->new_from_field($field);
87
    my $search_query = $heading->_search( 'match-heading' );
103
    $search_query = $heading->_search( 'match-heading' );
88
    my $terms = $search_query->{query}->{bool}->{must};
104
    $terms = $search_query->{query}->{bool}->{must};
89
    is_deeply( $terms->[0], { term => { 'match-heading.ci_raw' => 'Yankovic, Al 1959' } }, "Search formed as expected for a non-subject field with doulbe punctuation, hyphen+comma");
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");
121
122
    $field = MARC::Field->new( '100', ' ', '', a => 'Yankovic, Al', d => '1959-,', e => '[author]' );
123
    $heading = C4::Heading->new_from_field($field);
124
    $search_query = $heading->_search( 'match-heading' );
125
    $terms = $search_query->{query}->{bool}->{must};
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");
90
131
91
    $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]' );
92
    $heading = C4::Heading->new_from_field($field);
133
    $heading = C4::Heading->new_from_field($field);
93
    $search_query = $heading->_search( 'match-heading' );
134
    $search_query = $heading->_search( 'match-heading' );
94
    $terms = $search_query->{query}->{bool}->{must};
135
    $terms = $search_query->{query}->{bool}->{must};
95
    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 ");
96
141
97
};
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