3 # This Koha test module is a stub!
4 # Add more tests here!!!
9 use Test
::More tests
=> 16;
10 use List
::Util
qw(first);
16 use_ok
('C4::Languages');
19 my $dbh = C4
::Context
->dbh;
20 $dbh->{AutoCommit
} = 0;
21 $dbh->{RaiseError
} = 1;
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');
27 is
(C4
::Languages
::accept_language
(),undef, 'test that accept_languages returns undef when nothing is entered');
29 ok
(C4
::Languages
::getAllLanguages
(), 'test get all languages');
31 t
::lib
::Mocks
::mock_preference
('AdvancedSearchLanguages', '');
32 my $all_languages = C4
::Languages
::getAllLanguages
('eng');
33 ok
(@
$all_languages > 10, 'retrieved a bunch of languges');
35 my $languages = C4
::Languages
::getLanguages
('eng');
36 is_deeply
($languages, $all_languages, 'getLanguages() and getAllLanguages() return the same list');
38 $languages = C4
::Languages
::getLanguages
('eng', 1);
39 is_deeply
($languages, $all_languages, 'getLanguages() and getAllLanguages() with filtering selected but AdvancedSearchLanguages blank return the same list');
41 t
::lib
::Mocks
::mock_preference
('AdvancedSearchLanguages', 'ita|eng');
42 $languages = C4
::Languages
::getLanguages
('eng', 1);
43 is
(scalar(@
$languages), 2, 'getLanguages() filtering using AdvancedSearchLanguages works');
45 my $translatedlanguages1;
46 warnings_are
{ $translatedlanguages1 = C4
::Languages
::getTranslatedLanguages
('opac','prog',undef,'') }
48 'no warnings for calling getTranslatedLanguages';
49 my @currentcheck1 = map { $_->{current
} } @
$translatedlanguages1;
50 my $onlyzeros = first
{ $_ != 0 } @currentcheck1;
51 ok
(! $onlyzeros, "Everything was zeros.\n");
53 my $translatedlanguages2;
54 warnings_are
{ $translatedlanguages2 = C4
::Languages
::getTranslatedLanguages
('opac','prog','en','') }
56 'no warnings for calling getTranslatedLanguages';
57 my @currentcheck2 = map { $_->{current
} } @
$translatedlanguages2;
58 $onlyzeros = first
{ $_ != 0 } @currentcheck2;
59 ok
($onlyzeros, "There is a $onlyzeros\n");
61 # Language Descriptions
62 my $sth = $dbh->prepare("SELECT DISTINCT subtag,type,lang,description from language_descriptions;");
64 my $DistinctLangDesc = $sth->fetchall_arrayref({});
66 $sth = $dbh->prepare("SELECT subtag,type,lang,description from language_descriptions;");
68 my $LangDesc = $sth->fetchall_arrayref({});
70 is
(scalar(@
$LangDesc),scalar(@
$DistinctLangDesc),"No unexpected language_description duplicates.");
72 # Language_subtag_registry
73 $sth = $dbh->prepare("SELECT DISTINCT subtag,type,description,added FROM language_subtag_registry;");
75 my $DistinctLangReg = $sth->fetchall_arrayref({});
77 $sth = $dbh->prepare("SELECT subtag,type,description,added FROM language_subtag_registry;");
79 my $LangReg = $sth->fetchall_arrayref({});
81 is
(scalar(@
$LangReg),scalar(@
$DistinctLangReg),"No unexpected language_subtag_registry duplicates.");
83 # Language RFC4646 to ISO639
84 $sth = $dbh->prepare("SELECT DISTINCT rfc4646_subtag,iso639_2_code FROM language_rfc4646_to_iso639;");
86 my $DistinctLangRfc4646 = $sth->fetchall_arrayref({});
88 $sth = $dbh->prepare("SELECT rfc4646_subtag,iso639_2_code FROM language_rfc4646_to_iso639;");
90 my $LangRfc4646 = $sth->fetchall_arrayref({});
92 is
(scalar(@
$LangRfc4646),scalar(@
$DistinctLangRfc4646),"No unexpected language_rfc4646_to_iso639 duplicates.");