Skip to content
Permalink
Browse files

Unit test for attachTo and matching

  • Loading branch information...
lorenzo committed Feb 9, 2014
1 parent 3cd5aec commit 9e6aa7ed5cd15062363e05d1c8f1e070c6cb8316
Showing with 33 additions and 0 deletions.
  1. +33 −0 tests/TestCase/ORM/Association/BelongsToTest.php
@@ -210,6 +210,39 @@ public function testAttachToWithQueryBuilder() {
$association->attachTo($query, ['queryBuilder' => $builder]);
}
/**
* Tests that by passing the matching option to `attachTo` the association
* is joinned using `INNER`
*
* @return void
*/
public function testAttachToMAtching() {
$query = $this->getMock('\Cake\ORM\Query', ['join', 'select'], [null, null]);
$config = [
'foreignKey' => 'company_id',
'sourceTable' => $this->client,
'targetTable' => $this->company,
'conditions' => ['Companies.is_active' => true]
];
$association = new BelongsTo('Companies', $config);
$field = new IdentifierExpression('Clients.company_id');
$query->expects($this->once())->method('join')->with([
'Companies' => [
'conditions' => new QueryExpression([
'Companies.is_active' => true,
['Companies.id' => $field]
]),
'table' => 'companies',
'type' => 'INNER'
]
]);
$query->expects($this->once())->method('select')->with([
'Companies__id' => 'Companies.id',
'Companies__company_name' => 'Companies.company_name'
]);
$association->attachTo($query, ['matching' => true]);
}
/**
* Test the cascading delete of BelongsTo.
*

0 comments on commit 9e6aa7e

Please sign in to comment.
You can’t perform that action at this time.