From 104436cb74483cfef710fcda4b221d018311a6cd Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 9 Oct 2019 15:03:06 +0100 Subject: [PATCH] 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 --- t/Koha/SearchEngine/ElasticSearch/QueryBuilder.t | 103 ++++++++++++++++++- t/Koha/SearchEngine/Elasticsearch/QueryBuilder.t | 123 ----------------------- 2 files changed, 102 insertions(+), 124 deletions(-) delete mode 100644 t/Koha/SearchEngine/Elasticsearch/QueryBuilder.t diff --git a/t/Koha/SearchEngine/ElasticSearch/QueryBuilder.t b/t/Koha/SearchEngine/ElasticSearch/QueryBuilder.t index 73b3bde3ef..3bd5e4244a 100644 --- a/t/Koha/SearchEngine/ElasticSearch/QueryBuilder.t +++ b/t/Koha/SearchEngine/ElasticSearch/QueryBuilder.t @@ -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; diff --git a/t/Koha/SearchEngine/Elasticsearch/QueryBuilder.t b/t/Koha/SearchEngine/Elasticsearch/QueryBuilder.t deleted file mode 100644 index fae80c367d..0000000000 --- a/t/Koha/SearchEngine/Elasticsearch/QueryBuilder.t +++ /dev/null @@ -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 . - -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; -- 2.11.4.GIT