mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Add tests for issue #104
This commit is contained in:
parent
ff5e72c9a7
commit
8cadac3ee5
2 changed files with 47 additions and 0 deletions
|
@ -833,6 +833,45 @@ class Set2Test extends CakeTestCase {
|
|||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
|
|
|
@ -376,6 +376,14 @@ class Set2 {
|
|||
/**
|
||||
* 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
|
||||
|
|
Loading…
Add table
Reference in a new issue