Bug 15839: Koha::Reviews - Remove approvereview & unapprovereview
[koha.git] / t / db_dependent / Languages.t
1 #!/usr/bin/perl
2 #
3 # This Koha test module is a stub!  
4 # Add more tests here!!!
5
6 use strict;
7 use warnings;
8
9 use Test::More tests => 17;
10 use List::Util qw(first);
11 use Data::Dumper;
12 use Test::Warn;
13 use t::lib::Mocks;
14
15 BEGIN {
16     use_ok('C4::Languages');
17 }
18
19 my $dbh = C4::Context->dbh;
20 $dbh->{AutoCommit} = 0;
21 $dbh->{RaiseError} = 1;
22
23 isnt(C4::Languages::_get_themes(), undef, 'testing _get_themes doesnt return undef');
24
25 ok(C4::Languages::_get_language_dirs(), 'test getting _get_language_dirs');
26
27 my $result;
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');
32
33 ok(C4::Languages::getAllLanguages(), 'test get all languages');
34
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');
38
39 my $languages = C4::Languages::getLanguages('eng');
40 is_deeply($languages, $all_languages, 'getLanguages() and getAllLanguages() return the same list');
41
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');
44
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');
48
49 my $translatedlanguages1;
50 warnings_are { $translatedlanguages1 = C4::Languages::getTranslatedLanguages('opac','prog',undef,'') }
51              [],
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");
56
57 my $translatedlanguages2;
58 warnings_are { $translatedlanguages2 = C4::Languages::getTranslatedLanguages('opac','prog','en','') }
59              [],
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");
64
65 # Language Descriptions
66 my $sth = $dbh->prepare("SELECT DISTINCT subtag,type,lang,description from language_descriptions;");
67 $sth->execute();
68 my $DistinctLangDesc = $sth->fetchall_arrayref({});
69
70 $sth = $dbh->prepare("SELECT subtag,type,lang,description from language_descriptions;");
71 $sth->execute();
72 my $LangDesc = $sth->fetchall_arrayref({});
73
74 is(scalar(@$LangDesc),scalar(@$DistinctLangDesc),"No unexpected language_description duplicates.");
75
76 # Language_subtag_registry
77 $sth = $dbh->prepare("SELECT DISTINCT subtag,type,description,added FROM language_subtag_registry;");
78 $sth->execute();
79 my $DistinctLangReg = $sth->fetchall_arrayref({});
80
81 $sth = $dbh->prepare("SELECT subtag,type,description,added FROM language_subtag_registry;");
82 $sth->execute();
83 my $LangReg = $sth->fetchall_arrayref({});
84
85 is(scalar(@$LangReg),scalar(@$DistinctLangReg),"No unexpected language_subtag_registry duplicates.");
86
87 # Language RFC4646 to ISO639
88 $sth = $dbh->prepare("SELECT DISTINCT rfc4646_subtag,iso639_2_code FROM language_rfc4646_to_iso639;");
89 $sth->execute();
90 my $DistinctLangRfc4646 = $sth->fetchall_arrayref({});
91
92 $sth = $dbh->prepare("SELECT rfc4646_subtag,iso639_2_code FROM language_rfc4646_to_iso639;");
93 $sth->execute();
94 my $LangRfc4646 = $sth->fetchall_arrayref({});
95
96 is(scalar(@$LangRfc4646),scalar(@$DistinctLangRfc4646),"No unexpected language_rfc4646_to_iso639 duplicates.");
97
98 $dbh->rollback;