mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Improving tests for model associations lazy loading
This commit is contained in:
parent
c1a9a2e263
commit
0ec30be076
1 changed files with 52 additions and 1 deletions
|
@ -57,7 +57,7 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
* @return void
|
||||
*/
|
||||
public function testAssociationLazyLoading() {
|
||||
$this->loadFixtures('ArticleFeatured', 'User', 'Category', 'Comment');
|
||||
$this->loadFixtures('ArticleFeatured', 'User', 'Category', 'Comment', 'ArticleFeaturedsTags');
|
||||
$Article = new ArticleFeatured();
|
||||
$this->assertTrue(isset($Article->belongsTo['User']));
|
||||
$this->assertFalse(property_exists($Article, 'User'));
|
||||
|
@ -79,6 +79,57 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
$this->assertTrue(property_exists($Article, 'Tag'));
|
||||
$this->assertTrue(isset($Article->Tag));
|
||||
$this->assertType('Tag', $Article->Tag);
|
||||
$this->assertTrue(property_exists($Article, 'ArticleFeaturedsTag'));
|
||||
$this->assertType('AppModel', $Article->ArticleFeaturedsTag);
|
||||
$this->assertEquals($Article->hasAndBelongsToMany['Tag']['joinTable'], 'article_featureds_tags');
|
||||
$this->assertEquals($Article->hasAndBelongsToMany['Tag']['associationForeignKey'], 'tag_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* testAssociationLazyLoadWithHABTM
|
||||
*
|
||||
* @group lazyloading
|
||||
* @return void
|
||||
*/
|
||||
public function testAssociationLazyLoadWithHABTM() {
|
||||
$this->loadFixtures('Article', 'UuidTag', 'Fruit', 'FruitsUuidTag');
|
||||
$Article = new ArticleB();
|
||||
$this->assertTrue(isset($Article->hasAndBelongsToMany['TagB']));
|
||||
$this->assertFalse(property_exists($Article, 'TagB'));
|
||||
$this->assertType('TagB', $Article->TagB);
|
||||
|
||||
//Dynamic "with" models are not lazy loaded
|
||||
$this->assertTrue(property_exists($Article, 'ArticlesTag'));
|
||||
$this->assertType('AppModel', $Article->ArticlesTag);
|
||||
|
||||
$UuidTag = new UuidTag();
|
||||
$this->assertTrue(isset($UuidTag->hasAndBelongsToMany['Fruit']));
|
||||
$this->assertFalse(property_exists($UuidTag, 'Fruit'));
|
||||
$this->assertFalse(property_exists($UuidTag, 'FruitsUuidTag'));
|
||||
$this->assertTrue(isset($UuidTag->Fruit));
|
||||
//But non-dynamic with models are lazy loaded
|
||||
$this->assertFalse(property_exists($UuidTag, 'FruitsUuidTag'));
|
||||
$this->assertTrue(isset($UuidTag->FruitsUuidTag));
|
||||
$this->assertType('FruitsUuidTag', $UuidTag->FruitsUuidTag);
|
||||
}
|
||||
|
||||
/**
|
||||
* testAssociationLazyLoadWithBindModel
|
||||
*
|
||||
* @group lazyloading
|
||||
* @return void
|
||||
*/
|
||||
public function testAssociationLazyLoadWithBindModel() {
|
||||
$this->loadFixtures('Article', 'User');
|
||||
$Article = new ArticleB();
|
||||
|
||||
$this->assertFalse(isset($Article->belongsTo['User']));
|
||||
$this->assertFalse(property_exists($Article, 'User'));
|
||||
|
||||
$Article->bindModel(array('belongsTo' => array('User')));
|
||||
$this->assertTrue(isset($Article->belongsTo['User']));
|
||||
$this->assertFalse(property_exists($Article, 'User'));
|
||||
$this->assertType('User', $Article->User);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue