mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 00:48:25 +00:00
Adding documentation to show result of Set::reverse() with non-objects. Fixing commented out test for Set class and adding more tests.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6682 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
2262e5803c
commit
9af317b1b4
2 changed files with 65 additions and 70 deletions
|
@ -979,9 +979,10 @@ class Set extends Object {
|
||||||
return array_combine($keys, $vals);
|
return array_combine($keys, $vals);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Converts an object into an array
|
* Converts an object into an array. If $object is no object, reverse
|
||||||
|
* will return the same value.
|
||||||
*
|
*
|
||||||
* @param object $object
|
* @param object $object Object to reverse
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function reverse($object) {
|
function reverse($object) {
|
||||||
|
@ -1029,8 +1030,7 @@ class Set extends Object {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else if (is_object($object)) {
|
||||||
if (is_object($object)) {
|
|
||||||
$keys = get_object_vars($object);
|
$keys = get_object_vars($object);
|
||||||
if (isset($keys['_name_'])) {
|
if (isset($keys['_name_'])) {
|
||||||
$identity = $keys['_name_'];
|
$identity = $keys['_name_'];
|
||||||
|
@ -1056,8 +1056,6 @@ class Set extends Object {
|
||||||
} else {
|
} else {
|
||||||
$out = $object;
|
$out = $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -35,7 +35,6 @@ App::import('Core', 'Set');
|
||||||
* @subpackage cake.tests.cases.libs
|
* @subpackage cake.tests.cases.libs
|
||||||
*/
|
*/
|
||||||
class SetTest extends UnitTestCase {
|
class SetTest extends UnitTestCase {
|
||||||
|
|
||||||
function testNumericKeyExtraction() {
|
function testNumericKeyExtraction() {
|
||||||
$data = array('plugin' => null, 'controller' => '', 'action' => '', 1, 'whatever');
|
$data = array('plugin' => null, 'controller' => '', 'action' => '', 1, 'whatever');
|
||||||
$this->assertIdentical(Set::extract($data, '{n}'), array(1, 'whatever'));
|
$this->assertIdentical(Set::extract($data, '{n}'), array(1, 'whatever'));
|
||||||
|
@ -182,7 +181,6 @@ class SetTest extends UnitTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
function testSort() {
|
function testSort() {
|
||||||
// ascending
|
|
||||||
$a = array(
|
$a = array(
|
||||||
0 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'Nate'))),
|
0 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'Nate'))),
|
||||||
1 => array('Person' => array('name' => 'Tracy'),'Friend' => array(array('name' => 'Lindsay')))
|
1 => array('Person' => array('name' => 'Tracy'),'Friend' => array(array('name' => 'Lindsay')))
|
||||||
|
@ -195,7 +193,6 @@ class SetTest extends UnitTestCase {
|
||||||
$a = Set::sort($a, '{n}.Friend.{n}.name', 'asc');
|
$a = Set::sort($a, '{n}.Friend.{n}.name', 'asc');
|
||||||
$this->assertIdentical($a, $b);
|
$this->assertIdentical($a, $b);
|
||||||
|
|
||||||
// descending
|
|
||||||
$b = array(
|
$b = array(
|
||||||
0 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'Nate'))),
|
0 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'Nate'))),
|
||||||
1 => array('Person' => array('name' => 'Tracy'),'Friend' => array(array('name' => 'Lindsay')))
|
1 => array('Person' => array('name' => 'Tracy'),'Friend' => array(array('name' => 'Lindsay')))
|
||||||
|
@ -208,7 +205,6 @@ class SetTest extends UnitTestCase {
|
||||||
$a = Set::sort($a, '{n}.Friend.{n}.name', 'desc');
|
$a = Set::sort($a, '{n}.Friend.{n}.name', 'desc');
|
||||||
$this->assertIdentical($a, $b);
|
$this->assertIdentical($a, $b);
|
||||||
|
|
||||||
// ascending (with different key)
|
|
||||||
$a = array(
|
$a = array(
|
||||||
0 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'Nate'))),
|
0 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'Nate'))),
|
||||||
1 => array('Person' => array('name' => 'Tracy'),'Friend' => array(array('name' => 'Lindsay'))),
|
1 => array('Person' => array('name' => 'Tracy'),'Friend' => array(array('name' => 'Lindsay'))),
|
||||||
|
@ -222,8 +218,6 @@ class SetTest extends UnitTestCase {
|
||||||
$a = Set::sort($a, '{n}.Person.name', 'asc');
|
$a = Set::sort($a, '{n}.Person.name', 'asc');
|
||||||
$this->assertIdentical($a, $b);
|
$this->assertIdentical($a, $b);
|
||||||
|
|
||||||
|
|
||||||
// given a path to an array as the sort path, sort by lowest or highest value in array
|
|
||||||
$a = array(
|
$a = array(
|
||||||
array(7,6,4),
|
array(7,6,4),
|
||||||
array(3,4,5),
|
array(3,4,5),
|
||||||
|
@ -239,8 +233,6 @@ class SetTest extends UnitTestCase {
|
||||||
$a = Set::sort($a, '{n}.{n}', 'asc');
|
$a = Set::sort($a, '{n}.{n}', 'asc');
|
||||||
$this->assertIdentical($a, $b);
|
$this->assertIdentical($a, $b);
|
||||||
|
|
||||||
|
|
||||||
// as per above, but nested arrays
|
|
||||||
$a = array(
|
$a = array(
|
||||||
array(7,6,4),
|
array(7,6,4),
|
||||||
array(3,4,5),
|
array(3,4,5),
|
||||||
|
@ -256,8 +248,6 @@ class SetTest extends UnitTestCase {
|
||||||
$a = Set::sort($a, '{n}', 'asc');
|
$a = Set::sort($a, '{n}', 'asc');
|
||||||
$this->assertIdentical($a, $b);
|
$this->assertIdentical($a, $b);
|
||||||
|
|
||||||
|
|
||||||
// if every element doesn't have the matching key, the one without is compared as empty
|
|
||||||
$a = array(
|
$a = array(
|
||||||
0 => array('Person' => array('name' => 'Jeff')),
|
0 => array('Person' => array('name' => 'Jeff')),
|
||||||
1 => array('Shirt' => array('color' => 'black'))
|
1 => array('Shirt' => array('color' => 'black'))
|
||||||
|
@ -808,6 +798,12 @@ class SetTest extends UnitTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
function testMapReverse() {
|
function testMapReverse() {
|
||||||
|
$result = Set::reverse(null);
|
||||||
|
$this->assertEqual($result, null);
|
||||||
|
|
||||||
|
$result = Set::reverse(false);
|
||||||
|
$this->assertEqual($result, false);
|
||||||
|
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'Array1' => array(
|
'Array1' => array(
|
||||||
'Array1Data1' => 'Array1Data1 value 1', 'Array1Data2' => 'Array1Data2 value 2'),
|
'Array1Data1' => 'Array1Data1 value 1', 'Array1Data2' => 'Array1Data2 value 2'),
|
||||||
|
@ -830,7 +826,6 @@ class SetTest extends UnitTestCase {
|
||||||
$result = Set::reverse($map);
|
$result = Set::reverse($map);
|
||||||
$this->assertIdentical($result, $expected);
|
$this->assertIdentical($result, $expected);
|
||||||
|
|
||||||
|
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'Post' => array('id'=> 1, 'title' => 'First Post'),
|
'Post' => array('id'=> 1, 'title' => 'First Post'),
|
||||||
'Comment' => array(
|
'Comment' => array(
|
||||||
|
@ -1003,10 +998,11 @@ class SetTest extends UnitTestCase {
|
||||||
uses('model'.DS.'model');
|
uses('model'.DS.'model');
|
||||||
$model = new Model(array('id' => false, 'name' => 'Model', 'table' => false));
|
$model = new Model(array('id' => false, 'name' => 'Model', 'table' => false));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
|
'Behaviors' => array('modelName' => 'Model', '_attached' => array(), '_disabled' => array(), '__methods' => array(), '__mappedMethods' => array(), '_log' => null),
|
||||||
'useDbConfig' => 'default', 'useTable' => false, 'displayField' => null, 'id' => false, 'data' => array(), 'table' => false, 'primaryKey' => 'id', '_schema' => null, 'validate' => array(),
|
'useDbConfig' => 'default', 'useTable' => false, 'displayField' => null, 'id' => false, 'data' => array(), 'table' => false, 'primaryKey' => 'id', '_schema' => null, 'validate' => array(),
|
||||||
'validationErrors' => array(), 'tablePrefix' => null, 'name' => 'Model', 'alias' => 'Model', 'tableToModel' => array(), 'logTransactions' => false, 'transactional' => false, 'cacheQueries' => false,
|
'validationErrors' => array(), 'tablePrefix' => null, 'name' => 'Model', 'alias' => 'Model', 'tableToModel' => array(), 'logTransactions' => false, 'transactional' => false, 'cacheQueries' => false,
|
||||||
'belongsTo' => array(), 'hasOne' => array(), 'hasMany' => array(), 'hasAndBelongsToMany' => array(), 'actsAs' => null, 'behaviors' => array(), 'whitelist' => array(), 'cacheSources' => true,
|
'belongsTo' => array(), 'hasOne' => array(), 'hasMany' => array(), 'hasAndBelongsToMany' => array(), 'actsAs' => null, 'whitelist' => array(), 'cacheSources' => true,
|
||||||
'findQueryType' => null, '__behaviorMethods' => array(), 'recursive' => 1, 'order' => null, '__exists' => null,
|
'findQueryType' => null, 'recursive' => 1, 'order' => null, '__exists' => null,
|
||||||
'__associationKeys' => array(
|
'__associationKeys' => array(
|
||||||
'belongsTo' => array('className', 'foreignKey', 'conditions', 'fields', 'order', 'counterCache'),
|
'belongsTo' => array('className', 'foreignKey', 'conditions', 'fields', 'order', 'counterCache'),
|
||||||
'hasOne' => array('className', 'foreignKey', 'conditions', 'fields', 'order', 'dependent'),
|
'hasOne' => array('className', 'foreignKey', 'conditions', 'fields', 'order', 'dependent'),
|
||||||
|
@ -1014,11 +1010,12 @@ class SetTest extends UnitTestCase {
|
||||||
'hasAndBelongsToMany' => array('className', 'joinTable', 'with', 'foreignKey', 'associationForeignKey', 'conditions', 'fields', 'order', 'limit', 'offset', 'unique', 'finderQuery', 'deleteQuery', 'insertQuery')),
|
'hasAndBelongsToMany' => array('className', 'joinTable', 'with', 'foreignKey', 'associationForeignKey', 'conditions', 'fields', 'order', 'limit', 'offset', 'unique', 'finderQuery', 'deleteQuery', 'insertQuery')),
|
||||||
'__associations' => array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany'), '__backAssociation' => array(), '__insertID' => null, '__numRows' => null, '__affectedRows' => null,
|
'__associations' => array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany'), '__backAssociation' => array(), '__insertID' => null, '__numRows' => null, '__affectedRows' => null,
|
||||||
'__findMethods' => array('all' => true, 'first' => true, 'count' => true, 'neighbors' => true, 'list' => true), '_log' => null);
|
'__findMethods' => array('all' => true, 'first' => true, 'count' => true, 'neighbors' => true, 'list' => true), '_log' => null);
|
||||||
//$result = Set::reverse($model);
|
$result = Set::reverse($model);
|
||||||
|
|
||||||
//ksort($result);
|
ksort($result);
|
||||||
//ksort($expected);
|
ksort($expected);
|
||||||
//$this->assertIdentical($result, $expected);
|
|
||||||
|
$this->assertIdentical($result, $expected);
|
||||||
|
|
||||||
$class = new stdClass;
|
$class = new stdClass;
|
||||||
$class->User = new stdClass;
|
$class->User = new stdClass;
|
||||||
|
|
Loading…
Add table
Reference in a new issue