Permalink
Browse files

Add coverage for no entity.

  • Loading branch information...
1 parent 4a6f598 commit 2c8fa52d5c35c177350bb889cc05f20cbb6dcfea @markstory markstory committed Feb 7, 2014
Showing with 23 additions and 0 deletions.
  1. +3 −0 src/View/Form/EntityContext.php
  2. +20 −0 tests/TestCase/View/Form/EntityContextTest.php
@@ -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));
}
@@ -67,6 +67,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.
*
* @return void

0 comments on commit 2c8fa52

Please sign in to comment.