Bug 9259: Use is instead of is_deeply
[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 => 16;
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 is(C4::Languages::accept_language(),undef, 'test that accept_languages returns undef when nothing is entered');
28
29 ok(C4::Languages::getAllLanguages(), 'test get all languages');
30
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');
34
35 my $languages = C4::Languages::getLanguages('eng');
36 is_deeply($languages, $all_languages, 'getLanguages() and getAllLanguages() return the same list');
37
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');
40
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');
44
45 my $translatedlanguages1;
46 warnings_are { $translatedlanguages1 = C4::Languages::getTranslatedLanguages('opac','prog',undef,'') }
47              [],
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");
52
53 my $translatedlanguages2;
54 warnings_are { $translatedlanguages2 = C4::Languages::getTranslatedLanguages('opac','prog','en','') }
55              [],
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");
60
61 # Language Descriptions
62 my $sth = $dbh->prepare("SELECT DISTINCT subtag,type,lang,description from language_descriptions;");
63 $sth->execute();
64 my $DistinctLangDesc = $sth->fetchall_arrayref({});
65
66 $sth = $dbh->prepare("SELECT subtag,type,lang,description from language_descriptions;");
67 $sth->execute();
68 my $LangDesc = $sth->fetchall_arrayref({});
69
70 is(scalar(@$LangDesc),scalar(@$DistinctLangDesc),"No unexpected language_description duplicates.");
71
72 # Language_subtag_registry
73 $sth = $dbh->prepare("SELECT DISTINCT subtag,type,description,added FROM language_subtag_registry;");
74 $sth->execute();
75 my $DistinctLangReg = $sth->fetchall_arrayref({});
76
77 $sth = $dbh->prepare("SELECT subtag,type,description,added FROM language_subtag_registry;");
78 $sth->execute();
79 my $LangReg = $sth->fetchall_arrayref({});
80
81 is(scalar(@$LangReg),scalar(@$DistinctLangReg),"No unexpected language_subtag_registry duplicates.");
82
83 # Language RFC4646 to ISO639
84 $sth = $dbh->prepare("SELECT DISTINCT rfc4646_subtag,iso639_2_code FROM language_rfc4646_to_iso639;");
85 $sth->execute();
86 my $DistinctLangRfc4646 = $sth->fetchall_arrayref({});
87
88 $sth = $dbh->prepare("SELECT rfc4646_subtag,iso639_2_code FROM language_rfc4646_to_iso639;");
89 $sth->execute();
90 my $LangRfc4646 = $sth->fetchall_arrayref({});
91
92 is(scalar(@$LangRfc4646),scalar(@$DistinctLangRfc4646),"No unexpected language_rfc4646_to_iso639 duplicates.");
93
94 $dbh->rollback;