Browse Source

Cleanup

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.
ndm2 9 years ago
parent
commit
371ca3a515
2 changed files with 9 additions and 10 deletions
  1. 5 4
      src/View/Form/EntityContext.php
  2. 4 6
      tests/TestCase/View/Form/EntityContextTest.php

+ 5 - 4
src/View/Form/EntityContext.php

@@ -477,10 +477,11 @@ class EntityContext implements ContextInterface
      * 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];
@@ -512,10 +513,10 @@ class EntityContext implements ContextInterface
                 $assoc = $table->associations()->getByProperty($part);
             }
 
-            if (!$assoc && $rootFallback) {
+            if (!$assoc && $fallback) {
                 break;
             }
-            if (!$assoc && !$rootFallback) {
+            if (!$assoc && !$fallback) {
                 return false;
             }
 

+ 4 - 6
tests/TestCase/View/Form/EntityContextTest.php

@@ -942,10 +942,6 @@ class EntityContextTest extends TestCase
         $context = new EntityContext($this->request, [
             'entity' => $row,
             'table' => 'Articles',
-            'validator' => [
-                'Articles' => 'create',
-                'Users' => 'custom',
-            ]
         ]);
 
         $this->assertTrue($context->isRequired('tags.0._joinData.article_id'));
@@ -1026,9 +1022,11 @@ class EntityContextTest extends TestCase
         $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'));
     }
 
     /**
@@ -1254,7 +1252,7 @@ class EntityContextTest extends TestCase
             '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']]]