Lines 2-11
Link Here
|
2 |
# |
2 |
# |
3 |
# This Koha test module is a stub! |
3 |
# This Koha test module is a stub! |
4 |
# Add more tests here!!! |
4 |
# Add more tests here!!! |
5 |
|
5 |
use utf8; |
6 |
use Modern::Perl; |
6 |
use Modern::Perl; |
7 |
|
7 |
|
8 |
use Test::More tests => 21; |
8 |
use Encode; |
|
|
9 |
use Test::More tests => 22; |
10 |
use Test::Deep; |
11 |
use Test::Exception; |
9 |
use List::Util qw(first); |
12 |
use List::Util qw(first); |
10 |
use Data::Dumper; |
13 |
use Data::Dumper; |
11 |
use Test::Warn; |
14 |
use Test::Warn; |
Lines 110-112
foreach my $pair (@$DistinctLangRfc4646){
Link Here
|
110 |
$i++ if $pair->{rfc4646_subtag} eq C4::Languages::get_rfc4646_from_iso639( $pair->{iso639_2_code} ); |
113 |
$i++ if $pair->{rfc4646_subtag} eq C4::Languages::get_rfc4646_from_iso639( $pair->{iso639_2_code} ); |
111 |
} |
114 |
} |
112 |
is($i,scalar(@$DistinctLangRfc4646),"get_rfc4646_from_iso639 returns correct rfc for all iso values."); |
115 |
is($i,scalar(@$DistinctLangRfc4646),"get_rfc4646_from_iso639 returns correct rfc for all iso values."); |
113 |
- |
116 |
|
|
|
117 |
$schema->storage->txn_rollback; |
118 |
subtest 'getLanguages()' => sub { |
119 |
|
120 |
$schema->storage->txn_begin; |
121 |
|
122 |
# Setup: Ensure test environment is clean |
123 |
$dbh->do("DELETE FROM language_descriptions"); |
124 |
$dbh->do("DELETE FROM language_subtag_registry"); |
125 |
$dbh->do("DELETE FROM language_rfc4646_to_iso639"); |
126 |
|
127 |
# Insert test data |
128 |
$dbh->do( |
129 |
"INSERT INTO language_subtag_registry (subtag, type, description) VALUES |
130 |
('en', 'language', 'English'), |
131 |
('fr', 'language', 'French'), |
132 |
('es', 'language', 'Spanish')" |
133 |
); |
134 |
|
135 |
$dbh->do( |
136 |
"INSERT INTO language_descriptions (lang, subtag, type, description) VALUES |
137 |
('en', 'en', 'language', 'English'), |
138 |
('en', 'fr', 'language', 'French'), |
139 |
('en', 'es', 'language', 'Spanish'), |
140 |
('es', 'es', 'language', 'Español'), |
141 |
('fr', 'fr', 'language', 'Français'), |
142 |
('fr', 'es', 'language', 'Espagnol'), |
143 |
('fr', 'en', 'language', 'Anglais')" |
144 |
); |
145 |
|
146 |
$dbh->do( |
147 |
"INSERT INTO language_rfc4646_to_iso639 (rfc4646_subtag, iso639_2_code) VALUES |
148 |
('en', 'eng'), |
149 |
('fr', 'fra'), |
150 |
('es', 'spa')" |
151 |
); |
152 |
|
153 |
my $expected = [ |
154 |
{ |
155 |
'id' => ignore(), |
156 |
'added' => ignore(), |
157 |
'subtag' => 'en', |
158 |
'iso639_2_code' => 'eng', |
159 |
'description' => 'English', |
160 |
'language_description' => 'English (English)', |
161 |
'type' => 'language' |
162 |
}, |
163 |
{ |
164 |
'id' => ignore(), |
165 |
'added' => ignore(), |
166 |
'subtag' => 'fr', |
167 |
'iso639_2_code' => 'fra', |
168 |
'description' => 'French', |
169 |
'language_description' => "French (Français)", |
170 |
'type' => 'language' |
171 |
}, |
172 |
{ |
173 |
'id' => ignore(), |
174 |
'added' => ignore(), |
175 |
'subtag' => 'es', |
176 |
'iso639_2_code' => 'spa', |
177 |
'description' => 'Spanish', |
178 |
'language_description' => "Spanish (Español)", |
179 |
'type' => 'language' |
180 |
} |
181 |
]; |
182 |
|
183 |
# Test 1: No parameters, expect English names |
184 |
my $languages = getLanguages(); |
185 |
cmp_deeply( $languages, $expected, 'getLanguages returned the expected results when no parameters are passed, description is "English (Native)"' ); |
186 |
|
187 |
# Test 2: Specific language without full translations |
188 |
$expected->[2]->{language_description} = "Español (Español)"; |
189 |
$languages = getLanguages('es'); |
190 |
cmp_deeply( $languages, $expected, 'getLanguages returned the expected results when "es" is requested, description is "Spanish falling back to English when missing (Native)"' ); |
191 |
|
192 |
|
193 |
# Test 3: Specific language with translations |
194 |
$expected->[0]->{language_description} = "Anglais (English)"; |
195 |
$expected->[1]->{language_description} = "Français (Français)"; |
196 |
$expected->[2]->{language_description} = "Espagnol (Español)"; |
197 |
$languages = getLanguages('fr'); |
198 |
cmp_deeply( $languages, $expected, 'getLanguages returned the expected results when "fr" is requested, description is "French (Native)"'); |
199 |
|
200 |
# Test 4: Filtered results based on AdvancedSearchLanguages |
201 |
t::lib::Mocks::mock_preference('AdvancedSearchLanguages', 'eng,fra'); |
202 |
$languages = getLanguages( 'en', 1 ); |
203 |
is( scalar(@$languages), 2, 'Returned 2 filtered languages' ); |
204 |
is_deeply( |
205 |
[ map { $_->{iso639_2_code} } @$languages ], |
206 |
[ 'eng', 'fra' ], |
207 |
'Filtered ISO639-2 codes are correct' |
208 |
); |
209 |
|
210 |
# Cleanup: Restore database to original state |
211 |
$dbh->do("DELETE FROM language_descriptions"); |
212 |
$dbh->do("DELETE FROM language_subtag_registry"); |
213 |
$dbh->do("DELETE FROM language_rfc4646_to_iso639"); |
214 |
|
215 |
$schema->storage->txn_rollback; |
216 |
}; |