View | Details | Raw Unified | Return to bug 29245
Collapse All | Expand All

(-)a/t/db_dependent/Languages.t (-67 / +95 lines)
Lines 1-14 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
3
# Copyright 2021 Koha Development team
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
2
#
11
#
3
# This Koha test module is a stub!  
12
# Koha is distributed in the hope that it will be useful, but
4
# Add more tests here!!!
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
5
19
6
use Modern::Perl;
20
use Modern::Perl;
7
8
use Test::More tests => 18;
9
use List::Util qw(first);
21
use List::Util qw(first);
10
use Data::Dumper;
22
use Test::More tests => 5;
11
use Test::Warn;
23
use Test::Warn;
24
12
use t::lib::Mocks;
25
use t::lib::Mocks;
13
use Koha::Database;
26
use Koha::Database;
14
27
Lines 20-102 my $schema = Koha::Database->new->schema; Link Here
20
$schema->storage->txn_begin;
33
$schema->storage->txn_begin;
21
my $dbh = C4::Context->dbh;
34
my $dbh = C4::Context->dbh;
22
35
23
isnt(C4::Languages::_get_themes(), undef, 'testing _get_themes doesnt return undef');
36
subtest 'get_themes, get_language_dirs' => sub {
37
    plan tests => 4;
38
    isnt( C4::Languages::_get_themes(), undef, 'testing _get_themes doesnt return undef' );
39
    ok( C4::Languages::_get_language_dirs(), 'test getting _get_language_dirs' );
24
40
25
ok(C4::Languages::_get_language_dirs(), 'test getting _get_language_dirs');
41
    my $result;
42
    warning_is { $result = C4::Languages::accept_language(); }
43
        q{accept_language(x,y) called with no clientPreferences (x).},
44
        'accept_language() generated expected warning';
45
    is( $result,undef, 'test that accept_languages returns undef when nothing is entered' );
46
};
26
47
27
my $result;
48
subtest 'getAllLanguages' => sub {
28
warning_is { $result = C4::Languages::accept_language(); }
49
    plan tests => 5;
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
50
33
ok(C4::Languages::getAllLanguages(), 'test get all languages');
51
    ok( C4::Languages::getAllLanguages(), 'test get all languages' );
34
52
35
t::lib::Mocks::mock_preference('AdvancedSearchLanguages', '');
53
    t::lib::Mocks::mock_preference('AdvancedSearchLanguages', q{} );
36
my $all_languages = C4::Languages::getAllLanguages('eng');
54
    my $all_languages = C4::Languages::getAllLanguages('eng');
37
ok(@$all_languages > 10, 'retrieved a bunch of languges');
55
    ok( @$all_languages > 10, 'retrieved a bunch of languages' );
38
56
39
my $languages = C4::Languages::getLanguages('eng');
57
    my $languages = C4::Languages::getLanguages('eng');
40
is_deeply($languages, $all_languages, 'getLanguages() and getAllLanguages() return the same list');
58
    is_deeply( $languages, $all_languages, 'getLanguages() and getAllLanguages() return the same list' );
41
59
42
$languages = C4::Languages::getLanguages('eng', 1);
60
    $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');
61
    is_deeply( $languages, $all_languages, 'getLanguages() and getAllLanguages() with filtering selected but AdvancedSearchLanguages blank return the same list' );
44
62
45
t::lib::Mocks::mock_preference('AdvancedSearchLanguages', 'ita|eng');
63
    t::lib::Mocks::mock_preference( 'AdvancedSearchLanguages', 'ita|eng' );
46
$languages = C4::Languages::getLanguages('eng', 1);
64
    $languages = C4::Languages::getLanguages( 'eng', 1 );
47
is(scalar(@$languages), 2, 'getLanguages() filtering using AdvancedSearchLanguages works');
65
    is( scalar(@$languages), 2, 'getLanguages() filtering using AdvancedSearchLanguages works' );
66
};
48
67
49
my $translatedlanguages1;
68
subtest 'getTranslatedLanguages' => sub {
50
warnings_are { $translatedlanguages1 = C4::Languages::getTranslatedLanguages('opac','prog',undef,'') }
69
    plan tests => 4;
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
70
57
my $translatedlanguages2;
71
    my $translatedlanguages1;
58
warnings_are { $translatedlanguages2 = C4::Languages::getTranslatedLanguages('opac','prog','en','') }
72
    warnings_are { $translatedlanguages1 = C4::Languages::getTranslatedLanguages( 'opac', 'prog' ) }
59
             [],
73
        [],
60
             'no warnings for calling getTranslatedLanguages';
74
        '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
75
65
# Language Descriptions
76
    my @currentcheck1 = map { $_->{current} } @$translatedlanguages1;
66
my $sth = $dbh->prepare("SELECT DISTINCT subtag,type,lang,description from language_descriptions;");
77
    my $onlyzeros = first { $_ != 0 } @currentcheck1;
67
$sth->execute();
78
    ok(! $onlyzeros, "Everything was zeros.");
68
my $DistinctLangDesc = $sth->fetchall_arrayref({});
69
79
70
$sth = $dbh->prepare("SELECT subtag,type,lang,description from language_descriptions;");
80
    my $translatedlanguages2;
71
$sth->execute();
81
    warnings_are { $translatedlanguages2 = C4::Languages::getTranslatedLanguages( 'opac', 'prog', 'en' ) }
72
my $LangDesc = $sth->fetchall_arrayref({});
82
        [],
83
        'no warnings for calling getTranslatedLanguages';
84
    my @currentcheck2 = map { $_->{current} } @$translatedlanguages2;
85
    $onlyzeros = first { $_ != 0 } @currentcheck2;
86
    ok($onlyzeros, "There is a $onlyzeros");
87
};
73
88
74
is(scalar(@$LangDesc),scalar(@$DistinctLangDesc),"No unexpected language_description duplicates.");
89
subtest 'Language descriptions, Language_subtag_registry, RFC4646 to ISO639' => sub {
90
    plan tests => 4;
75
91
76
# Language_subtag_registry
92
    my $sth = $dbh->prepare( "SELECT DISTINCT subtag,type,lang,description from language_descriptions" );
77
$sth = $dbh->prepare("SELECT DISTINCT subtag,type,description,added FROM language_subtag_registry;");
93
    $sth->execute();
78
$sth->execute();
94
    my $DistinctLangDesc = $sth->fetchall_arrayref({});
79
my $DistinctLangReg = $sth->fetchall_arrayref({});
80
95
81
$sth = $dbh->prepare("SELECT subtag,type,description,added FROM language_subtag_registry;");
96
    $sth = $dbh->prepare("SELECT subtag,type,lang,description from language_descriptions;");
82
$sth->execute();
97
    $sth->execute();
83
my $LangReg = $sth->fetchall_arrayref({});
98
    my $LangDesc = $sth->fetchall_arrayref({});
84
99
85
is(scalar(@$LangReg),scalar(@$DistinctLangReg),"No unexpected language_subtag_registry duplicates.");
100
    is( scalar(@$LangDesc), scalar(@$DistinctLangDesc), "No unexpected language_description duplicates." );
86
101
87
# Language RFC4646 to ISO639
102
    # Language_subtag_registry
88
$sth = $dbh->prepare("SELECT DISTINCT rfc4646_subtag,iso639_2_code FROM language_rfc4646_to_iso639;");
103
    $sth = $dbh->prepare("SELECT DISTINCT subtag,type,description,added FROM language_subtag_registry;");
89
$sth->execute();
104
    $sth->execute();
90
my $DistinctLangRfc4646 = $sth->fetchall_arrayref({});
105
    my $DistinctLangReg = $sth->fetchall_arrayref({});
91
106
92
$sth = $dbh->prepare("SELECT rfc4646_subtag,iso639_2_code FROM language_rfc4646_to_iso639;");
107
    $sth = $dbh->prepare("SELECT subtag,type,description,added FROM language_subtag_registry;");
93
$sth->execute();
108
    $sth->execute();
94
my $LangRfc4646 = $sth->fetchall_arrayref({});
109
    my $LangReg = $sth->fetchall_arrayref({});
95
110
96
is(scalar(@$LangRfc4646),scalar(@$DistinctLangRfc4646),"No unexpected language_rfc4646_to_iso639 duplicates.");
111
    is( scalar(@$LangReg), scalar(@$DistinctLangReg), "No unexpected language_subtag_registry duplicates." );
97
112
98
my $i = 0;
113
    # Language RFC4646 to ISO639
99
foreach my $pair (@$DistinctLangRfc4646){
114
    $sth = $dbh->prepare( "SELECT DISTINCT rfc4646_subtag,iso639_2_code FROM language_rfc4646_to_iso639" );
100
    $i++ if $pair->{rfc4646_subtag} eq C4::Languages::get_rfc4646_from_iso639( $pair->{iso639_2_code} );
115
    $sth->execute();
101
}
116
    my $DistinctLangRfc4646 = $sth->fetchall_arrayref({});
102
is($i,scalar(@$DistinctLangRfc4646),"get_rfc4646_from_iso639 returns correct rfc for all iso values.");
117
118
    $sth = $dbh->prepare( "SELECT rfc4646_subtag,iso639_2_code FROM language_rfc4646_to_iso639" );
119
    $sth->execute();
120
    my $LangRfc4646 = $sth->fetchall_arrayref({});
121
122
    is( scalar(@$LangRfc4646), scalar(@$DistinctLangRfc4646), "No unexpected language_rfc4646_to_iso639 duplicates." );
123
124
    my $i = 0;
125
    foreach my $pair (@$DistinctLangRfc4646){
126
        $i++ if $pair->{rfc4646_subtag} eq C4::Languages::get_rfc4646_from_iso639( $pair->{iso639_2_code} );
127
    }
128
    is( $i, scalar(@$DistinctLangRfc4646), "get_rfc4646_from_iso639 returns correct rfc for all iso values." );
129
};
130
131
$schema->storage->txn_rollback;
103
- 

Return to bug 29245