Browse Source

added check from input params in method init()

master
Vyacheslav Agafonov 13 years ago
parent
commit
b7e71c20b7
  1. 6
      i18n/I18N.php
  2. 13
      tests/i18n/I18NTest.php

6
i18n/I18N.php

@ -28,7 +28,11 @@ class I18N
static public function init()
{
$config = Config::get(__CLASS__);
if (!is_array($config['locales'])) {
throw new InitializationException('locales empty');
}
self::$locales = $config['locales'];
if (isset($config['bidi'])) {

13
tests/i18n/I18NTest.php

@ -14,16 +14,17 @@ require_once dirname(__FILE__) . '/../../Registry.php';
require_once dirname(__FILE__) . '/../../Config.php';
require_once dirname(__FILE__) . '/../../classes/Env.class.php';
require_once dirname(__FILE__) . '/../../i18n/I18N.php';
require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
require_once dirname(__FILE__) . '/../../exception/InitializationException.php';
/**
* @runTestsInSeparateProcesses
*/
class I18NTest extends PHPUnit_Framework_TestCase
{
public function run(PHPUnit_Framework_TestResult $result = NULL)
{
$this->setConstants();
$this->setPreserveGlobalState(false);
return parent::run($result);
}
@ -34,18 +35,18 @@ class I18NTest extends PHPUnit_Framework_TestCase
public function testInit()
{
$this->setConstants();
Config::set('I18N', array('locales' => array('ru' => 'ru-ru', 'us' => 'en-us')));
Config::set('I18N', array('locales' => array('ru' => 'ru-ru', 'us' => 'en-us')));
I18N::init();
$this->assertAttributeEquals(array('ru' => 'ru-ru', 'us' => 'en-us'), 'locales', 'I18N');
$this->assertAttributeEquals('ru-ru', 'locale', 'I18N');
}
/**
* @expectedException GeneralException
*/
public function testInitNoConfig()
{
Config::set('I18N', array('locales' => null));
$this->setExpectedException('InitializationException');
I18N::init();
}

Loading…
Cancel
Save