diff --git a/cake/libs/inflector.php b/cake/libs/inflector.php index 3b1efd0cc0d..9221c820b22 100644 --- a/cake/libs/inflector.php +++ b/cake/libs/inflector.php @@ -234,6 +234,13 @@ class Inflector { */ protected static $_cache = array(); +/** + * The initial state of Inflector so reset() works. + * + * @var array + */ + protected static $_initialState = array(); + /** * Cache inflected values, and return if already available * @@ -255,6 +262,24 @@ protected static function _cache($type, $key, $value = false) { return self::$_cache[$type][$key]; } +/** + * Clears Inflectors inflected value caches. And resets the inflection + * rules to the initial values. + * + * @return void + */ + public static function reset() { + if (empty(self::$_initialState)) { + self::$_initialState = get_class_vars('Inflector'); + return; + } + foreach (self::$_initialState as $key => $val) { + if ($key != '_initialState') { + self::${$key} = $val; + } + } + } + /** * Adds custom inflection $rules, of either 'plural', 'singular' or 'transliteration' $type. * @@ -540,3 +565,6 @@ public static function slug($string, $replacement = '_', $map = array()) { return preg_replace(array_keys($map), array_values($map), $string); } } + +// Store the initial state +Inflector::reset(); \ No newline at end of file diff --git a/cake/tests/cases/libs/all_libs.test.php b/cake/tests/cases/libs/all_libs.test.php index 32a196953dd..3d334d72b26 100644 --- a/cake/tests/cases/libs/all_libs.test.php +++ b/cake/tests/cases/libs/all_libs.test.php @@ -42,6 +42,7 @@ public static function suite() { $suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'error_handler.test.php'); $suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'file.test.php'); $suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'folder.test.php'); + $suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'inflector.test.php'); $suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'log' . DS . 'file_log.test.php'); $suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'cake_log.test.php'); $suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'class_registry.test.php'); diff --git a/cake/tests/cases/libs/inflector.test.php b/cake/tests/cases/libs/inflector.test.php index 4dab49f4933..edf434e9b9f 100644 --- a/cake/tests/cases/libs/inflector.test.php +++ b/cake/tests/cases/libs/inflector.test.php @@ -35,12 +35,14 @@ class InflectorTest extends CakeTestCase { /** - * Inflector property + * teardown * - * @var mixed null - * @access public + * @return void */ - public $Inflector = null; + function tearDown() { + parent::tearDown(); + Inflector::reset(); + } /** * testInflectingSingulars method