Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
Remove copy pasta, make use of existing variable, update fallback
argument name and description, and additional assertions to make sure
the non-`_joinData` fallback case is properly covered.
  • Loading branch information
ndm2 committed Feb 17, 2017
1 parent 34e356c commit 371ca3a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
9 changes: 5 additions & 4 deletions src/View/Form/EntityContext.php
Expand Up @@ -477,10 +477,11 @@ protected function _getValidator($parts)
* Get the table instance from a property path
*
* @param array $parts Each one of the parts in a path for a field name
* @param bool $rootFallback Whether or not to fallback to the root entity.
* @param bool $fallback Whether or not to fallback to the last found table
* when a non-existent field/property is being encountered.
* @return \Cake\ORM\Table|bool Table instance or false
*/
protected function _getTable($parts, $rootFallback = true)
protected function _getTable($parts, $fallback = true)
{
if (count($parts) === 1) {
return $this->_tables[$this->_rootName];
Expand Down Expand Up @@ -512,10 +513,10 @@ protected function _getTable($parts, $rootFallback = true)
$assoc = $table->associations()->getByProperty($part);
}

if (!$assoc && $rootFallback) {
if (!$assoc && $fallback) {
break;
}
if (!$assoc && !$rootFallback) {
if (!$assoc && !$fallback) {
return false;
}

Expand Down
10 changes: 4 additions & 6 deletions tests/TestCase/View/Form/EntityContextTest.php
Expand Up @@ -942,10 +942,6 @@ public function testIsRequiredAssociatedJoinTable()
$context = new EntityContext($this->request, [
'entity' => $row,
'table' => 'Articles',
'validator' => [
'Articles' => 'create',
'Users' => 'custom',
]
]);

$this->assertTrue($context->isRequired('tags.0._joinData.article_id'));
Expand Down Expand Up @@ -1026,9 +1022,11 @@ public function testTypeAssociatedJoinData()
$this->assertEquals('integer', $context->type('tags.0._joinData.article_id'));
$this->assertNull($context->type('tags.0._joinData.non_existent'));

// tests the root fallback behavior
// tests the fallback behavior
$this->assertEquals('integer', $context->type('tags.0._joinData._joinData.article_id'));
$this->assertEquals('integer', $context->type('tags.0._joinData.non_existent.article_id'));
$this->assertNull($context->type('tags.0._joinData._joinData.non_existent'));
$this->assertNull($context->type('tags.0._joinData.non_existent'));
}

/**
Expand Down Expand Up @@ -1254,7 +1252,7 @@ protected function _setupTables()
'body' => ['type' => 'crazy_text', 'baseType' => 'text'],
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]],
]);
$articles->Tags->junction()->schema([
$articlesTags->schema([
'article_id' => ['type' => 'integer', 'length' => 11, 'null' => false],
'tag_id' => ['type' => 'integer', 'length' => 11, 'null' => false],
'_constraints' => ['unique_tag' => ['type' => 'primary', 'columns' => ['article_id', 'tag_id']]]
Expand Down

0 comments on commit 371ca3a

Please sign in to comment.