Browse Source

Add test for Model::getID(), simplify return and remove dated @see link

Kyle Robinson Young 14 years ago
parent
commit
060e225b76
2 changed files with 25 additions and 6 deletions
  1. 1 5
      lib/Cake/Model/Model.php
  2. 24 1
      lib/Cake/Test/Case/Model/ModelIntegrationTest.php

+ 1 - 5
lib/Cake/Model/Model.php

@@ -3164,11 +3164,7 @@ class Model extends Object {
 			return false;
 		}
 
-		foreach ($this->id as $id) {
-			return $id;
-		}
-
-		return false;
+		return current($this->id);
 	}
 
 /**

+ 24 - 1
lib/Cake/Test/Case/Model/ModelIntegrationTest.php

@@ -2022,7 +2022,6 @@ class ModelIntegrationTest extends BaseModelTest {
 
 /**
  * testEscapeField to prove it escapes the field well even when it has part of the alias on it
- * @see ttp://cakephp.lighthouseapp.com/projects/42648-cakephp-1x/tickets/473-escapefield-doesnt-consistently-prepend-modelname
  *
  * @return void
  */
@@ -2053,6 +2052,30 @@ class ModelIntegrationTest extends BaseModelTest {
 	}
 
 /**
+ * testGetID
+ *
+ * @return void
+ */
+	public function testGetID() {
+		$TestModel = new Test();
+
+		$result = $TestModel->getID();
+		$this->assertFalse($result);
+
+		$TestModel->id = 9;
+		$result = $TestModel->getID();
+		$this->assertEquals(9, $result);
+
+		$TestModel->id = array(10, 9, 8, 7);
+		$result = $TestModel->getID(2);
+		$this->assertEquals(8, $result);
+
+		$TestModel->id = array(array(), 1, 2, 3);
+		$result = $TestModel->getID();
+		$this->assertFalse($result);
+	}
+
+/**
  * test that model->hasMethod checks self and behaviors.
  *
  * @return void