Browse Source

Add a test demonstrating current behavior

The association name is used to store the object in the table registry
AD7six 11 years ago
parent
commit
f9de012ca8
1 changed files with 37 additions and 0 deletions
  1. 37 0
      tests/TestCase/ORM/AssociationTest.php

+ 37 - 0
tests/TestCase/ORM/AssociationTest.php

@@ -14,6 +14,7 @@
  */
 namespace Cake\Test\TestCase\ORM;
 
+use Cake\Core\Plugin;
 use Cake\ORM\Association;
 use Cake\ORM\Table;
 use Cake\ORM\TableRegistry;
@@ -170,6 +171,42 @@ class AssociationTest extends TestCase
     }
 
     /**
+     * Tests that target() returns the correct Table object for plugins
+     *
+     * @return void
+     */
+    public function testTargetPlugin()
+    {
+        Plugin::load('TestPlugin');
+
+        $config = [
+            'className' => 'TestPlugin.Comments',
+            'foreignKey' => 'a_key',
+            'conditions' => ['field' => 'value'],
+            'dependent' => true,
+            'sourceTable' => $this->source,
+            'joinType' => 'INNER'
+        ];
+        $this->association = $this->getMock('\Cake\ORM\Association',
+            [
+                '_options', 'attachTo', '_joinCondition', 'cascadeDelete', 'isOwningSide',
+                'saveAssociated', 'eagerLoader', 'type'
+            ],
+            ['ThisAssociationName', $config]
+        );
+
+        $table = $this->association->target();
+        $this->assertInstanceOf('TestPlugin\Model\Table\CommentsTable', $table);
+
+        $this->assertFalse(TableRegistry::exists('TestPlugin.Comments'));
+        $this->assertFalse(TableRegistry::exists('Comments'));
+        $this->assertTrue(TableRegistry::exists('ThisAssociationName'));
+
+        $plugin = TableRegistry::get('ThisAssociationName');
+        $this->assertSame($table, $plugin, 'Should be the same TestPlugin.Comments object');
+    }
+
+    /**
      * Tests that source() returns the correct Table object
      *
      * @return void