3 # This Koha test module is a stub!
4 # Add more tests here!!!
8 use Test
::More tests
=> 18;
9 use List
::Util
qw(first);
16 use_ok
('C4::Languages');
19 my $schema = Koha
::Database
->new->schema;
20 $schema->storage->txn_begin;
21 my $dbh = C4
::Context
->dbh;
23 isnt
(C4
::Languages
::_get_themes
(), undef, 'testing _get_themes doesnt return undef');
25 ok
(C4
::Languages
::_get_language_dirs
(), 'test getting _get_language_dirs');
28 warning_is
{ $result = C4
::Languages
::accept_language
(); }
29 q{accept_language(x,y) called with no clientPreferences (x).},
30 'accept_language() generated expected warning';
31 is
($result,undef, 'test that accept_languages returns undef when nothing is entered');
33 ok
(C4
::Languages
::getAllLanguages
(), 'test get all languages');
35 t
::lib
::Mocks
::mock_preference
('AdvancedSearchLanguages', '');
36 my $all_languages = C4
::Languages
::getAllLanguages
('eng');
37 ok
(@
$all_languages > 10, 'retrieved a bunch of languges');
39 my $languages = C4
::Languages
::getLanguages
('eng');
40 is_deeply
($languages, $all_languages, 'getLanguages() and getAllLanguages() return the same list');
42 $languages = C4
::Languages
::getLanguages
('eng', 1);
43 is_deeply
($languages, $all_languages, 'getLanguages() and getAllLanguages() with filtering selected but AdvancedSearchLanguages blank return the same list');
45 t
::lib
::Mocks
::mock_preference
('AdvancedSearchLanguages', 'ita|eng');
46 $languages = C4
::Languages
::getLanguages
('eng', 1);
47 is
(scalar(@
$languages), 2, 'getLanguages() filtering using AdvancedSearchLanguages works');
49 my $translatedlanguages1;
50 warnings_are
{ $translatedlanguages1 = C4
::Languages
::getTranslatedLanguages
('opac','prog',undef,'') }
52 'no warnings for calling getTranslatedLanguages';
53 my @currentcheck1 = map { $_->{current
} } @
$translatedlanguages1;
54 my $onlyzeros = first
{ $_ != 0 } @currentcheck1;
55 ok
(! $onlyzeros, "Everything was zeros.\n");
57 my $translatedlanguages2;
58 warnings_are
{ $translatedlanguages2 = C4
::Languages
::getTranslatedLanguages
('opac','prog','en','') }
60 'no warnings for calling getTranslatedLanguages';
61 my @currentcheck2 = map { $_->{current
} } @
$translatedlanguages2;
62 $onlyzeros = first
{ $_ != 0 } @currentcheck2;
63 ok
($onlyzeros, "There is a $onlyzeros\n");
65 # Language Descriptions
66 my $sth = $dbh->prepare("SELECT DISTINCT subtag,type,lang,description from language_descriptions;");
68 my $DistinctLangDesc = $sth->fetchall_arrayref({});
70 $sth = $dbh->prepare("SELECT subtag,type,lang,description from language_descriptions;");
72 my $LangDesc = $sth->fetchall_arrayref({});
74 is
(scalar(@
$LangDesc),scalar(@
$DistinctLangDesc),"No unexpected language_description duplicates.");
76 # Language_subtag_registry
77 $sth = $dbh->prepare("SELECT DISTINCT subtag,type,description,added FROM language_subtag_registry;");
79 my $DistinctLangReg = $sth->fetchall_arrayref({});
81 $sth = $dbh->prepare("SELECT subtag,type,description,added FROM language_subtag_registry;");
83 my $LangReg = $sth->fetchall_arrayref({});
85 is
(scalar(@
$LangReg),scalar(@
$DistinctLangReg),"No unexpected language_subtag_registry duplicates.");
87 # Language RFC4646 to ISO639
88 $sth = $dbh->prepare("SELECT DISTINCT rfc4646_subtag,iso639_2_code FROM language_rfc4646_to_iso639;");
90 my $DistinctLangRfc4646 = $sth->fetchall_arrayref({});
92 $sth = $dbh->prepare("SELECT rfc4646_subtag,iso639_2_code FROM language_rfc4646_to_iso639;");
94 my $LangRfc4646 = $sth->fetchall_arrayref({});
96 is
(scalar(@
$LangRfc4646),scalar(@
$DistinctLangRfc4646),"No unexpected language_rfc4646_to_iso639 duplicates.");
99 foreach my $pair (@
$DistinctLangRfc4646){
100 $i++ if $pair->{rfc4646_subtag
} eq C4
::Languages
::get_rfc4646_from_iso639
( $pair->{iso639_2_code
} );
102 is
($i,scalar(@
$DistinctLangRfc4646),"get_rfc4646_from_iso639 returns correct rfc for all iso values.");