Skip to content
This repository
Browse code

Add support for NULL values in Set::format().

Add test case.
Fixes #2076.
  • Loading branch information...
commit e894ab2dd27d8a742f4489450414d8aef825e2ec 1 parent d823710
Thomas Ploch authored October 07, 2011 markstory committed October 07, 2011
2  cake/libs/set.php
@@ -329,7 +329,7 @@ function format($data, $format, $keys) {
329 329
 			for ($j = 0; $j < $count; $j++) {
330 330
 				$args = array();
331 331
 				for ($i = 0; $i < $count2; $i++) {
332  
-					if (isset($data[$i][$j])) {
  332
+					if (array_key_exists($j, $data[$i])) {
333 333
 						$args[] = $data[$i][$j];
334 334
 					}
335 335
 				}
20  cake/tests/cases/libs/set.test.php
@@ -2161,6 +2161,26 @@ function testFormatting() {
2161 2161
 		$this->assertEqual($result, $expected);
2162 2162
 	}
2163 2163
 /**
  2164
+ * testFormattingNullValues method
  2165
+ *
  2166
+ * @return void
  2167
+ */
  2168
+	public function testFormattingNullValues() {
  2169
+		$data = array(
  2170
+			array('Person' => array('first_name' => 'Nate', 'last_name' => 'Abele', 'city' => 'Boston', 'state' => 'MA', 'something' => '42')),
  2171
+			array('Person' => array('first_name' => 'Larry', 'last_name' => 'Masters', 'city' => 'Boondock', 'state' => 'TN', 'something' => null)),
  2172
+			array('Person' => array('first_name' => 'Garrett', 'last_name' => 'Woodworth', 'city' => 'Venice Beach', 'state' => 'CA', 'something' => null)));
  2173
+
  2174
+		$result = Set::format($data, '%s', array('{n}.Person.something'));
  2175
+		$expected = array('42', '', '');
  2176
+		$this->assertEqual($expected, $result);
  2177
+
  2178
+		$result = Set::format($data, '{0}, {1}', array('{n}.Person.city', '{n}.Person.something'));
  2179
+		$expected = array('Boston, 42', 'Boondock, ', 'Venice Beach, ');
  2180
+		$this->assertEqual($expected, $result);
  2181
+	}
  2182
+
  2183
+/**
2164 2184
  * testCountDim method
2165 2185
  *
2166 2186
  * @access public

0 notes on commit e894ab2

Please sign in to comment.
Something went wrong with that request. Please try again.