Skip to content

Commit

Permalink
seperating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
saeideng committed Oct 4, 2016
1 parent fefd251 commit ebda690
Showing 1 changed file with 87 additions and 21 deletions.
108 changes: 87 additions & 21 deletions tests/TestCase/ORM/QueryRegressionTest.php
Expand Up @@ -1157,14 +1157,13 @@ public function testBooleanConditionsInContain()
}

/**
* Test that contain/matching/innerJoinWith/leftJoinWith/notMatching
* queries map types correctly.
* Test that contain queries map types correctly.
*
* @return void
*/
public function testComplexTypesInJoinedWhere()
{
$this->loadFixtures('Comments', 'Users', 'Articles', 'Tags', 'ArticlesTags');
$this->loadFixtures('Comments', 'Users');
$table = TableRegistry::get('Users');
$table->hasOne('Comments', [
'foreignKey' => 'user_id',
Expand All @@ -1178,39 +1177,88 @@ public function testComplexTypesInJoinedWhere()
$result = $query->first();
$this->assertNotEmpty($result);
$this->assertInstanceOf('Cake\I18n\Time', $result->comment->updated);
}

/**
* Test that nested contain queries map types correctly.
*
* @return void
*/
public function testComplexNestedTypesInJoinedWhere()
{
$this->loadFixtures('Comments', 'Users', 'Articles');
$table = TableRegistry::get('Users');
$table->hasOne('Comments', [
'foreignKey' => 'user_id',
]);
$table->Comments->belongsTo('Articles');
$table->Comments->Articles->belongsTo('Authors', [
'className' => 'Users',
'foreignKey' => 'author_id'
]);

$query = $table->find()
->matching('Comments')
->contain('Comments.Articles.Authors')
->where([
'Comments.updated >' => new \DateTime('2007-03-18 10:55:00')
'Authors.created >' => new \DateTime('2007-03-17 01:16:00')
]);

$result = $query->first();
$this->assertNotEmpty($result);
$this->assertInstanceOf('Cake\I18n\Time', $result->_matchingData['Comments']->updated);
$this->assertInstanceOf('Cake\I18n\Time', $result->comment->article->author->updated);
}

/**
* Test that matching queries map types correctly.
*
* @return void
*/
public function testComplexTypesInJoinedWhereWithMatching()
{
$this->loadFixtures('Comments', 'Users', 'Articles');
$table = TableRegistry::get('Users');
$table->hasOne('Comments', [
'foreignKey' => 'user_id',
]);
$table->Comments->belongsTo('Articles');
$table->Comments->Articles->belongsTo('Authors', [
'className' => 'Users',
'foreignKey' => 'author_id'
]);

$query = $table->find()
->innerJoinWith('Comments')
->matching('Comments')
->where([
'Comments.updated >' => new \DateTime('2007-03-18 10:55:00')
]);

$result = $query->first();
$this->assertNotEmpty($result);
$this->assertInstanceOf('Cake\I18n\Time', $result->updated);
$this->assertInstanceOf('Cake\I18n\Time', $result->_matchingData['Comments']->updated);


$query = $table->find()
->leftJoinWith('Comments')
->matching('Comments.Articles.Authors')
->where([
'Comments.updated >' => new \DateTime('2007-03-18 10:55:00')
'Authors.created >' => new \DateTime('2007-03-17 01:16:00')
]);

$result = $query->first();
$this->assertNotEmpty($result);
$this->assertInstanceOf('Cake\I18n\Time', $result->updated);
$this->assertInstanceOf('Cake\I18n\Time', $result->_matchingData['Authors']->updated);
}

/**
* Test that notMatching queries map types correctly.
*
* @return void
*/
public function testComplexTypesInJoinedWhereWithNotMatching()
{
$this->loadFixtures('Articles', 'Tags', 'ArticlesTags');
$Tags = TableRegistry::get('Tags');
$Tags->belongsToMany('Articles');

$query = $Tags->find()
->notMatching('Articles', function ($q) {
return $q ->where(['ArticlesTags.tag_id !=' => 3 ]);
Expand All @@ -1226,12 +1274,11 @@ public function testComplexTypesInJoinedWhere()
}

/**
* Test that nested contain/matching/innerJoinWith/leftJoinWith
* queries map types correctly.
* Test that innerJoinWith queries map types correctly.
*
* @return void
*/
public function testComplexNestedTypesInJoinedWhere()
public function testComplexTypesInJoinedWhereWithInnerJoinWith()
{
$this->loadFixtures('Comments', 'Users', 'Articles');
$table = TableRegistry::get('Users');
Expand All @@ -1245,29 +1292,48 @@ public function testComplexNestedTypesInJoinedWhere()
]);

$query = $table->find()
->contain('Comments.Articles.Authors')
->innerJoinWith('Comments')
->where([
'Authors.created >' => new \DateTime('2007-03-17 01:16:00')
'Comments.updated >' => new \DateTime('2007-03-18 10:55:00')
]);

$result = $query->first();
$this->assertNotEmpty($result);
$this->assertInstanceOf('Cake\I18n\Time', $result->comment->article->author->updated);
$this->assertInstanceOf('Cake\I18n\Time', $result->updated);

$query = $table->find()
->matching('Comments.Articles.Authors')
->innerJoinWith('Comments.Articles.Authors')
->where([
'Authors.created >' => new \DateTime('2007-03-17 01:16:00')
]);

$result = $query->first();
$this->assertNotEmpty($result);
$this->assertInstanceOf('Cake\I18n\Time', $result->_matchingData['Authors']->updated);
$this->assertInstanceOf('Cake\I18n\Time', $result->updated);
}

/**
* Test that leftJoinWith queries map types correctly.
*
* @return void
*/
public function testComplexTypesInJoinedWhereWithLeftJoinWith()
{
$this->loadFixtures('Comments', 'Users', 'Articles');
$table = TableRegistry::get('Users');
$table->hasOne('Comments', [
'foreignKey' => 'user_id',
]);
$table->Comments->belongsTo('Articles');
$table->Comments->Articles->belongsTo('Authors', [
'className' => 'Users',
'foreignKey' => 'author_id'
]);

$query = $table->find()
->innerJoinWith('Comments.Articles.Authors')
->leftJoinWith('Comments')
->where([
'Authors.created >' => new \DateTime('2007-03-17 01:16:00')
'Comments.updated >' => new \DateTime('2007-03-18 10:55:00')
]);

$result = $query->first();
Expand Down

0 comments on commit ebda690

Please sign in to comment.