From b7e71c20b7a06dec712449c041c3335e6f1e7014 Mon Sep 17 00:00:00 2001 From: Vyacheslav Agafonov Date: Mon, 28 Nov 2011 20:24:20 +0400 Subject: [PATCH] added check from input params in method init() --- i18n/I18N.php | 6 +++++- tests/i18n/I18NTest.php | 13 +++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/i18n/I18N.php b/i18n/I18N.php index e4f0f25..523efc1 100644 --- a/i18n/I18N.php +++ b/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'])) { diff --git a/tests/i18n/I18NTest.php b/tests/i18n/I18NTest.php index f5e9ed6..593c9ed 100644 --- a/tests/i18n/I18NTest.php +++ b/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(); }