Skip to content
Permalink
Browse files

Added test for extracting custom primary keys in EntityContext

  • Loading branch information...
lorenzo committed Mar 1, 2014
1 parent 305958c commit 1c513eb6b2fa5c4293c576bf9e6b40a667b7042d
Showing with 30 additions and 1 deletion.
  1. +30 −1 tests/TestCase/View/Form/EntityContextTest.php
@@ -449,7 +449,7 @@ public function testValAssociatedHasMany() {
*
* @return void
*/
public function testValAssociatedIds() {
public function testValAssociatedDefaultIds() {
$row = new Entity([
'title' => 'First post',
'user' => new Entity([
@@ -470,6 +470,35 @@ public function testValAssociatedIds() {
$this->assertEquals([1, 2], $result);
}
/**
* 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.
*

0 comments on commit 1c513eb

Please sign in to comment.
You can’t perform that action at this time.