Permalink
Browse files

Add tests for issue #104

  • Loading branch information...
1 parent ff5e72c commit 8cadac3ee551336e273984edd3e32317efb8898e @markstory markstory committed Feb 22, 2012
Showing with 47 additions and 0 deletions.
  1. +39 −0 lib/Cake/Test/Case/Utility/Set2Test.php
  2. +8 −0 lib/Cake/Utility/Set2.php
@@ -834,6 +834,45 @@ public function testExtractAttributePattern() {
}
/**
+ * Test that uneven keys are handled correctly.
+ *
+ * @return void
+ */
+ public function testExtractUnevenKeys() {
+ $data = array(
+ 'Level1' => array(
+ 'Level2' => array('test1', 'test2'),
+ 'Level2bis' => array('test3', 'test4')
+ )
+ );
+ $this->assertEquals(
+ array('test1', 'test2'),
+ Set2::extract($data, 'Level1.Level2')
+ );
+ $this->assertEquals(
+ array('test3', 'test4'),
+ Set2::extract($data, 'Level1.Level2bis')
+ );
+
+ $data = array(
+ 'Level1' => array(
+ 'Level2bis' => array(
+ array('test3', 'test4'),
+ array('test5', 'test6')
+ )
+ )
+ );
+ $expected = array(
+ array('test3', 'test4'),
+ array('test5', 'test6')
+ );
+ $this->assertEquals($expected, Set2::extract($data, 'Level1.Level2bis'));
+
+ $data['Level1']['Level2'] = array('test1', 'test2');
+ $this->assertEquals($expected, Set2::extract($data, 'Level1.Level2bis'));
+ }
+
+/**
* testSort method
*
* @return void
@@ -376,6 +376,14 @@ public static function combine(array $data, $keyPath, $valuePath = null, $groupP
/**
* Returns a formated series of values extracted from `$data`, using
* `$format` as the format and `$paths` as the values to extract.
+ *
+ * Usage:
+ *
+ * {{{
+ * $result = Set::format($users, array('{n}.User.id', '{n}.User.name'), '%s : %s');
+ * }}}
+ *
+ * The `$format` string can use any format options that `vsprintf()` and `sprintf()` do.
*
* @param array $data Source array from which to extract the data
* @param string $paths An array containing one or more Set2::extract()-style key paths

0 comments on commit 8cadac3

Please sign in to comment.