Browse Source

Add coverage for no entity.

mark_story 12 years ago
parent
commit
2c8fa52d5c
2 changed files with 23 additions and 0 deletions
  1. 3 0
      src/View/Form/EntityContext.php
  2. 20 0
      tests/TestCase/View/Form/EntityContextTest.php

+ 3 - 0
src/View/Form/EntityContext.php

@@ -323,6 +323,9 @@ class EntityContext {
 	public function error($field) {
 		$parts = explode('.', $field);
 		list($entity, $prop) = $this->_getEntity($parts);
+		if (!$entity) {
+			return [];
+		}
 		return $entity->errors(array_pop($parts));
 	}
 

+ 20 - 0
tests/TestCase/View/Form/EntityContextTest.php

@@ -67,6 +67,26 @@ class EntityContextTest extends TestCase {
 	}
 
 /**
+ * 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