Skip to content

Commit

Permalink
Add some more test coverage for association aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
AD7six committed Feb 16, 2015
1 parent 66a3e8e commit ce81f62
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
1 change: 0 additions & 1 deletion tests/TestCase/ORM/AssociationTest.php
Expand Up @@ -178,7 +178,6 @@ public function testTarget()
public function testTargetPlugin()
{
Plugin::load('TestPlugin');

$config = [
'className' => 'TestPlugin.Comments',
'foreignKey' => 'a_key',
Expand Down
43 changes: 43 additions & 0 deletions tests/TestCase/ORM/TableTest.php
Expand Up @@ -532,6 +532,49 @@ public function testHasOnePlugin()
$this->assertSame('TestPlugin.Comments', $hasOne->registryAlias());
}

/**
* testNoneUniqueAssociationsSameClass
*
* @return void
*/
public function testNoneUniqueAssociationsSameClass()
{
$Users = new Table(['table' => 'users']);
$options = ['className' => 'Comments'];
$Users->hasMany('Comments', $options);

$Articles = new Table(['table' => 'articles']);
$options = ['className' => 'Comments'];
$Articles->hasMany('Comments', $options);

$Categories = new Table(['table' => 'categories']);
$options = ['className' => 'TestPlugin.Comments'];
$Categories->hasMany('Comments', $options);

$this->assertInstanceOf('Cake\ORM\Table', $Users->Comments->target());
$this->assertInstanceOf('Cake\ORM\Table', $Articles->Comments->target());
$this->assertInstanceOf('TestPlugin\Model\Table\CommentsTable', $Categories->Comments->target());
}

/**
* testMultipleAssociationsSameClass
*
* @return void
*/
public function testMultipleAssociationsSameClass()
{
$Comments = new Table(['table' => 'comments']);
$options = ['className' => 'Comments'];
$Comments->hasMany('Children', $options);
$Comments->belongsTo('Parent', $options);

$this->assertSame('Children', $Comments->Children->alias());
$this->assertSame('Children', $Comments->Children->target()->alias());

$this->assertSame('Parent', $Comments->Parent->alias());
$this->assertSame('Parent', $Comments->Parent->target()->alias());
}

/**
* Tests that hasMany() creates and configures correctly the association
*
Expand Down

0 comments on commit ce81f62

Please sign in to comment.