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