From 328513d35ee937b6cbfc5384cdceba82cf36fb89 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 11 Jan 2012 21:33:14 -0500 Subject: [PATCH] Start Set2. --- lib/Cake/Test/Case/Utility/Set2Test.php | 145 ++++++++++++++++++++++++ lib/Cake/Utility/Set2.php | 56 +++++++++ 2 files changed, 201 insertions(+) create mode 100644 lib/Cake/Test/Case/Utility/Set2Test.php create mode 100644 lib/Cake/Utility/Set2.php diff --git a/lib/Cake/Test/Case/Utility/Set2Test.php b/lib/Cake/Test/Case/Utility/Set2Test.php new file mode 100644 index 000000000..01dd79e6a --- /dev/null +++ b/lib/Cake/Test/Case/Utility/Set2Test.php @@ -0,0 +1,145 @@ + array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + ), + 'Comment' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + ), + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => 'Second Comment for First Article', + ), + ), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + ), + array( + 'id' => '2', + 'tag' => 'tag2', + ) + ), + 'Deep' => array( + 'Nesting' => array( + 'test' => array( + 1 => 'foo', + 2 => array( + 'and' => array('more' => 'stuff') + ) + ) + ) + ) + ), + array( + 'Article' => array( + 'id' => '3', + 'user_id' => '1', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + ), + 'User' => array( + 'id' => '2', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + ), + 'Comment' => array(), + 'Tag' => array() + ), + array( + 'Article' => array( + 'id' => '3', + 'user_id' => '1', + 'title' => 'Third Article', + 'body' => 'Third Article Body', + ), + 'User' => array( + 'id' => '3', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + ), + 'Comment' => array(), + 'Tag' => array() + ), + array( + 'Article' => array( + 'id' => '4', + 'user_id' => '1', + 'title' => 'Fourth Article', + 'body' => 'Fourth Article Body', + ), + 'User' => array( + 'id' => '4', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + ), + 'Comment' => array(), + 'Tag' => array() + ), + array( + 'Article' => array( + 'id' => '5', + 'user_id' => '1', + 'title' => 'Fifth Article', + 'body' => 'Fifth Article Body', + ), + 'User' => array( + 'id' => '5', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + ), + 'Comment' => array(), + 'Tag' => array() + ) + ); + } + +/** + * Test get() + * + * return void + */ + public function testGet() { + $data = self::articleData(); + + $result = Set2::get(array(), '1.Article.title'); + $this->assertNull($result); + + $result = Set2::get($data, ''); + $this->assertNull($result); + + $result = Set2::get($data, '1.Article.title'); + $this->assertEquals('Second Article', $result); + + $result = Set2::get($data, '5.Article.title'); + $this->assertNull($result); + + $result = Set2::get($data, '1.Article.title.not_there'); + $this->assertNull($result); + + $result = Set2::get($data, '1.Article'); + $this->assertEquals($data[1]['Article'], $result); + } +} diff --git a/lib/Cake/Utility/Set2.php b/lib/Cake/Utility/Set2.php new file mode 100644 index 000000000..1029732ce --- /dev/null +++ b/lib/Cake/Utility/Set2.php @@ -0,0 +1,56 @@ +