diff --git a/cake/libs/cache.php b/cake/libs/cache.php index 9cf59f861fa..6a6550cdb23 100644 --- a/cake/libs/cache.php +++ b/cake/libs/cache.php @@ -142,10 +142,6 @@ function config($name = null, $settings = array()) { * @static */ function engine($name = 'File', $settings = array()) { - if (!$name || Configure::read('Cache.disable')) { - return false; - } - $cacheClass = $name . 'Engine'; $_this =& Cache::getInstance(); if (!isset($_this->_Engine[$name])) { diff --git a/cake/libs/set.php b/cake/libs/set.php index 302056f98aa..4376f5c0554 100644 --- a/cake/libs/set.php +++ b/cake/libs/set.php @@ -369,16 +369,16 @@ function format($data, $format, $keys) { * @static */ function extract($path, $data = null, $options = array()) { - if (empty($data) && is_string($path) && $path{0} === '/') { - return array(); + if (is_string($data)) { + $tmp = $data; + $data = $path; + $path = $tmp; } - if (is_string($data) && $data{0} === '/') { - $tmp = $path; - $path = $data; - $data = $tmp; + if (empty($data)) { + return array(); } - if (is_array($path) || empty($data) || is_object($path) || empty($path)) { - return Set::classicExtract($path, $data); + if (strpos($path, '/') === false) { + return Set::classicExtract($data, $path); } if ($path === '/') { return $data; @@ -1090,7 +1090,7 @@ function __flatten($results, $key = null) { function sort($data, $path, $dir) { $result = Set::__flatten(Set::extract($data, $path)); list($keys, $values) = array(Set::extract($result, '{n}.id'), Set::extract($result, '{n}.value')); - + $dir = strtolower($dir); if ($dir === 'asc') { $dir = SORT_ASC; diff --git a/cake/tests/cases/libs/set.test.php b/cake/tests/cases/libs/set.test.php index c1bf885dcb5..ed2f4f04c58 100644 --- a/cake/tests/cases/libs/set.test.php +++ b/cake/tests/cases/libs/set.test.php @@ -887,7 +887,7 @@ function testExtract() { $expected = array('Neo', 'Morpheus'); $r = Set::extract('/User/name', $mixedKeys); $this->assertEqual($r, $expected); - + $single = array( array( 'CallType' => array( @@ -898,11 +898,11 @@ function testExtract() { ) ) ); - + $expected = array(7); $r = Set::extract('/CallType[name=Internal Voice]/../x/hour', $single); $this->assertEqual($r, $expected); - + $multiple = array( array( 'CallType' => array( @@ -933,7 +933,7 @@ function testExtract() { $expected = array(7,2,1); $r = Set::extract('/CallType[name=Internal Voice]/../x/hour', $multiple); $this->assertEqual($r, $expected); - + $f = array( array( 'file' => array( @@ -961,16 +961,16 @@ function testExtract() { 'error' => 0, 'size' => '21324' ) - ) + ) ); $expected = array(array('name' => 'zipfile2.zip','type' => 'application/x-zip-compressed','tmp_name' => '/tmp/php179.tmp','error' => 0,'size' => '354784')); $r = Set::extract('/file/.[type=application/x-zip-compressed]', $f); $this->assertEqual($r, $expected); - + $expected = array(array('name' => 'zipfile.zip','type' => 'application/zip','tmp_name' => '/tmp/php178.tmp','error' => 0,'size' => '564647')); $r = Set::extract('/file/.[type=application/zip]', $f); $this->assertEqual($r, $expected); - + } /** * testMatches method @@ -1042,6 +1042,25 @@ function testMatches() { $this->assertEqual(Set::extract('/Article/keep/Comment/fields', $r), array('comment', 'published')); $this->assertEqual(Set::extract('/Article/keep/User/fields', $r), array('user')); + + } +/** + * testSetExtractReturnsEmptyArray method + * + * @access public + * @return void + */ + function testSetExtractReturnsEmptyArray() { + + $this->assertEqual(Set::extract(array(), '/Post/id'), array()); + + $this->assertEqual(Set::extract('/Post/id', array()), array()); + + $this->assertEqual(Set::extract('/Post/id', array( + array('Post' => array('name' => 'bob')), + array('Post' => array('name' => 'jim')) + )), array()); + } /** * testClassicExtract method