Lines 18-26
Link Here
|
18 |
use strict; |
18 |
use strict; |
19 |
use warnings; |
19 |
use warnings; |
20 |
|
20 |
|
21 |
use Test::More tests => 3; |
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 60-63
subtest "UNIMARC tests" => sub {
Link Here
|
60 |
ok(!C4::Heading::valid_heading_subfield('600', 'i'), '600i not valid for bib'); |
61 |
ok(!C4::Heading::valid_heading_subfield('600', 'i'), '600i not valid for bib'); |
61 |
|
62 |
|
62 |
ok(!C4::Heading::valid_heading_subfield('012', 'a'), '012a invalid field for bib'); |
63 |
ok(!C4::Heading::valid_heading_subfield('012', 'a'), '012a invalid field for bib'); |
63 |
} |
64 |
}; |
|
|
65 |
|
66 |
subtest "_search tests" => sub { |
67 |
plan tests => 4; |
68 |
|
69 |
t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); |
70 |
t::lib::Mocks::mock_preference('SearchEngine', 'Elasticsearch'); |
71 |
my $search = Test::MockModule->new('Koha::SearchEngine::Elasticsearch::Search'); |
72 |
|
73 |
$search->mock('search_auth_compat', sub { |
74 |
my $self = shift; |
75 |
my $search_query = shift; |
76 |
return $search_query; |
77 |
}); |
78 |
|
79 |
my $field = MARC::Field->new( '650', ' ', '0', a => 'Uncles', x => 'Fiction' ); |
80 |
my $heading = C4::Heading->new_from_field($field); |
81 |
my $search_query = $heading->_search( 'match-heading' ); |
82 |
my $terms = $search_query->{query}->{bool}->{must}; |
83 |
my $expected_terms = [ |
84 |
{ term => { 'match-heading.ci_raw' => 'Uncles generalsubdiv Fiction' } }, |
85 |
{ term => { 'subject-heading-thesaurus.ci_raw' => 'a' } }, |
86 |
]; |
87 |
is_deeply( $terms, $expected_terms, "Search formed as expected for a subject with second indicator 0"); |
88 |
|
89 |
$field = MARC::Field->new( '650', ' ', '3', a => 'Uncles', x => 'Fiction' ); |
90 |
$heading = C4::Heading->new_from_field($field); |
91 |
$search_query = $heading->_search( 'match-heading' ); |
92 |
$terms = $search_query->{query}->{bool}->{must}; |
93 |
$expected_terms = [ |
94 |
{ term => { 'match-heading.ci_raw' => 'Uncles generalsubdiv Fiction' } }, |
95 |
{ term => { 'subject-heading-thesaurus.ci_raw' => 'd' } }, |
96 |
]; |
97 |
is_deeply( $terms, $expected_terms, "Search formed as expected with second indicator 3"); |
98 |
|
99 |
$field = MARC::Field->new( '650', ' ', '7', a => 'Uncles', x => 'Fiction', 2 => 'special_sauce' ); |
100 |
$heading = C4::Heading->new_from_field($field); |
101 |
$search_query = $heading->_search( 'match-heading' ); |
102 |
$terms = $search_query->{query}->{bool}->{must}; |
103 |
$expected_terms = [ |
104 |
{ term => { 'match-heading.ci_raw' => 'Uncles generalsubdiv Fiction' } }, |
105 |
{ term => { 'subject-heading-thesaurus-conventions.ci_raw' => 'special_sauce' } }, |
106 |
{ term => { 'subject-heading-thesaurus.ci_raw' => 'z' } }, |
107 |
]; |
108 |
is_deeply( $terms, $expected_terms, "Search formed as expected with second indicator 7 and subfield 2"); |
109 |
|
110 |
$field = MARC::Field->new( '100', ' ', '', a => 'Yankovic, Al', d => '1959-,', e => '[author]' ); |
111 |
$heading = C4::Heading->new_from_field($field); |
112 |
$search_query = $heading->_search( 'match-heading' ); |
113 |
$terms = $search_query->{query}->{bool}->{must}; |
114 |
$expected_terms = [ |
115 |
{ term => { 'match-heading.ci_raw' => 'Yankovic, Al 1959-' } }, |
116 |
{ term => { 'subject-heading-thesaurus.ci_raw' => 'a' } }, |
117 |
]; |
118 |
is_deeply( $terms, $expected_terms, "Search formed as expected for a non-subject field"); |
119 |
|
120 |
}; |