Skip to content

Commit

Permalink
Move test cases into the correct class.
Browse files Browse the repository at this point in the history
These tests started off in the regression case as the belongs to many
tests didn't support fixtures. That is no longer the case anymore.

Refs #7994
  • Loading branch information
markstory committed Jan 10, 2016
1 parent 8902ed0 commit 47b9940
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 62 deletions.
62 changes: 62 additions & 0 deletions tests/TestCase/ORM/Association/BelongsToManyTest.php
Expand Up @@ -980,4 +980,66 @@ public function testEagerLoadingBelongsToManyLimitedFields()
$this->assertNotEmpty($result->tags[0]->id);
$this->assertEmpty($result->tags[0]->name);
}

/**
* Test that association proxy find() applies joins when conditions are involved.
*
* @return void
*/
public function testAssociationProxyFindWithConditions()
{
$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);
}

/**
* Test that matching() works on belongsToMany associations.
*
* @return void
*/
public function testBelongsToManyAssociationWithConditions()
{
$table = TableRegistry::get('Articles');
$table->belongsToMany('Tags', [
'foreignKey' => 'article_id',
'associationForeignKey' => 'tag_id',
'conditions' => ['SpecialTags.highlighted' => true],
'through' => 'SpecialTags'
]);
$query = $table->find()->matching('Tags', function ($q) {
return $q->where(['Tags.name' => 'tag1']);
});
$results = $query->toArray();
$this->assertCount(1, $results);
$this->assertNotEmpty($results[0]->_matchingData);
}

/**
* Test that association proxy find() with matching resolves joins correctly
*
* @return void
*/
public function testAssociationProxyFindWithConditionsMatching()
{
$table = TableRegistry::get('Articles');
$table->belongsToMany('Tags', [
'foreignKey' => 'article_id',
'associationForeignKey' => 'tag_id',
'conditions' => ['SpecialTags.highlighted' => true],
'through' => 'SpecialTags'
]);
$query = $table->Tags->find()->matching('Articles', function ($query) {
return $query->where(['Articles.id' => 1]);
});
// The inner join on special_tags excludes the results.
$this->assertEquals(0, $query->count());
}
}
62 changes: 0 additions & 62 deletions tests/TestCase/ORM/QueryRegressionTest.php
Expand Up @@ -101,68 +101,6 @@ 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);
}

/**
* Test that matching() works on belongsToMany associations.
*
* @return void
*/
public function testMatchingOnBelongsToManyAssociationWithConditions()
{
$table = TableRegistry::get('Articles');
$table->belongsToMany('Tags', [
'foreignKey' => 'article_id',
'associationForeignKey' => 'tag_id',
'conditions' => ['SpecialTags.highlighted' => true],
'through' => 'SpecialTags'
]);
$query = $table->find()->matching('Tags', function ($q) {
return $q->where(['Tags.name' => 'tag1']);
});
$results = $query->toArray();
$this->assertCount(1, $results);
$this->assertNotEmpty($results[0]->_matchingData);
}

/**
* Test that association proxy find() with matching resolves joins correctly
*
* @return void
*/
public function testBelongsToManyAssociationProxyFindWithConditionsMatching()
{
$table = TableRegistry::get('Articles');
$table->belongsToMany('Tags', [
'foreignKey' => 'article_id',
'associationForeignKey' => 'tag_id',
'conditions' => ['SpecialTags.highlighted' => true],
'through' => 'SpecialTags'
]);
$query = $table->Tags->find()->matching('Articles', function ($query) {
return $query->where(['Articles.id' => 1]);
});
// The inner join on special_tags excludes the results.
$this->assertEquals(0, $query->count());
}

/**
* 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
Expand Down

0 comments on commit 47b9940

Please sign in to comment.