Lines 24-64
use t::lib::Mocks;
Link Here
|
24 |
use_ok('Koha::SearchEngine::Elasticsearch::Search'); |
24 |
use_ok('Koha::SearchEngine::Elasticsearch::Search'); |
25 |
|
25 |
|
26 |
subtest 'search_auth_compat' => sub { |
26 |
subtest 'search_auth_compat' => sub { |
27 |
plan tests => 2; |
27 |
plan tests => 4; |
28 |
|
28 |
|
29 |
t::lib::Mocks::mock_preference('QueryRegexEscapeOptions', 'dont_escape'); |
29 |
t::lib::Mocks::mock_preference( 'QueryRegexEscapeOptions', 'dont_escape' ); |
30 |
|
30 |
|
31 |
my $module = Test::MockModule->new('Koha::SearchEngine::Elasticsearch::Search'); |
|
|
32 |
$module->mock('count_auth_use', sub { return 1 }); |
33 |
$module->mock('search', sub { |
34 |
# While the 001 and the authid should be the same, it is not always the case |
35 |
# The _id is always the authid and so should be our source of trutch |
36 |
my $marc_record = MARC::Record->new(); |
37 |
$marc_record->append_fields( |
38 |
MARC::Field->new('001', 'Wrong001Number'), |
39 |
); |
40 |
return { |
41 |
hits => { |
42 |
hits => [{ |
43 |
'_id' => 8675309, |
44 |
'_source' => { |
45 |
'local-number' => ['Wrong001Number'], |
46 |
'marc_data' => $marc_record, |
47 |
'marc_format' => 'base64ISO2709', |
48 |
}, |
49 |
}] |
50 |
} |
51 |
}; |
52 |
}); |
53 |
my $search; |
31 |
my $search; |
54 |
ok( |
32 |
ok( |
55 |
$search = Koha::SearchEngine::Elasticsearch::Search->new({ 'index' => $Koha::SearchEngine::Elasticsearch::AUTHORITIES_INDEX }), |
33 |
$search = Koha::SearchEngine::Elasticsearch::Search->new( |
|
|
34 |
{ index => $Koha::SearchEngine::Elasticsearch::AUTHORITIES_INDEX } |
35 |
), |
56 |
'Creating a new Search object' |
36 |
'Creating a new Search object' |
57 |
); |
37 |
); |
58 |
|
38 |
|
|
|
39 |
my $builder; |
40 |
ok( |
41 |
$builder = |
42 |
Koha::SearchEngine::QueryBuilder->new( { index => $Koha::SearchEngine::Elasticsearch::AUTHORITIES_INDEX } ), |
43 |
'Creating a new Builder object' |
44 |
); |
45 |
|
46 |
my $search_query = $builder->build_authorities_query_compat( |
47 |
['mainmainentry'], ['and'], [''], ['contains'], |
48 |
['Donald - Duck'], '', 'HeadingAsc' |
49 |
); |
50 |
|
51 |
my ( $bad_results, undef ) = $search->search_auth_compat( $search_query, 0, 20, undef ); |
52 |
|
53 |
is( @$bad_results[0], undef, 'We expect no record because it doesnt exist' ); |
54 |
|
55 |
my $module = Test::MockModule->new('Koha::SearchEngine::Elasticsearch::Search'); |
56 |
$module->mock( 'count_auth_use', sub { return 1 } ); |
57 |
$module->mock( |
58 |
'search', |
59 |
sub { |
60 |
# While the 001 and the authid should be the same, it is not always the case |
61 |
# The _id is always the authid and so should be our source of trutch |
62 |
my $marc_record = MARC::Record->new(); |
63 |
$marc_record->append_fields( |
64 |
MARC::Field->new( '001', 'Wrong001Number' ), |
65 |
); |
66 |
return { |
67 |
hits => { |
68 |
hits => [ |
69 |
{ |
70 |
'_id' => 8675309, |
71 |
'_source' => { |
72 |
'local-number' => ['Wrong001Number'], |
73 |
'marc_data' => $marc_record, |
74 |
'marc_format' => 'base64ISO2709', |
75 |
}, |
76 |
} |
77 |
] |
78 |
} |
79 |
}; |
80 |
} |
81 |
); |
82 |
|
59 |
my ( $results, undef ) = $search->search_auth_compat('faked'); |
83 |
my ( $results, undef ) = $search->search_auth_compat('faked'); |
60 |
|
84 |
|
61 |
is( @$results[0]->{authid}, '8675309', 'We get the expected record _id and not the 001'); |
85 |
is( @$results[0]->{authid}, '8675309', 'We get the expected record _id and not the 001' ); |
62 |
|
86 |
|
63 |
}; |
87 |
}; |
64 |
|
88 |
|
65 |
- |
|
|