Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Closed
wants to merge 2 commits into from

2 participants

@tPl0ch

Added support for NULL values in Set::format(). Added test case. Fixes #2076 .

http://cakephp.lighthouseapp.com/projects/42648/tickets/2076-setcombine-cant-handle-null-values

@markstory
Owner

Thanks for doing the patches for 1.3. There usually isn't a need to redo these kind of changes for 2.0. The changes come across in the merge between 1.3 and 2.0. I'm going to close this pull request as the merge looks like it will be clean. Thanks again :)

@markstory markstory closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
20 lib/Cake/Test/Case/Utility/SetTest.php
@@ -2264,6 +2264,26 @@ public function testFormatting() {
}
/**
+ * 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
*
* @return void
View
2  lib/Cake/Utility/Set.php
@@ -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];
}
}
Something went wrong with that request. Please try again.