diff --git a/tests/TestCase/ORM/TableTest.php b/tests/TestCase/ORM/TableTest.php index a6079bed4df..fc9e0b73b15 100644 --- a/tests/TestCase/ORM/TableTest.php +++ b/tests/TestCase/ORM/TableTest.php @@ -16,6 +16,7 @@ use ArrayObject; use Cake\Core\Configure; +use Cake\Core\Plugin; use Cake\Database\Expression\OrderByExpression; use Cake\Database\Expression\QueryExpression; use Cake\Database\TypeMap; @@ -519,6 +520,28 @@ public function testHasMany() $this->assertSame($table, $hasMany->source()); } + /** + * Should a dupicate short-named association be defined, the earlier + * association will be inaccessible via the __get method + * + * @return void + */ + public function testHasManyPluginOverlap() + { + TableRegistry::get('Comments'); + Plugin::load('TestPlugin'); + + $table = new Table(['table' => 'authors']); + + $table->hasOne('Comments'); + $comments = $table->Comments->target(); + $this->assertInstanceOf('Cake\ORM\Table', $comments); + + $table->hasMany('TestPlugin.Comments'); + $comments = $table->Comments->target(); + $this->assertInstanceOf('TestPlugin\Model\Table\CommentsTable', $comments); + } + /** * Tests that BelongsToMany() creates and configures correctly the association *