Skip to content
Permalink
Browse files

add tests

  • Loading branch information...
saeideng committed Oct 1, 2016
1 parent 875d911 commit fefd251ad62faca0616b7d5d3319334251c5baf3
Showing with 80 additions and 3 deletions.
  1. +80 −3 tests/TestCase/ORM/QueryRegressionTest.php
@@ -1157,13 +1157,14 @@ public function testBooleanConditionsInContain()
}
/**
* Test that contain queries map types correctly.
* Test that contain/matching/innerJoinWith/leftJoinWith/notMatching
* queries map types correctly.
*
* @return void
*/
public function testComplexTypesInJoinedWhere()
{
$this->loadFixtures('Comments', 'Users');
$this->loadFixtures('Comments', 'Users', 'Articles', 'Tags', 'ArticlesTags');
$table = TableRegistry::get('Users');
$table->hasOne('Comments', [
'foreignKey' => 'user_id',
@@ -1177,10 +1178,56 @@ public function testComplexTypesInJoinedWhere()
$result = $query->first();
$this->assertNotEmpty($result);
$this->assertInstanceOf('Cake\I18n\Time', $result->comment->updated);
$query = $table->find()
->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->_matchingData['Comments']->updated);
$query = $table->find()
->innerJoinWith('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);
$query = $table->find()
->leftJoinWith('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);
$Tags = TableRegistry::get('Tags');
$Tags->belongsToMany('Articles');
$query = $Tags->find()
->notMatching('Articles', function ($q) {
return $q ->where(['ArticlesTags.tag_id !=' => 3 ]);
})
->where([
'Tags.created <' => new \DateTime('2016-01-02 00:00:00')
]);
$result = $query->first();
$this->assertNotEmpty($result);
$this->assertEquals(3, $result->id);
$this->assertInstanceOf('Cake\I18n\Time', $result->created);
}
/**
* Test that nested contain queries map types correctly.
* Test that nested contain/matching/innerJoinWith/leftJoinWith
* queries map types correctly.
*
* @return void
*/
@@ -1206,6 +1253,36 @@ public function testComplexNestedTypesInJoinedWhere()
$result = $query->first();
$this->assertNotEmpty($result);
$this->assertInstanceOf('Cake\I18n\Time', $result->comment->article->author->updated);
$query = $table->find()
->matching('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);
$query = $table->find()
->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->updated);
$query = $table->find()
->leftJoinWith('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->updated);
}
/**

0 comments on commit fefd251

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