浏览代码

Add coverage for no entity.

mark_story 12 年之前
父节点
当前提交
2c8fa52d5c
共有 2 个文件被更改,包括 23 次插入0 次删除
  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) {
 	public function error($field) {
 		$parts = explode('.', $field);
 		$parts = explode('.', $field);
 		list($entity, $prop) = $this->_getEntity($parts);
 		list($entity, $prop) = $this->_getEntity($parts);
+		if (!$entity) {
+			return [];
+		}
 		return $entity->errors(array_pop($parts));
 		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.
  * Test operations that lack a table argument.
  *
  *
  * @return void
  * @return void