From 5b8f680d43874e98ac3be2ba40045c61777b05b2 Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Sun, 23 Jan 2011 20:00:06 -0200 Subject: [PATCH] Throwing exception instead notice in loadConfig. --- cake/libs/view/helpers/html.php | 40 +++++++++---------- .../cases/libs/view/helpers/html.test.php | 4 +- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/cake/libs/view/helpers/html.php b/cake/libs/view/helpers/html.php index 21543f311..436941a81 100644 --- a/cake/libs/view/helpers/html.php +++ b/cake/libs/view/helpers/html.php @@ -937,34 +937,30 @@ class HtmlHelper extends AppHelper { $reader = $configFile[1]; } } else { - return trigger_error(__('Cannot load the configuration file. Wrong "configFile" configuration.'), E_USER_NOTICE); + throw new ConfigureException(__('Cannot load the configuration file. Wrong "configFile" configuration.')); } $readerClass = Inflector::camelize($reader) . 'Reader'; if (!App::import('Lib', 'config/' . $readerClass)) { - return trigger_error(__('Cannot load the configuration file. Unknown reader.'), E_USER_NOTICE); + throw new ConfigureException(__('Cannot load the configuration file. Unknown reader.')); } - try { - $readerObj = new $readerClass($path); - $configs = $readerObj->read($file); - if (isset($configs['tags']) && is_array($configs['tags'])) { - $this->_tags = array_merge($this->_tags, $configs['tags']); - } - if (isset($configs['minimizedAttributes']) && is_array($configs['minimizedAttributes'])) { - $this->_minimizedAttributes = array_merge($this->_minimizedAttributes, $configs['minimizedAttributes']); - } - if (isset($configs['docTypes']) && is_array($configs['docTypes'])) { - $this->__docTypes = array_merge($this->__docTypes, $configs['docTypes']); - } - if (isset($configs['attributeFormat'])) { - $this->_attributeFormat = $configs['attributeFormat']; - } - if (isset($configs['minimizedAttributeFormat'])) { - $this->_minimizedAttributeFormat = $configs['minimizedAttributeFormat']; - } - } catch (Exception $e) { - return trigger_error(__('Cannot load the configuration file. Failed to load the file.'), E_USER_NOTICE); + $readerObj = new $readerClass($path); + $configs = $readerObj->read($file); + if (isset($configs['tags']) && is_array($configs['tags'])) { + $this->_tags = array_merge($this->_tags, $configs['tags']); + } + if (isset($configs['minimizedAttributes']) && is_array($configs['minimizedAttributes'])) { + $this->_minimizedAttributes = array_merge($this->_minimizedAttributes, $configs['minimizedAttributes']); + } + if (isset($configs['docTypes']) && is_array($configs['docTypes'])) { + $this->__docTypes = array_merge($this->__docTypes, $configs['docTypes']); + } + if (isset($configs['attributeFormat'])) { + $this->_attributeFormat = $configs['attributeFormat']; + } + if (isset($configs['minimizedAttributeFormat'])) { + $this->_minimizedAttributeFormat = $configs['minimizedAttributeFormat']; } return $configs; } diff --git a/cake/tests/cases/libs/view/helpers/html.test.php b/cake/tests/cases/libs/view/helpers/html.test.php index a7a4cfbec..c2226acac 100644 --- a/cake/tests/cases/libs/view/helpers/html.test.php +++ b/cake/tests/cases/libs/view/helpers/html.test.php @@ -1400,11 +1400,11 @@ class HtmlHelperTest extends CakeTestCase { $this->assertEqual($result, $expected); $this->assertEqual($this->Html->getAttribute('_minimizedAttributeFormat'), 'format'); - $this->expectError(); + $this->expectException('ConfigureException'); $result = $this->Html->loadConfig('wrong_file'); $this->assertFalse($result); - $this->expectError(); + $this->expectException('ConfigureException'); $result = $this->Html->loadConfig(array('htmlhelper_tags', 'wrong_reader'), $path); $this->assertFalse($result); }