Browse Source

Merge branch '1.3' into 1.3-merge

Conflicts:
	cake/console/cake.php
	cake/console/libs/shell.php
	cake/tests/cases/console/libs/shell.test.php
mark_story 14 years ago
parent
commit
788d38ccef

+ 3 - 5
lib/Cake/Console/Shell.php

@@ -448,13 +448,11 @@ class Shell extends Object {
 			}
 		}
 		if (is_array($options)) {
-			while ($in == '' || ($in && (!in_array(strtolower($in), $options) && !in_array(strtoupper($in), $options)) && !in_array($in, $options))) {
+			while ($in === '' || ($in !== '' && (!in_array(strtolower($in), $options) && !in_array(strtoupper($in), $options)) && !in_array($in, $options))) {
 				$in = $this->_getInput($prompt, $options, $default);
 			}
 		}
-		if ($in) {
-			return $in;
-		}
+		return $in;
 	}
 
 /**
@@ -484,7 +482,7 @@ class Shell extends Object {
 		}
 		$result = trim($result);
 
-		if ($default != null && empty($result)) {
+		if ($default !== null && ($result === '' || $result === null)) {
 			return $default;
 		}
 		return $result;

+ 20 - 6
lib/Cake/Test/Case/Console/Command/ShellTest.php

@@ -214,6 +214,10 @@ class ShellTest extends CakeTestCase {
 			->method('read')
 			->will($this->returnValue('y'));
 
+		$this->Shell->stdin->expects($this->at(5))
+			->method('read')
+			->will($this->returnValue('0'));
+
 		$result = $this->Shell->in('Just a test?', array('y', 'n'), 'n');
 		$this->assertEqual($result, 'n');
 
@@ -229,6 +233,16 @@ class ShellTest extends CakeTestCase {
 		$result = $this->Shell->in('Just a test?', 'y', 'y');
 		$this->assertEqual($result, 'y');
 
+		$result = $this->Shell->in('Just a test?', array(0, 1, 2), '0');
+		$this->assertEqual($result, '0');
+	}
+
+/**
+ * Test in() when not interactive.
+ *
+ * @return void
+ */
+	public function testInNonInteractive() {
 		$this->Shell->interactive = false;
 
 		$result = $this->Shell->in('Just a test?', 'y/n', 'n');
@@ -517,13 +531,13 @@ class ShellTest extends CakeTestCase {
 
 		$this->Shell->interactive = false;
 
-		$contents = "<?php\necho 'test';\n\$te = 'st';\n?>";
+		$contents = "<?php\necho 'test';\n\$te = 'st';\n";
 		$result = $this->Shell->createFile($file, $contents);
 		$this->assertTrue($result);
 		$this->assertTrue(file_exists($file));
 		$this->assertEqual(file_get_contents($file), $contents);
 
-		$contents = "<?php\necho 'another test';\n\$te = 'st';\n?>";
+		$contents = "<?php\necho 'another test';\n\$te = 'st';\n";
 		$result = $this->Shell->createFile($file, $contents);
 		$this->assertTrue($result);
 		$this->assertTrue(file_exists($file));
@@ -555,7 +569,7 @@ class ShellTest extends CakeTestCase {
 			->will($this->returnValue('y'));
 
 
-		$contents = "<?php\necho 'yet another test';\n\$te = 'st';\n?>";
+		$contents = "<?php\necho 'yet another test';\n\$te = 'st';\n";
 		$result = $this->Shell->createFile($file, $contents);
 		$this->assertTrue($result);
 		$this->assertTrue(file_exists($file));
@@ -593,13 +607,13 @@ class ShellTest extends CakeTestCase {
 
 		$this->Shell->interactive = false;
 
-		$contents = "<?php\r\necho 'test';\r\n\$te = 'st';\r\n?>";
+		$contents = "<?php\r\necho 'test';\r\n\$te = 'st';\r\n";
 		$result = $this->Shell->createFile($file, $contents);
 		$this->assertTrue($result);
 		$this->assertTrue(file_exists($file));
 		$this->assertEqual(file_get_contents($file), $contents);
 
-		$contents = "<?php\r\necho 'another test';\r\n\$te = 'st';\r\n?>";
+		$contents = "<?php\r\necho 'another test';\r\n\$te = 'st';\r\n";
 		$result = $this->Shell->createFile($file, $contents);
 		$this->assertTrue($result);
 		$this->assertTrue(file_exists($file));
@@ -631,7 +645,7 @@ class ShellTest extends CakeTestCase {
 			->will($this->returnValue('y'));
 
 
-		$contents = "<?php\r\necho 'yet another test';\r\n\$te = 'st';\r\n?>";
+		$contents = "<?php\r\necho 'yet another test';\r\n\$te = 'st';\r\n";
 		$result = $this->Shell->createFile($file, $contents);
 		$this->assertTrue($result);
 		$this->assertTrue(file_exists($file));

+ 20 - 0
lib/Cake/Test/Case/Utility/SetTest.php

@@ -2264,6 +2264,26 @@ class SetTest extends CakeTestCase {
 	}
 
 /**
+ * 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

+ 1 - 1
lib/Cake/Utility/Set.php

@@ -298,7 +298,7 @@ class Set {
 			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];
 					}
 				}