|
Lines 1-11
Link Here
|
| 1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
| 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( |
| 186 |
$languages, $expected, |
| 187 |
'getLanguages returned the expected results when no parameters are passed, description is "English (Native)"' |
| 188 |
); |
| 189 |
|
| 190 |
# Test 2: Specific language without full translations |
| 191 |
$expected->[2]->{language_description} = "Español (Español)"; |
| 192 |
$languages = getLanguages('es'); |
| 193 |
cmp_deeply( |
| 194 |
$languages, $expected, |
| 195 |
'getLanguages returned the expected results when "es" is requested, description is "Spanish falling back to English when missing (Native)"' |
| 196 |
); |
| 197 |
|
| 198 |
# Test 3: Specific language with translations |
| 199 |
$expected->[0]->{language_description} = "Anglais (English)"; |
| 200 |
$expected->[1]->{language_description} = "Français (Français)"; |
| 201 |
$expected->[2]->{language_description} = "Espagnol (Español)"; |
| 202 |
$languages = getLanguages('fr'); |
| 203 |
cmp_deeply( |
| 204 |
$languages, $expected, |
| 205 |
'getLanguages returned the expected results when "fr" is requested, description is "French (Native)"' |
| 206 |
); |
| 207 |
|
| 208 |
# Test 4: Filtered results based on AdvancedSearchLanguages |
| 209 |
t::lib::Mocks::mock_preference( 'AdvancedSearchLanguages', 'eng,fra' ); |
| 210 |
$languages = getLanguages( 'en', 1 ); |
| 211 |
is( scalar(@$languages), 2, 'Returned 2 filtered languages' ); |
| 212 |
is_deeply( |
| 213 |
[ map { $_->{iso639_2_code} } @$languages ], |
| 214 |
[ 'eng', 'fra' ], |
| 215 |
'Filtered ISO639-2 codes are correct' |
| 216 |
); |
| 217 |
|
| 218 |
# Cleanup: Restore database to original state |
| 219 |
$dbh->do("DELETE FROM language_descriptions"); |
| 220 |
$dbh->do("DELETE FROM language_subtag_registry"); |
| 221 |
$dbh->do("DELETE FROM language_rfc4646_to_iso639"); |
| 222 |
|
| 223 |
$schema->storage->txn_rollback; |
| 224 |
}; |