|
Lines 23-29
our $child;
Link Here
|
| 23 |
|
23 |
|
| 24 |
subtest 'test_search' => sub { |
24 |
subtest 'test_search' => sub { |
| 25 |
|
25 |
|
| 26 |
plan tests => 20; |
26 |
plan tests => 27; |
| 27 |
|
27 |
|
| 28 |
t::lib::Mocks::mock_preference('SearchEngine', 'Elasticsearch'); |
28 |
t::lib::Mocks::mock_preference('SearchEngine', 'Elasticsearch'); |
| 29 |
|
29 |
|
|
Lines 66-83
subtest 'test_search' => sub {
Link Here
|
| 66 |
|
66 |
|
| 67 |
my $builder = Test::MockModule->new('Koha::SearchEngine::Elasticsearch::QueryBuilder'); |
67 |
my $builder = Test::MockModule->new('Koha::SearchEngine::Elasticsearch::QueryBuilder'); |
| 68 |
$builder->mock('build_query_compat', sub { |
68 |
$builder->mock('build_query_compat', sub { |
| 69 |
my ( $self, $operators, $operands ) = @_; |
69 |
my ( $self, $operators, $operands, undef, undef, $sort_by ) = @_; |
| 70 |
|
70 |
|
| 71 |
return (undef, $operands->[0]); |
71 |
my $query = $operands->[0]; |
|
|
72 |
if (scalar(@{$sort_by})) { |
| 73 |
$query .= ' sort ' . join(',', @{$sort_by}); |
| 74 |
} |
| 75 |
return (undef, $query); |
| 72 |
}); |
76 |
}); |
| 73 |
|
77 |
|
| 74 |
my $search = Test::MockModule->new('Koha::SearchEngine::Elasticsearch::Search'); |
78 |
my $search = Test::MockModule->new('Koha::SearchEngine::Elasticsearch::Search'); |
| 75 |
$search->mock('simple_search_compat', sub { |
79 |
$search->mock('simple_search_compat', sub { |
| 76 |
my ( $self, $query ) = @_; |
80 |
my ( $self, $query ) = @_; |
| 77 |
|
81 |
|
| 78 |
return ('unexpected query', undef, 0) unless $query eq '((author:(author)) AND ((title:(title\(s\))) OR (title:(speciäl))))' || $query eq "(simple search)"; |
82 |
return ('unexpected query', undef, 0) unless $query eq '((author:(author)) AND ((title:(title\(s\))) OR (title:(speciäl))))' |
|
|
83 |
|| $query eq '((author:(author)) AND ((title:(title\(s\))) OR (title:(speciäl)))) sort title_desc' |
| 84 |
|| $query eq "(simple search)"; |
| 79 |
|
85 |
|
| 80 |
my @records = ($marc_record_1, $marc_record_2); |
86 |
my @records; |
|
|
87 |
if ($query =~ / sort title_desc/) { |
| 88 |
@records = ($marc_record_2, $marc_record_1); |
| 89 |
} else { |
| 90 |
@records = ($marc_record_1, $marc_record_2); |
| 91 |
} |
| 81 |
return (undef, \@records, 2); |
92 |
return (undef, \@records, 2); |
| 82 |
}); |
93 |
}); |
| 83 |
|
94 |
|
|
Lines 151-156
subtest 'test_search' => sub {
Link Here
|
| 151 |
ok($returned2, 'Record 2 returned as MARCXML'); |
162 |
ok($returned2, 'Record 2 returned as MARCXML'); |
| 152 |
is($returned2->as_xml, $marc_record_2->as_xml, 'Record 2 returned properly'); |
163 |
is($returned2->as_xml, $marc_record_2->as_xml, 'Record 2 returned properly'); |
| 153 |
|
164 |
|
|
|
165 |
$agent->get_ok("$base/biblios?operation=searchRetrieve&recordSchema=marcxml&version=1.1&maximumRecords=10&query=(dc.author%3dauthor AND (dc.title%3d\"title(s)\" OR dc.title%3dspeciäl)) sortby title%2Fdescending", 'Retrieve search results'); |
| 166 |
$dom = XML::LibXML->load_xml(string => $agent->content()); |
| 167 |
@nodes = $dom->getElementsByTagNameNS($ns, 'searchRetrieveResponse'); |
| 168 |
is(scalar(@nodes), 1, 'sorted searchRetrieveResponse returned'); |
| 169 |
@records = $nodes[0]->getElementsByTagNameNS($marc_ns, 'record'); |
| 170 |
is(scalar(@records), 2, 'Two results returned'); |
| 171 |
|
| 172 |
$returned1 = MARC::Record->new_from_xml($records[0]->toString(), 'UTF-8'); |
| 173 |
ok($returned1, 'First record returned as MARCXML'); |
| 174 |
is($returned1->as_xml, $marc_record_2->as_xml, 'Record 2 returned first'); |
| 175 |
|
| 176 |
$returned2= MARC::Record->new_from_xml($records[1]->toString(), 'UTF-8'); |
| 177 |
ok($returned2, 'Second record returned as MARCXML'); |
| 178 |
is($returned2->as_xml, $marc_record_1->as_xml, 'Record 1 returned second'); |
| 179 |
|
| 154 |
cleanup(); |
180 |
cleanup(); |
| 155 |
}; |
181 |
}; |
| 156 |
|
182 |
|
| 157 |
- |
|
|