Skip to content
Permalink
Browse files

seperating tests

  • Loading branch information...
saeideng committed Oct 4, 2016
1 parent fefd251 commit ebda6903477a4d66f4a91176d17bfc7c78fa7d52
Showing with 87 additions and 21 deletions.
  1. +87 −21 tests/TestCase/ORM/QueryRegressionTest.php
@@ -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',
@@ -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 ]);
@@ -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');
@@ -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();

0 comments on commit ebda690

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