Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# This file is part of Koha. |
4 |
# |
5 |
# Koha is free software; you can redistribute it and/or modify it |
6 |
# under the terms of the GNU General Public License as published by |
7 |
# the Free Software Foundation; either version 3 of the License, or |
8 |
# (at your option) any later version. |
9 |
# |
10 |
# Koha is distributed in the hope that it will be useful, but |
11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
# GNU General Public License for more details. |
14 |
# |
15 |
# You should have received a copy of the GNU General Public License |
16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
17 |
|
18 |
use Modern::Perl; |
19 |
|
20 |
use Test::More tests => 1; |
21 |
use Test::MockModule; |
22 |
use t::lib::Mocks; |
23 |
use C4::Search; |
24 |
|
25 |
use utf8; |
26 |
|
27 |
subtest '_sort_facets_zebra with system preference' => sub { |
28 |
plan tests => 3; |
29 |
|
30 |
my $facets = [ |
31 |
{ facet_label_value => 'Mary' }, |
32 |
{ facet_label_value => 'Harry' }, |
33 |
{ facet_label_value => 'Fairy' }, |
34 |
{ facet_label_value => 'Ari' }, |
35 |
{ facet_label_value => 'mary' }, |
36 |
{ facet_label_value => 'harry' }, |
37 |
{ facet_label_value => 'fairy' }, |
38 |
{ facet_label_value => 'ari' }, |
39 |
{ facet_label_value => 'étienne' }, |
40 |
{ facet_label_value => 'Åuthor' }, |
41 |
]; |
42 |
|
43 |
# Test with explicit locale parameter |
44 |
my $sorted_facets_explicit = C4::Search::_sort_facets_zebra( $facets, 'default' ); |
45 |
my $expected = [ |
46 |
{ facet_label_value => 'ari' }, |
47 |
{ facet_label_value => 'Ari' }, |
48 |
{ facet_label_value => 'Åuthor' }, |
49 |
{ facet_label_value => 'étienne' }, |
50 |
{ facet_label_value => 'fairy' }, |
51 |
{ facet_label_value => 'Fairy' }, |
52 |
{ facet_label_value => 'harry' }, |
53 |
{ facet_label_value => 'Harry' }, |
54 |
{ facet_label_value => 'mary' }, |
55 |
{ facet_label_value => 'Mary' }, |
56 |
]; |
57 |
is_deeply( $sorted_facets_explicit, $expected, "Zebra facets sorted correctly with explicit locale" ); |
58 |
|
59 |
# Test with system preference |
60 |
t::lib::Mocks::mock_preference( 'FacetSortingLocale', 'default' ); |
61 |
my $sorted_facets_syspref = C4::Search::_sort_facets_zebra($facets); |
62 |
is_deeply( $sorted_facets_syspref, $expected, "Zebra facets sorted correctly with system preference" ); |
63 |
|
64 |
# Test fallback behavior |
65 |
t::lib::Mocks::mock_preference( 'FacetSortingLocale', '' ); |
66 |
my $sorted_facets_fallback = C4::Search::_sort_facets_zebra($facets); |
67 |
is( ref($sorted_facets_fallback), 'ARRAY', "Zebra facets sorting fallback works" ); |
68 |
}; |