Bug 22770: DBRev 19.05.00.003
[koha.git] / t / Languages.t
1 #!/usr/bin/perl
2
3 # Copyright 2013 Equinox Software, Inc.
4 # Copyright 2014 BibLibre
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 3 of the License, or (at your option) any later
11 # version.
12 #
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use Modern::Perl;
21 use Test::More tests => 4;
22 use Test::MockModule;
23 use CGI qw ( -utf8 );
24 use Koha::Cache::Memory::Lite;
25
26 BEGIN {
27     use_ok('C4::Languages');
28 }
29
30 my @languages = (); # stores the list of active languages
31                     # for the syspref mock
32 my $return_undef = 0;
33
34 my $module_context = new Test::MockModule('C4::Context');
35
36 $module_context->mock(
37     preference => sub {
38         my ($self, $pref) = @_;
39         if ($return_undef) {
40             return undef;
41         } elsif ($pref =~ /language/) {
42             return join ',', @languages;
43         } else {
44             return 'XXX';
45         }
46   },
47 );
48
49 delete $ENV{HTTP_ACCEPT_LANGUAGE};
50
51 my $query = CGI->new();
52 @languages = ('de-DE', 'fr-FR');
53 is(C4::Languages::getlanguage($query), 'de-DE', 'default to first language specified in syspref (bug 10560)');
54
55 Koha::Cache::Memory::Lite->get_instance()->clear_from_cache('getlanguage');
56 @languages = ();
57 is(C4::Languages::getlanguage($query), 'en', 'default to English if no language specified in syspref (bug 10560)');
58
59 Koha::Cache::Memory::Lite->get_instance()->clear_from_cache('getlanguage');
60 $return_undef = 1;
61 is(C4::Languages::getlanguage($query), 'en', 'default to English if no database');