3 # This Koha test module is a stub!
4 # Add more tests here!!!
11 use Test::More tests => 5;
15 use C4::AuthoritiesMarc qw( FindDuplicateAuthority );
18 use_ok('C4::AuthoritiesMarc::MARC21', qw( default_auth_type_location fix_marc21_auth_type_location ));
21 my @result = C4::AuthoritiesMarc::MARC21::default_auth_type_location();
22 ok($result[0] eq '942', "testing default_auth_type_location has first value '942'");
23 ok($result[1] eq 'a', "testing default_auth_type_location has first value 'a'");
25 my $marc_record = MARC::Record->new();
26 is(C4::AuthoritiesMarc::MARC21::fix_marc21_auth_type_location($marc_record, '', ''), undef, "testing fix_marc21_auth_type_location returns undef with empty MARC record");
28 subtest "FindDuplicateAuthority tests" => sub {
30 my $zebra_search_module = Test::MockModule->new( 'C4::Search' );
31 $zebra_search_module->mock( 'SimpleSearch', sub {
33 return ( undef, [$query] );
35 $zebra_search_module->mock( 'new_record_from_zebra', sub {
36 my (undef, $query ) = @_;
37 my $marc = MARC::Record->new;
39 MARC::Field->new( '001', $query ),
43 my $es_search_module = Test::MockModule->new( 'Koha::SearchEngine::Elasticsearch::Search' );
44 $es_search_module->mock( 'simple_search_compat', sub {
45 my (undef, $query) = @_;
46 return ( undef, [$query] );
49 my $record = MARC::Record->new;
50 $record->append_fields(
51 MARC::Field->new('155', '', '', a => 'Potato' ),
54 t::lib::Mocks::mock_preference( 'SearchEngine', 'Zebra' );
55 my ($query) = FindDuplicateAuthority( $record, "GENRE/FORM" );
56 is( $query, q{at:"GENRE/FORM" AND he:"Potato"}, "Query formed correctly for Zebra");
58 t::lib::Mocks::mock_preference( 'SearchEngine', 'Elasticsearch' );
59 ($query) = FindDuplicateAuthority( $record, "GENRE/FORM" );
60 is( $query, q{at:"GENRE/FORM" AND he:"Potato"}, "Query formed correctly for Elasticsearch");