Bug 31023: Unit tests
authorNick Clemens <nick@bywatersolutions.com>
Tue, 12 Jul 2022 13:46:27 +0000 (13:46 +0000)
committerArthur Suzuki <arthur.suzuki@biblibre.com>
Mon, 14 Nov 2022 13:34:44 +0000 (14:34 +0100)
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit df184560a5de428ed6eaaff437cb5dd450f45726)
(cherry picked from commit 4b9106d995ef0f686a941cf914906eae45e5328e)
Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com>
t/AuthoritiesMarc_MARC21.t

index 5c5c837..4ed2e1d 100755 (executable)
@@ -6,9 +6,14 @@
 use strict;
 use warnings;
 
-use Test::More tests => 4;
+use Test::MockModule;
+use Test::MockObject;
+use Test::More tests => 5;
+use t::lib::Mocks;
 use MARC::Record;
 
+use C4::AuthoritiesMarc qw( FindDuplicateAuthority );
+
 BEGIN {
         use_ok('C4::AuthoritiesMarc::MARC21', qw( default_auth_type_location fix_marc21_auth_type_location ));
 }
@@ -19,3 +24,39 @@ ok($result[1] eq 'a', "testing default_auth_type_location has first value 'a'");
 
 my $marc_record = MARC::Record->new();
 is(C4::AuthoritiesMarc::MARC21::fix_marc21_auth_type_location($marc_record, '', ''), undef, "testing fix_marc21_auth_type_location returns undef with empty MARC record");
+
+subtest "FindDuplicateAuthority tests" => sub {
+    plan tests => 2;
+    my $zebra_search_module = Test::MockModule->new( 'C4::Search' );
+    $zebra_search_module->mock( 'SimpleSearch', sub {
+        my $query = shift;
+        return ( undef, [$query] );
+    });
+    $zebra_search_module->mock( 'new_record_from_zebra', sub {
+        my (undef, $query ) = @_;
+        my $marc = MARC::Record->new;
+        $marc->append_fields(
+            MARC::Field->new( '001', $query ),
+        );
+        return $marc;
+    });
+    my $es_search_module = Test::MockModule->new( 'Koha::SearchEngine::Elasticsearch::Search' );
+    $es_search_module->mock( 'simple_search_compat', sub {
+        my (undef, $query) = @_;
+        return ( undef, [$query] );
+    });
+
+    my $record = MARC::Record->new;
+    $record->append_fields(
+        MARC::Field->new('155', '', '', a => 'Potato' ),
+    );
+
+    t::lib::Mocks::mock_preference( 'SearchEngine', 'Zebra' );
+    my ($query) = FindDuplicateAuthority( $record, "GENRE/FORM" );
+    is( $query, q{at:"GENRE/FORM"  AND he:"Potato"}, "Query formed correctly for Zebra");
+
+    t::lib::Mocks::mock_preference( 'SearchEngine', 'Elasticsearch' );
+    ($query) = FindDuplicateAuthority( $record, "GENRE/FORM" );
+    is( $query, q{at:"GENRE/FORM"  AND he:"Potato"}, "Query formed correctly for Elasticsearch");
+
+};