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