Lines 21-37
use Modern::Perl;
Link Here
|
21 |
use List::Util qw(first); |
21 |
use List::Util qw(first); |
22 |
use Test::More tests => 5; |
22 |
use Test::More tests => 5; |
23 |
use Test::Warn; |
23 |
use Test::Warn; |
|
|
24 |
use Test::MockModule; |
24 |
|
25 |
|
25 |
use t::lib::Mocks; |
26 |
use t::lib::Mocks; |
26 |
use Koha::Database; |
27 |
use Koha::Database; |
|
|
28 |
use Koha::Caches; |
27 |
|
29 |
|
28 |
BEGIN { |
30 |
BEGIN { |
29 |
use_ok('C4::Languages', qw( accept_language getAllLanguages getLanguages getTranslatedLanguages get_rfc4646_from_iso639 )); |
31 |
use_ok('C4::Languages', qw( accept_language getAllLanguages getLanguages getTranslatedLanguages get_rfc4646_from_iso639 )); |
30 |
} |
32 |
} |
31 |
|
33 |
|
32 |
my $schema = Koha::Database->new->schema; |
34 |
our $schema = Koha::Database->new->schema; |
33 |
$schema->storage->txn_begin; |
35 |
$schema->storage->txn_begin; |
34 |
my $dbh = C4::Context->dbh; |
36 |
our $dbh = C4::Context->dbh; |
|
|
37 |
our $lang_module = Test::MockModule->new( 'C4::Languages' ); |
38 |
our $cache = Koha::Caches->get_instance; |
35 |
|
39 |
|
36 |
subtest 'get_themes, get_language_dirs' => sub { |
40 |
subtest 'get_themes, get_language_dirs' => sub { |
37 |
plan tests => 4; |
41 |
plan tests => 4; |
Lines 66-89
subtest 'getAllLanguages' => sub {
Link Here
|
66 |
}; |
70 |
}; |
67 |
|
71 |
|
68 |
subtest 'getTranslatedLanguages' => sub { |
72 |
subtest 'getTranslatedLanguages' => sub { |
69 |
plan tests => 4; |
73 |
plan tests => 9; |
|
|
74 |
|
75 |
# Obvious assumptions |
76 |
t::lib::Mocks::mock_preference( 'opacthemes', 'bootstrap' ); |
77 |
t::lib::Mocks::mock_preference( 'template', 'prog' ); |
70 |
|
78 |
|
71 |
my $translatedlanguages1; |
79 |
my $translatedlanguages1; |
72 |
warnings_are { $translatedlanguages1 = C4::Languages::getTranslatedLanguages( 'opac', 'prog' ) } |
80 |
$cache->clear_from_cache( "languages_opac_bootstrap" ); |
|
|
81 |
warnings_are { $translatedlanguages1 = C4::Languages::getTranslatedLanguages( 'opac', 'bootstrap' ) } |
73 |
[], |
82 |
[], |
74 |
'no warnings for calling getTranslatedLanguages'; |
83 |
'no warnings for calling getTranslatedLanguages'; |
75 |
|
|
|
76 |
my @currentcheck1 = map { $_->{current} } @$translatedlanguages1; |
84 |
my @currentcheck1 = map { $_->{current} } @$translatedlanguages1; |
77 |
my $onlyzeros = first { $_ != 0 } @currentcheck1; |
85 |
my $onlyzeros = first { $_ != 0 } @currentcheck1; |
78 |
ok(! $onlyzeros, "Everything was zeros."); |
86 |
is( $onlyzeros, undef, "No language was marked as current"); |
79 |
|
87 |
|
80 |
my $translatedlanguages2; |
88 |
my $translatedlanguages2; |
81 |
warnings_are { $translatedlanguages2 = C4::Languages::getTranslatedLanguages( 'opac', 'prog', 'en' ) } |
89 |
$cache->clear_from_cache( "languages_opac_bootstrap" ); |
|
|
90 |
warnings_are { $translatedlanguages2 = C4::Languages::getTranslatedLanguages( 'opac', 'bootstrap', 'en' ) } |
82 |
[], |
91 |
[], |
83 |
'no warnings for calling getTranslatedLanguages'; |
92 |
'no warnings for calling getTranslatedLanguages'; |
84 |
my @currentcheck2 = map { $_->{current} } @$translatedlanguages2; |
93 |
my @currentcheck2 = map { $_->{current} } @$translatedlanguages2; |
85 |
$onlyzeros = first { $_ != 0 } @currentcheck2; |
94 |
$onlyzeros = first { $_ != 0 } @currentcheck2; |
86 |
ok($onlyzeros, "There is a $onlyzeros"); |
95 |
is( $onlyzeros, 1, "en is marked as current now" ); |
|
|
96 |
|
97 |
# mock opac languages, test leaving out opac/bootstrap |
98 |
my @language_dirs; |
99 |
$lang_module->mock( '_get_language_dirs', sub { return @language_dirs; } ); |
100 |
t::lib::Mocks::mock_preference( 'OPACLanguages', 'ita,eng,nl-NL' ); |
101 |
@language_dirs = ( 'eng', 'ita', 'nl-NL' ); |
102 |
$translatedlanguages1 = C4::Languages::getTranslatedLanguages(); |
103 |
is( @$translatedlanguages1, 1, 'Only one language since we didnt clear the cache' ); |
104 |
$cache->clear_from_cache( "languages_opac_bootstrap" ); |
105 |
$translatedlanguages1 = C4::Languages::getTranslatedLanguages(); |
106 |
is( @$translatedlanguages1, 3, 'Check if we get back three languages now' ); |
107 |
|
108 |
# mock intranet languages |
109 |
@language_dirs = ( 'eng', 'fr-CA', 'fr-FR', 'fr-NL', 'zh-NL' ); |
110 |
$cache->clear_from_cache( "languages_intranet_prog" ); |
111 |
t::lib::Mocks::mock_preference( 'language', 'zh,fr-NL,fr-CA,eng,fr-FR,de-DE' ); # de-DE missing |
112 |
# TODO Should getTranslatedLanguages sort? |
113 |
$translatedlanguages1 = [ sort |
114 |
{ $a->{language} cmp $b->{language} } |
115 |
@{ C4::Languages::getTranslatedLanguages( 'intranet' ) }]; # forgot prog |
116 |
is( @$translatedlanguages1, 3, 'Three intranet languages' ); |
117 |
is( @{$translatedlanguages1->[1]->{sublanguages_loop}}, 3, 'Three french variants' ); |
118 |
is( $translatedlanguages1->[2]->{language}, 'zh', 'Found zh too' ); |
119 |
$lang_module->unmock( '_get_language_dirs' ); |
87 |
}; |
120 |
}; |
88 |
|
121 |
|
89 |
subtest 'Language descriptions, Language_subtag_registry, RFC4646 to ISO639' => sub { |
122 |
subtest 'Language descriptions, Language_subtag_registry, RFC4646 to ISO639' => sub { |
90 |
- |
|
|