Skip to content

Commit

Permalink
Add coverage for no entity.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Feb 7, 2014
1 parent 4a6f598 commit 2c8fa52
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/View/Form/EntityContext.php
Expand Up @@ -323,6 +323,9 @@ public function hasError($field) {
public function error($field) {
$parts = explode('.', $field);
list($entity, $prop) = $this->_getEntity($parts);
if (!$entity) {
return [];
}
return $entity->errors(array_pop($parts));
}

Expand Down
20 changes: 20 additions & 0 deletions tests/TestCase/View/Form/EntityContextTest.php
Expand Up @@ -66,6 +66,26 @@ public function testInvalidTable() {
]);
}

/**
* Test operations with no entity.
*
* @return void
*/
public function testOperationsNoEntity() {
$context = new EntityContext($this->request, [
'table' => 'Articles'
]);

$this->assertNull($context->val('title'));
$this->assertFalse($context->isRequired('title'));
$this->assertFalse($context->hasError('title'));
$this->assertEquals('string', $context->type('title'));
$this->assertEquals([], $context->error('title'));
$this->assertEquals(
['length' => null, 'precision' => null],
$context->attributes('title'));
}

/**
* Test operations that lack a table argument.
*
Expand Down

0 comments on commit 2c8fa52

Please sign in to comment.