Bug 20334: (RM follow-up) Fix test for case insensative filesystems

This patch moved the tests created in Elasticsearch/QueryBuilder.t into
ElasticSearch/QueryBuilder.t and thus removes the case directory name
collision introduced.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Martin Renvoize 2019-10-09 15:03:06 +01:00
parent a013f2bbdd
commit 104436cb74
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
2 changed files with 102 additions and 124 deletions

View File

@ -17,7 +17,7 @@
use Modern::Perl;
use Test::More tests => 2;
use Test::More tests => 5;
use t::lib::Mocks;
use_ok('Koha::SearchEngine::Elasticsearch::QueryBuilder');
@ -123,3 +123,104 @@ subtest 'query_regex_escape_options' => sub {
"Escaped slash outside of quotes has been unescaped while escaped slash within quotes is left as is when unescape escaping is enabled."
);
};
subtest '_truncate_terms() tests' => sub {
plan tests => 7;
my $qb;
ok(
$qb = Koha::SearchEngine::Elasticsearch::QueryBuilder->new({ 'index' => $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX }),
'Creating a new QueryBuilder object'
);
my $res = $qb->_truncate_terms('donald');
is_deeply($res, 'donald*', 'single search term returned correctly');
$res = $qb->_truncate_terms('donald duck');
is_deeply($res, 'donald* duck*', 'two search terms returned correctly');
$res = $qb->_truncate_terms(' donald duck ');
is_deeply($res, 'donald* duck*', 'two search terms surrounded by spaces returned correctly');
$res = $qb->_truncate_terms('"donald duck"');
is_deeply($res, '"donald duck"', 'quoted search term returned correctly');
$res = $qb->_truncate_terms('"donald, duck"');
is_deeply($res, '"donald, duck"', 'quoted search term with comma returned correctly');
$res = $qb->_truncate_terms(' "donald duck" ');
is_deeply($res, '"donald duck"', 'quoted search terms surrounded by spaces correctly');
};
subtest '_split_query() tests' => sub {
plan tests => 7;
my $qb;
ok(
$qb = Koha::SearchEngine::Elasticsearch::QueryBuilder->new({ 'index' => $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX }),
'Creating a new QueryBuilder object'
);
my @res = $qb->_split_query('donald');
my @exp = 'donald';
is_deeply(\@res, \@exp, 'single search term returned correctly');
@res = $qb->_split_query('donald duck');
@exp = ('donald', 'duck');
is_deeply(\@res, \@exp, 'two search terms returned correctly');
@res = $qb->_split_query(' donald duck ');
@exp = ('donald', 'duck');
is_deeply(\@res, \@exp, 'two search terms surrounded by spaces returned correctly');
@res = $qb->_split_query('"donald duck"');
@exp = ( '"donald duck"' );
is_deeply(\@res, \@exp, 'quoted search term returned correctly');
@res = $qb->_split_query('"donald, duck"');
@exp = ( '"donald, duck"' );
is_deeply(\@res, \@exp, 'quoted search term with comma returned correctly');
@res = $qb->_split_query(' "donald duck" ');
@exp = ( '"donald duck"' );
is_deeply(\@res, \@exp, 'quoted search terms surrounded by spaces correctly');
};
subtest '_clean_search_term() tests' => sub {
plan tests => 10;
my $qb;
ok(
$qb = Koha::SearchEngine::Elasticsearch::QueryBuilder->new({ 'index' => $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX }),
'Creating a new QueryBuilder object'
);
my $res = $qb->_clean_search_term('an=123');
is($res, 'koha-auth-number:123', 'equals sign replaced with colon');
$res = $qb->_clean_search_term('"balanced quotes"');
is($res, '"balanced quotes"', 'balanced quotes returned correctly');
$res = $qb->_clean_search_term('unbalanced quotes"');
is($res, 'unbalanced quotes ', 'unbalanced quotes removed');
$res = $qb->_clean_search_term('"unbalanced "quotes"');
is($res, ' unbalanced quotes ', 'unbalanced quotes removed');
$res = $qb->_clean_search_term('test : query');
is($res, 'test query', 'dangling colon removed');
$res = $qb->_clean_search_term('test :: query');
is($res, 'test query', 'dangling double colon removed');
$res = $qb->_clean_search_term('test "another : query"');
is($res, 'test "another : query"', 'quoted dangling colon not removed');
$res = $qb->_clean_search_term('test {another part}');
is($res, 'test "another part"', 'curly brackets replaced correctly');
$res = $qb->_clean_search_term('test {another part');
is($res, 'test another part', 'unbalanced curly brackets replaced correctly');
};
1;

View File

@ -1,123 +0,0 @@
#!/usr/bin/perl
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Test::More tests => 3;
use Koha::SearchEngine::Elasticsearch::QueryBuilder;
subtest '_truncate_terms() tests' => sub {
plan tests => 7;
my $qb;
ok(
$qb = Koha::SearchEngine::Elasticsearch::QueryBuilder->new({ 'index' => $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX }),
'Creating a new QueryBuilder object'
);
my $res = $qb->_truncate_terms('donald');
is_deeply($res, 'donald*', 'single search term returned correctly');
$res = $qb->_truncate_terms('donald duck');
is_deeply($res, 'donald* duck*', 'two search terms returned correctly');
$res = $qb->_truncate_terms(' donald duck ');
is_deeply($res, 'donald* duck*', 'two search terms surrounded by spaces returned correctly');
$res = $qb->_truncate_terms('"donald duck"');
is_deeply($res, '"donald duck"', 'quoted search term returned correctly');
$res = $qb->_truncate_terms('"donald, duck"');
is_deeply($res, '"donald, duck"', 'quoted search term with comma returned correctly');
$res = $qb->_truncate_terms(' "donald duck" ');
is_deeply($res, '"donald duck"', 'quoted search terms surrounded by spaces correctly');
};
subtest '_split_query() tests' => sub {
plan tests => 7;
my $qb;
ok(
$qb = Koha::SearchEngine::Elasticsearch::QueryBuilder->new({ 'index' => $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX }),
'Creating a new QueryBuilder object'
);
my @res = $qb->_split_query('donald');
my @exp = 'donald';
is_deeply(\@res, \@exp, 'single search term returned correctly');
@res = $qb->_split_query('donald duck');
@exp = ('donald', 'duck');
is_deeply(\@res, \@exp, 'two search terms returned correctly');
@res = $qb->_split_query(' donald duck ');
@exp = ('donald', 'duck');
is_deeply(\@res, \@exp, 'two search terms surrounded by spaces returned correctly');
@res = $qb->_split_query('"donald duck"');
@exp = ( '"donald duck"' );
is_deeply(\@res, \@exp, 'quoted search term returned correctly');
@res = $qb->_split_query('"donald, duck"');
@exp = ( '"donald, duck"' );
is_deeply(\@res, \@exp, 'quoted search term with comma returned correctly');
@res = $qb->_split_query(' "donald duck" ');
@exp = ( '"donald duck"' );
is_deeply(\@res, \@exp, 'quoted search terms surrounded by spaces correctly');
};
subtest '_clean_search_term() tests' => sub {
plan tests => 10;
my $qb;
ok(
$qb = Koha::SearchEngine::Elasticsearch::QueryBuilder->new({ 'index' => $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX }),
'Creating a new QueryBuilder object'
);
my $res = $qb->_clean_search_term('an=123');
is($res, 'koha-auth-number:123', 'equals sign replaced with colon');
$res = $qb->_clean_search_term('"balanced quotes"');
is($res, '"balanced quotes"', 'balanced quotes returned correctly');
$res = $qb->_clean_search_term('unbalanced quotes"');
is($res, 'unbalanced quotes ', 'unbalanced quotes removed');
$res = $qb->_clean_search_term('"unbalanced "quotes"');
is($res, ' unbalanced quotes ', 'unbalanced quotes removed');
$res = $qb->_clean_search_term('test : query');
is($res, 'test query', 'dangling colon removed');
$res = $qb->_clean_search_term('test :: query');
is($res, 'test query', 'dangling double colon removed');
$res = $qb->_clean_search_term('test "another : query"');
is($res, 'test "another : query"', 'quoted dangling colon not removed');
$res = $qb->_clean_search_term('test {another part}');
is($res, 'test "another part"', 'curly brackets replaced correctly');
$res = $qb->_clean_search_term('test {another part');
is($res, 'test another part', 'unbalanced curly brackets replaced correctly');
};
1;