Browse files

Unit test for attachTo and matching

  • Loading branch information...
1 parent 3cd5aec commit 9e6aa7ed5cd15062363e05d1c8f1e070c6cb8316 @lorenzo lorenzo committed Feb 9, 2014
Showing with 33 additions and 0 deletions.
  1. +33 −0 tests/TestCase/ORM/Association/BelongsToTest.php
View
33 tests/TestCase/ORM/Association/BelongsToTest.php
@@ -211,6 +211,39 @@ public function testAttachToWithQueryBuilder() {
}
/**
+ * 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.
*
* @return void

0 comments on commit 9e6aa7e

Please sign in to comment.