mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Adding fixes and tests for Set::check(), closes #4077
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6441 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
0a52e958b9
commit
5770e95fc9
3 changed files with 34 additions and 8 deletions
|
@ -544,7 +544,7 @@ class Set extends Object {
|
|||
if ($i == count($path) - 1) {
|
||||
return (is_array($data) && array_key_exists($key, $data));
|
||||
} else {
|
||||
if (!is_array($data) && array_key_exists($key, $data)) {
|
||||
if (!is_array($data) || !array_key_exists($key, $data)) {
|
||||
return false;
|
||||
}
|
||||
$data =& $data[$key];
|
||||
|
|
|
@ -2141,7 +2141,6 @@ class ModelTest extends CakeTestCase {
|
|||
$this->assertEqual($result, $expected);
|
||||
|
||||
$data = array('Tag' => array('Tag' => array()));
|
||||
|
||||
$result = $this->model->set($data);
|
||||
$this->assertTrue($result);
|
||||
|
||||
|
@ -2161,12 +2160,7 @@ class ModelTest extends CakeTestCase {
|
|||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$data = array(
|
||||
'Tag' => array(
|
||||
'Tag' => array( 2, 3 )
|
||||
)
|
||||
);
|
||||
|
||||
$data = array('Tag' => array('Tag' => array(2, 3)));
|
||||
$result = $this->model->set($data);
|
||||
$this->assertTrue($result);
|
||||
|
||||
|
|
|
@ -64,6 +64,38 @@ class SetTest extends UnitTestCase {
|
|||
$this->assertFalse(Set::numeric(array_keys($data)));
|
||||
}
|
||||
|
||||
function testKeyCheck() {
|
||||
$data = array('Multi' => array('dimensonal' => array('array')));
|
||||
$this->assertTrue(Set::check($data, 'Multi.dimensonal'));
|
||||
$this->assertFalse(Set::check($data, 'Multi.dimensonal.array'));
|
||||
|
||||
$data = array(
|
||||
array(
|
||||
'Article' => array('id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'),
|
||||
'User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'),
|
||||
'Comment' => array(
|
||||
array('id' => '1', 'article_id' => '1', 'user_id' => '2', 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'),
|
||||
array('id' => '2', 'article_id' => '1', 'user_id' => '4', 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31'),
|
||||
),
|
||||
'Tag' => array(
|
||||
array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'),
|
||||
array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31')
|
||||
)
|
||||
),
|
||||
array(
|
||||
'Article' => array('id' => '3', 'user_id' => '1', 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'),
|
||||
'User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'),
|
||||
'Comment' => array(),
|
||||
'Tag' => array()
|
||||
)
|
||||
);
|
||||
$this->assertTrue(Set::check($data, '0.Article.user_id'));
|
||||
$this->assertTrue(Set::check($data, '0.Comment.0.id'));
|
||||
$this->assertFalse(Set::check($data, '0.Comment.0.id.0'));
|
||||
$this->assertTrue(Set::check($data, '0.Article.user_id'));
|
||||
$this->assertFalse(Set::check($data, '0.Article.user_id.a'));
|
||||
}
|
||||
|
||||
function testMerge() {
|
||||
$r = Set::merge(array('foo'));
|
||||
$this->assertIdentical($r, array('foo'));
|
||||
|
|
Loading…
Add table
Reference in a new issue