mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
cleaning up some Set::extract, adding tests for empty data and results. Removing some checks from Cache engine.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8097 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
b184d0705d
commit
198548092b
3 changed files with 35 additions and 20 deletions
|
@ -142,10 +142,6 @@ class Cache extends Object {
|
|||
* @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])) {
|
||||
|
|
|
@ -369,16 +369,16 @@ class Set extends Object {
|
|||
* @static
|
||||
*/
|
||||
function extract($path, $data = null, $options = array()) {
|
||||
if (empty($data) && is_string($path) && $path{0} === '/') {
|
||||
if (is_string($data)) {
|
||||
$tmp = $data;
|
||||
$data = $path;
|
||||
$path = $tmp;
|
||||
}
|
||||
if (empty($data)) {
|
||||
return array();
|
||||
}
|
||||
if (is_string($data) && $data{0} === '/') {
|
||||
$tmp = $path;
|
||||
$path = $data;
|
||||
$data = $tmp;
|
||||
}
|
||||
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 @@ class Set extends Object {
|
|||
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;
|
||||
|
|
|
@ -887,7 +887,7 @@ class SetTest extends CakeTestCase {
|
|||
$expected = array('Neo', 'Morpheus');
|
||||
$r = Set::extract('/User/name', $mixedKeys);
|
||||
$this->assertEqual($r, $expected);
|
||||
|
||||
|
||||
$single = array(
|
||||
array(
|
||||
'CallType' => array(
|
||||
|
@ -898,11 +898,11 @@ class SetTest extends CakeTestCase {
|
|||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
$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 @@ class SetTest extends CakeTestCase {
|
|||
$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 @@ class SetTest extends CakeTestCase {
|
|||
'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 @@ class SetTest extends CakeTestCase {
|
|||
$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
|
||||
|
|
Loading…
Add table
Reference in a new issue