Bug 16976 - Unit tests
authorNick Clemens <nick@bywatersolutions.com>
Fri, 7 Jul 2017 17:55:50 +0000 (17:55 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 15 Aug 2017 15:17:40 +0000 (12:17 -0300)
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
t/Search/Zebra/QueryBuilder.t [new file with mode: 0644]

diff --git a/t/Search/Zebra/QueryBuilder.t b/t/Search/Zebra/QueryBuilder.t
new file mode 100644 (file)
index 0000000..f0608ec
--- /dev/null
@@ -0,0 +1,38 @@
+#!/usr/bin/env perl
+
+use Modern::Perl;
+
+use Test::More tests => 2;
+use_ok('Koha::SearchEngine::Zebra::QueryBuilder');
+
+subtest 'build_authorities_query' => sub {
+    plan tests => 2;
+
+    my @test_search = (
+        ['mainmainentry'], ['and'], [''], ['contains'], ['any'], '',
+        'HeadingAsc'
+    );
+    my $expected_result = {
+        marclist     => ['mainmainentry'],
+        and_or       => ['and'],
+        excluding    => [''],
+        operator     => ['contains'],
+        value        => ['any'],
+        authtypecode => '',
+        orderby      => 'HeadingAsc',
+    };
+    my $built_search =
+      Koha::SearchEngine::Zebra::QueryBuilder->build_authorities_query( @test_search );
+    is_deeply(
+        $built_search, $expected_result,
+        "We are simply hashifying our array of refs/values, should otherwise not be altered"
+    );
+    $expected_result->{value} = ['"any"'];
+    $test_search[4] = ['"any"'];
+    $built_search =
+      Koha::SearchEngine::Zebra::QueryBuilder->build_authorities_query( @test_search );
+    is_deeply(
+        $built_search, $expected_result,
+        "The same should hold true if the search contains double quotes which will be escaped during searching by search_auth_compat subroutine"
+    );
+};