Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0: Added support for NULL values in Set::format(). Added test case. #234

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/Cake/Test/Case/Utility/SetTest.php
Expand Up @@ -2263,6 +2263,26 @@ public function testFormatting() {
$this->assertEqual($expected, $result);
}

/**
* 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
2 changes: 1 addition & 1 deletion lib/Cake/Utility/Set.php
Expand Up @@ -298,7 +298,7 @@ public static 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