Skip to content

Commit

Permalink
[jan] Horde_Registry_Nlsconfig#validLang() checks now if a locale is …
Browse files Browse the repository at this point in the history
…installed (Request #10457).
  • Loading branch information
yunosh committed Jan 18, 2016
1 parent fc45d04 commit 629dad1
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 4 deletions.
21 changes: 18 additions & 3 deletions framework/Core/lib/Horde/Registry/Nlsconfig.php
@@ -1,7 +1,5 @@
<?php
/**
* Interface to NLS configuration.
*
* Copyright 2010-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
Expand All @@ -12,6 +10,15 @@
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Core
*/

/**
* Interface to NLS configuration.
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Core
*/
class Horde_Registry_Nlsconfig
{
/**
Expand Down Expand Up @@ -122,7 +129,15 @@ public function __get($name)
public function validLang($lang)
{
if (!$GLOBALS['session']->exists('horde', 'nls/valid_' . $lang)) {
$GLOBALS['session']->set('horde', 'nls/valid_' . $lang, isset($this->languages[$lang]));
$valid = false;
if (isset($this->languages[$lang])) {
$locale = setlocale(LC_ALL, 0);
if (setlocale(LC_ALL, $lang . '.UTF-8')) {
$valid = true;
}
setlocale(LC_ALL, $locale);
}
$GLOBALS['session']->set('horde', 'nls/valid_' . $lang, $valid);
}

return $GLOBALS['session']->get('horde', 'nls/valid_' . $lang);
Expand Down
4 changes: 3 additions & 1 deletion framework/Core/package.xml
Expand Up @@ -39,6 +39,7 @@
</stability>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [jan] Horde_Registry_Nlsconfig#validLang() checks now if a locale is installed (Request #10457).
* [jan] Mark PHP 7 as supported.
* [jan] Add option to always lowercase user names after logging in.
</notes>
Expand Down Expand Up @@ -1463,7 +1464,7 @@
<package>
<name>Horde_Test</name>
<channel>pear.horde.org</channel>
<min>2.1.0</min>
<min>2.6.0</min>
<max>3.0.0alpha1</max>
<exclude>3.0.0alpha1</exclude>
</package>
Expand Down Expand Up @@ -4120,6 +4121,7 @@
<date>2016-01-05</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [jan] Horde_Registry_Nlsconfig#validLang() checks now if a locale is installed (Request #10457).
* [jan] Mark PHP 7 as supported.
* [jan] Add option to always lowercase user names after logging in.
</notes>
Expand Down
70 changes: 70 additions & 0 deletions framework/Core/test/Horde/Core/NlsconfigTest.php
@@ -0,0 +1,70 @@
<?php
/**
* Copyright 2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Core
*/

/**
* Tests for Horde_Registry_Nlsconfig.
*
* @author Jan Schneider <jan@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Core
*/
class Horde_Core_NlsconfigTest extends Horde_Test_Case
{
public function setUp()
{
$GLOBALS['session'] = new Horde_Session();
$GLOBALS['session']->sessionHandler = new Horde_Support_Stub();
$GLOBALS['registry'] = new Horde_Test_Stub_Registry('john', 'horde');
$config = new Horde_Test_Stub_Registry_Loadconfig(
'horde', 'nls.php', 'horde_nls_config'
);
foreach ($this->providerForTestGet() as $values) {
$config->config['horde_nls_config'][$values[0]] = $values[1];
}
$GLOBALS['registry']->setConfigFile(
$config, 'nls.php', 'horde_nls_config', 'horde'
);
}

public function providerForTestGet()
{
return array(
'languages' => array(
'languages', array('en_US' => '&#x202d;English (American)')
),
'aliases' => array(
'aliases',
array('ar' => 'ar_SY', 'bg' => 'bg_BG')
),
'charsets' => array(
'charsets',
array('bg_BG' => 'windows-1251', 'bs_BA' => 'ISO-8859-2')
),
);
}

/**
* @dataProvider providerForTestGet
*/
public function testGet($key, $expected)
{
$nls = new Horde_Registry_Nlsconfig();
}

public function testValidLang()
{
$nls = new Horde_Registry_Nlsconfig();
$this->assertTrue($nls->validLang('en_US'));
$this->assertFalse($nls->validLang('xy_XY'));
}
}

0 comments on commit 629dad1

Please sign in to comment.