Permalink
Browse files

Merge branch 'issue-10250' into master

Refs #10250
  • Loading branch information...
markstory committed Jul 13, 2017
2 parents 3f6ca93 + c1851cb commit ee2ead47b4b5b25a520a91d0b50a039c193af7eb
Showing with 18 additions and 1 deletion.
  1. +1 −1 src/View/Form/EntityContext.php
  2. +17 −0 tests/TestCase/View/Form/EntityContextTest.php
@@ -263,7 +263,7 @@ public function val($field, $options = [])
if (is_array($entity) || $entity instanceof ArrayAccess) {
$key = array_pop($parts);
return isset($entity[$key]) ? $entity[$key] : null;
return isset($entity[$key]) ? $entity[$key] : $options['default'];
}
return null;
@@ -447,6 +447,23 @@ public function testValBasic()
$this->assertNull($result);
}
/**
* Test default values when entity is an array.
*
* @return void
*/
public function testValDefaultArray()
{
$context = new EntityContext($this->request, [
'entity' => new Article([
'prop' => ['title' => 'foo']
]),
'table' => 'Articles',
]);
$this->assertEquals('foo', $context->val('prop.title', ['default' => 'bar']));
$this->assertEquals('bar', $context->val('prop.nope', ['default' => 'bar']));
}
/**
* Test reading array values from an entity.
*

0 comments on commit ee2ead4

Please sign in to comment.