Skip to content
Permalink
Browse files

Added missing test for attachTo

  • Loading branch information...
lorenzo committed Jan 4, 2014
1 parent 17287a6 commit afa83e32236d718acf57158938308dbc6a479d9a
Showing with 37 additions and 0 deletions.
  1. +37 −0 Cake/Test/TestCase/ORM/Association/HasManyTest.php
@@ -457,6 +457,43 @@ public function testAttachToNoFields() {
$association->attachTo($query, ['includeFields' => false]);
}
/**
* Tests that by supplying a query builder function, it is possible to add fields
* and conditions to an association
*
* @return void
*/
public function testAttachToWithQueryBuilder() {
$query = $this->getMock('\Cake\ORM\Query', ['join', 'select'], [null, null]);
$config = [
'sourceTable' => $this->author,
'targetTable' => $this->article,
'conditions' => ['Articles.is_active' => true]
];
$field = new IdentifierExpression('Articles.author_id');
$association = new HasMany('Articles', $config);
$query->expects($this->once())->method('join')->with([
'Articles' => [
'conditions' => new QueryExpression([
'Articles.is_active' => true,
['Authors.id' => $field],
new QueryExpression(['a' => 1])
]),
'type' => 'INNER',
'table' => 'articles'
]
]);
$query->expects($this->once())->method('select')
->with([
'Articles__a' => 'Articles.a',
'Articles__b' => 'Articles.b'
]);
$builder = function($q) {
return $q->select(['a', 'b'])->where(['a' => 1]);
};
$association->attachTo($query, ['queryBuilder' => $builder]);
}
/**
* Test cascading deletes.
*

0 comments on commit afa83e3

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