Skip to content
Permalink
Browse files

Expand tests and remove unreachable code.

  • Loading branch information...
markstory committed Feb 7, 2014
1 parent bbbd505 commit 4a6f5982259f64d716fbb0a8a9b0b7bb24c87572
Showing with 21 additions and 21 deletions.
  1. +5 −21 src/View/Form/EntityContext.php
  2. +16 −0 tests/TestCase/View/Form/EntityContextTest.php
@@ -150,9 +150,6 @@ public function val($field) {
}
$parts = explode('.', $field);
list($entity, $prop) = $this->_getEntity($parts);
if (!$entity) {
return null;
}
return $entity->get(array_pop($parts));
}
@@ -187,7 +184,10 @@ protected function _getEntity($path) {
}
$entity = $next;
}
return [false, false];
throw \RuntimeException(sprintf(
'Unable to fetch property "%s"',
implode(".", $path)
));
}
/**
@@ -220,15 +220,8 @@ public function isRequired($field) {
}
$parts = explode('.', $field);
list($entity, $prop) = $this->_getEntity($parts);
if (!$entity) {
return false;
}
$validator = $this->_getValidator($prop);
if (!$validator) {
return false;
}
$field = array_pop($parts);
if (!$validator->hasField($field)) {
return false;
@@ -242,7 +235,7 @@ public function isRequired($field) {
* conventions.
*
* @param string $entity The entity name to get a validator for.
* @return Validator|false
* @return Validator
*/
protected function _getValidator($entity) {
$table = $this->_getTable($entity);
@@ -291,9 +284,6 @@ protected function _getTable($prop) {
public function type($field) {
$parts = explode('.', $field);
list($entity, $prop) = $this->_getEntity($parts);
if (!$entity) {
return null;
}
$table = $this->_getTable($prop);
$column = array_pop($parts);
return $table->schema()->columnType($column);
@@ -308,9 +298,6 @@ public function type($field) {
public function attributes($field) {
$parts = explode('.', $field);
list($entity, $prop) = $this->_getEntity($parts);
if (!$entity) {
return [];
}
$table = $this->_getTable($prop);
$column = $table->schema()->column(array_pop($parts));
$whitelist = ['length' => null, 'precision' => null];
@@ -336,9 +323,6 @@ 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));
}
@@ -53,6 +53,19 @@ public function setUp() {
$this->request = new Request();
}
/**
* Test an invalid table scope throws an error.
*
* @expectedException \RuntimeException
* @expectedExceptionMessage Unable to find table class for current entity
*/
public function testInvalidTable() {
$row = new \StdClass();
$context = new EntityContext($this->request, [
'entity' => $row,
]);
}
/**
* Test operations that lack a table argument.
*
@@ -295,6 +308,7 @@ public function testIsRequiredStringValidator() {
$this->assertFalse($context->isRequired('Herp.derp.derp'));
$this->assertFalse($context->isRequired('nope'));
$this->assertFalse($context->isRequired(''));
}
/**
@@ -326,6 +340,8 @@ public function testIsRequiredAssociatedHasMany() {
$this->assertTrue($context->isRequired('comments.0.user_id'));
$this->assertFalse($context->isRequired('comments.0.other'));
$this->assertFalse($context->isRequired('user.0.other'));
$this->assertFalse($context->isRequired(''));
}
/**

0 comments on commit 4a6f598

Please sign in to comment.
You can’t perform that action at this time.