Lines 17-28
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 2; |
20 |
use Test::More tests => 3; |
21 |
use Test::MockModule; |
21 |
use Test::MockModule; |
22 |
use t::lib::Mocks; |
22 |
use t::lib::Mocks; |
23 |
|
23 |
|
|
|
24 |
use utf8; |
25 |
|
24 |
use_ok('Koha::SearchEngine::Elasticsearch::Search'); |
26 |
use_ok('Koha::SearchEngine::Elasticsearch::Search'); |
25 |
|
27 |
|
|
|
28 |
subtest '_sort_facets' => sub { |
29 |
plan tests => 2; |
30 |
t::lib::Mocks::mock_preference( 'SearchEngine', 'Elasticsearch' ); |
31 |
my $facets = [ |
32 |
{ facet_label_value => 'Mary' }, |
33 |
{ facet_label_value => 'Harry' }, |
34 |
{ facet_label_value => 'Fairy' }, |
35 |
{ facet_label_value => 'Ari' }, |
36 |
{ facet_label_value => 'mary' }, |
37 |
{ facet_label_value => 'harry' }, |
38 |
{ facet_label_value => 'fairy' }, |
39 |
{ facet_label_value => 'ari' }, |
40 |
{ facet_label_value => 'étienne' }, |
41 |
{ facet_label_value => 'Åuthor' }, |
42 |
]; |
43 |
|
44 |
my @normal_sort_facets = sort { $a->{facet_label_value} cmp $b->{facet_label_value} } @$facets; |
45 |
my @normal_expected_facets = ( |
46 |
{ facet_label_value => 'Ari' }, |
47 |
{ facet_label_value => 'Fairy' }, |
48 |
{ facet_label_value => 'Harry' }, |
49 |
{ facet_label_value => 'Mary' }, |
50 |
{ facet_label_value => 'ari' }, |
51 |
{ facet_label_value => 'fairy' }, |
52 |
{ facet_label_value => 'harry' }, |
53 |
{ facet_label_value => 'mary' }, |
54 |
{ facet_label_value => 'Åuthor' }, |
55 |
{ facet_label_value => 'étienne' }, |
56 |
); |
57 |
|
58 |
#NOTE: stringwise/bytewise is not UTF-8 friendly |
59 |
is_deeply( \@normal_sort_facets, \@normal_expected_facets, "Perl's built-in sort is stringwise/bytewise." ); |
60 |
|
61 |
my $search = Koha::SearchEngine::Elasticsearch::Search->new( |
62 |
{ index => $Koha::SearchEngine::Elasticsearch::AUTHORITIES_INDEX } ); |
63 |
|
64 |
#NOTE: The 'default' locale uses the Default Unicode Collation Element Table, which |
65 |
#is used for the locales of English (en) and French (fr). |
66 |
my $sorted_facets = $search->_sort_facets( { facets => $facets, locale => 'default' } ); |
67 |
my $expected = [ |
68 |
{ facet_label_value => 'ari' }, |
69 |
{ facet_label_value => 'Ari' }, |
70 |
{ facet_label_value => 'Åuthor' }, |
71 |
{ facet_label_value => 'étienne' }, |
72 |
{ facet_label_value => 'fairy' }, |
73 |
{ facet_label_value => 'Fairy' }, |
74 |
{ facet_label_value => 'harry' }, |
75 |
{ facet_label_value => 'Harry' }, |
76 |
{ facet_label_value => 'mary' }, |
77 |
{ facet_label_value => 'Mary' }, |
78 |
]; |
79 |
is_deeply( $sorted_facets, $expected, "Facets sorted correctly with default locale" ); |
80 |
|
81 |
#NOTE: If "locale" is not provided to _sort_facets, it will look up the LC_COLLATE |
82 |
#for the local system. This is what allows this function to work well in production. |
83 |
#However, since LC_COLLATE could vary from system to system running these unit tests, |
84 |
#we can't test arbitrary locales here. |
85 |
|
86 |
#TODO: It would be great to explicitly use a fi_FI locale for another test, but we cannot guarantee |
87 |
#that every system has that locale. That said, perhaps we could do some conditional unit |
88 |
#testing if certain locales are available when running tests. This could allow for the Koha community |
89 |
#to thoroughly test this functionality, while letting anyone run the unit tests regardless of their |
90 |
#installed locales. |
91 |
}; |
92 |
|
26 |
subtest 'search_auth_compat' => sub { |
93 |
subtest 'search_auth_compat' => sub { |
27 |
plan tests => 4; |
94 |
plan tests => 4; |
28 |
|
95 |
|
29 |
- |
|
|