mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Added a new $altKey parameter to normalizeFindParams
Refactored the unit test for it and added more samples git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6018 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
266d7ba738
commit
b3afc463ac
2 changed files with 73 additions and 22 deletions
|
@ -2062,7 +2062,7 @@ class Model extends Overloadable {
|
|||
return false;
|
||||
}
|
||||
|
||||
function normalizeFindParams($type, $data, $r = array(), $_this = null) {
|
||||
function normalizeFindParams($type, $data, $altType = null, $r = array(), $_this = null) {
|
||||
if ($_this == null) {
|
||||
$_this = $this;
|
||||
$root = true;
|
||||
|
@ -2082,15 +2082,23 @@ class Model extends Overloadable {
|
|||
|
||||
if (!empty($children)) {
|
||||
if ($_this->name == $name) {
|
||||
$r = am($r, $this->normalizeFindParams($type, $children, $r, $_this));
|
||||
$r = am($r, $this->normalizeFindParams($type, $children, $altType, $r, $_this));
|
||||
} else {
|
||||
$r[$name] = $this->normalizeFindParams($type, $children, @$r[$name], $_this->{$name});;
|
||||
if (!$_this->getAssociated($name)) {
|
||||
$r[$altType][$name] = $children;
|
||||
} else {
|
||||
$r[$name] = $this->normalizeFindParams($type, $children, $altType, @$r[$name], $_this->{$name});;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($_this->getAssociated($name)) {
|
||||
$r[$name] = array($type => null);
|
||||
} else {
|
||||
if ($altType != null) {
|
||||
$r[$type][] = $name;
|
||||
} else {
|
||||
$r[$type] = $name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -461,18 +461,23 @@ class ModelTest extends CakeTestCase {
|
|||
}
|
||||
|
||||
function testNormalizeFindParams() {
|
||||
$this->model =& new Article();
|
||||
|
||||
$result = $this->model->normalizeFindParams('fields', array(
|
||||
$samples = array(
|
||||
0 => array(
|
||||
'model' => new Article(),
|
||||
'params' => array(
|
||||
'fields',
|
||||
array(
|
||||
'title', 'body', 'published',
|
||||
'Article.id', 'User', 'Comment.id', 'Comment.comment', 'Comment.User.password', 'Comment.Article',
|
||||
'Tag' => array('id', 'tag')
|
||||
)
|
||||
);
|
||||
$expected = array(
|
||||
'Tag' => array('id', 'tag'),
|
||||
'User.name' => 'Jimmy',
|
||||
),
|
||||
'conditions'
|
||||
),
|
||||
'expected' => array(
|
||||
'Article' => array(
|
||||
'fields' => array('title', 'body', 'published', 'id'),
|
||||
'User' => array('fields' => null),
|
||||
'User' => array('fields' => null, 'conditions' => array('name' => 'Jimmy')),
|
||||
'Comment' => array(
|
||||
'fields' => array('id', 'comment'),
|
||||
'User' => array('fields' => array('password')),
|
||||
|
@ -480,8 +485,46 @@ class ModelTest extends CakeTestCase {
|
|||
),
|
||||
'Tag' => array('fields' => array('id', 'tag'))
|
||||
)
|
||||
)
|
||||
),
|
||||
1 => array(
|
||||
'params' => array(
|
||||
'fields',
|
||||
array(
|
||||
'User.id' => 2
|
||||
),
|
||||
'conditions'
|
||||
),
|
||||
'expected' => array(
|
||||
'Article' => array(
|
||||
'User' => array(
|
||||
'conditions' => array('id' => 2)
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
2 => array(
|
||||
'params' => array(
|
||||
'limit',
|
||||
array('Comment' => 5),
|
||||
),
|
||||
'expected' => array(
|
||||
'Article' => array(
|
||||
'Comment' => array(
|
||||
'limit' => 5
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
foreach ($samples as $i => $sample) {
|
||||
if (isset($sample['model'])) {
|
||||
$Model =& $sample['model'];
|
||||
}
|
||||
$results = call_user_func_array(array(&$Model, 'normalizeFindParams'), $sample['params']);
|
||||
$this->assertEqual($results, $sample['expected'], '%s - Sample #'.$i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue