Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add support for NULL values in Set::format().
Add test case.
Fixes #2076.
  • Loading branch information
Thomas Ploch authored and markstory committed Oct 8, 2011
1 parent d823710 commit e894ab2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cake/libs/set.php
Expand Up @@ -329,7 +329,7 @@ function format($data, $format, $keys) {
for ($j = 0; $j < $count; $j++) {
$args = array();
for ($i = 0; $i < $count2; $i++) {
if (isset($data[$i][$j])) {
if (array_key_exists($j, $data[$i])) {
$args[] = $data[$i][$j];
}
}
Expand Down
20 changes: 20 additions & 0 deletions cake/tests/cases/libs/set.test.php
Expand Up @@ -2160,6 +2160,26 @@ function testFormatting() {
$expected = array('Nate, 42', 'Larry, 0', 'Garrett, 0');
$this->assertEqual($result, $expected);
}
/**
* testFormattingNullValues method
*
* @return void
*/
public function testFormattingNullValues() {
$data = array(
array('Person' => array('first_name' => 'Nate', 'last_name' => 'Abele', 'city' => 'Boston', 'state' => 'MA', 'something' => '42')),
array('Person' => array('first_name' => 'Larry', 'last_name' => 'Masters', 'city' => 'Boondock', 'state' => 'TN', 'something' => null)),
array('Person' => array('first_name' => 'Garrett', 'last_name' => 'Woodworth', 'city' => 'Venice Beach', 'state' => 'CA', 'something' => null)));

$result = Set::format($data, '%s', array('{n}.Person.something'));
$expected = array('42', '', '');
$this->assertEqual($expected, $result);

$result = Set::format($data, '{0}, {1}', array('{n}.Person.city', '{n}.Person.something'));
$expected = array('Boston, 42', 'Boondock, ', 'Venice Beach, ');
$this->assertEqual($expected, $result);
}

/**
* testCountDim method
*
Expand Down

0 comments on commit e894ab2

Please sign in to comment.