Skip to content
Permalink
Browse files

Update tests for #7707 to be more representative.

Having an integration test seems like a better idea. The old mock based
test was just ensuring the code was written, not that the behavior was
correct.
  • Loading branch information...
markstory committed Dec 5, 2015
1 parent 88af5c2 commit 8c2d4b2cda33e2b74dc3b283272619a332e9b418
Showing with 21 additions and 32 deletions.
  1. +0 −30 tests/TestCase/ORM/Association/BelongsToManyTest.php
  2. +21 −2 tests/TestCase/ORM/QueryRegressionTest.php
@@ -854,36 +854,6 @@ public function testReplaceLinkSuccess()
$this->assertFalse($entity->dirty('tags'));
}
/**
* Test that find() applies a contain() when the association uses conditions.
*
* @return void
*/
public function testFindAppliesContainWithConditions()
{
$connection = ConnectionManager::get('test');
$this->article->belongsToMany('Tags', [
'targetTable' => $this->tag,
'conditions' => ['ArticlesTags.favorite' => true]
]);
$query = $this->getMock(
'\Cake\ORM\Query',
[],
[$connection, $this->article]
);
$query->expects($this->once())
->method('where')
->with(['ArticlesTags.favorite' => true])
->will($this->returnSelf());
$query->expects($this->once())
->method('contain')
->with(['ArticlesTags'])
->will($this->returnSelf());
$this->tag->method('find')->will($this->returnValue($query));
$this->article->Tags->find();
}
/**
* Tests that replaceLinks() will contain() the target table when
* there are conditions present on the association.
@@ -101,6 +101,25 @@ public function testEagerLoadingBelongsToManyList()
$table->find()->contain('Tags')->toArray();
}
/**
* Test that association proxy find() applies joins when conditions are involved.
*
* @return void
*/
public function testBelongsToManyAssociationProxyFindWithConditions()
{
$table = TableRegistry::get('Articles');
$table->belongsToMany('Tags', [
'foreignKey' => 'article_id',
'associationForeignKey' => 'tag_id',
'conditions' => ['SpecialTags.highlighted' => true],
'through' => 'SpecialTags'
]);
$query = $table->Tags->find();
$result = $query->toArray();
$this->assertCount(1, $result);
}
/**
* Tests that duplicate aliases in contain() can be used, even when they would
* naturally be attached to the query instead of eagerly loaded. What should
@@ -221,11 +240,11 @@ public function testReciprocalBelongsToManyNoOverwrite()
$articles->belongsToMany('Tags');
$tags->belongsToMany('Articles');
$sub = $articles->Tags->find()->select(['id'])->matching('Articles', function ($q) {
$sub = $articles->Tags->find()->select(['Tags.id'])->matching('Articles', function ($q) {
return $q->where(['Articles.id' => 1]);
});
$query = $articles->Tags->find()->where(['id NOT IN' => $sub]);
$query = $articles->Tags->find()->where(['Tags.id NOT IN' => $sub]);
$this->assertEquals(1, $query->count());
}

0 comments on commit 8c2d4b2

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