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 |
}; |