Browse Source

Added test for extracting custom primary keys in EntityContext

Jose Lorenzo Rodriguez 12 years ago
parent
commit
1c513eb6b2
1 changed files with 30 additions and 1 deletions
  1. 30 1
      tests/TestCase/View/Form/EntityContextTest.php

+ 30 - 1
tests/TestCase/View/Form/EntityContextTest.php

@@ -449,7 +449,7 @@ class EntityContextTest extends TestCase {
  *
  * @return void
  */
-	public function testValAssociatedIds() {
+	public function testValAssociatedDefaultIds() {
 		$row = new Entity([
 			'title' => 'First post',
 			'user' => new Entity([
@@ -471,6 +471,35 @@ class EntityContextTest extends TestCase {
 	}
 
 /**
+ * Test reading values for magic _ids input
+ *
+ * @return void
+ */
+	public function testValAssociatedCustomIds() {
+		$row = new Entity([
+			'title' => 'First post',
+			'user' => new Entity([
+				'username' => 'mark',
+				'fname' => 'Mark',
+				'groups' => [
+					new Entity(['title' => 'PHP', 'thing' => 1]),
+					new Entity(['title' => 'Javascript', 'thing' => 4]),
+				]
+			]),
+		]);
+		$context = new EntityContext($this->request, [
+			'entity' => $row,
+			'table' => 'Articles',
+		]);
+
+		TableRegistry::get('Users')->belongsToMany('Groups');
+		TableRegistry::get('Groups')->primaryKey('thing');
+
+		$result = $context->val('user.groups._ids');
+		$this->assertEquals([1, 4], $result);
+	}
+
+/**
  * Test validator as a string.
  *
  * @return void