Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
saeideng committed Oct 1, 2016
1 parent 875d911 commit fefd251
Showing 1 changed file with 80 additions and 3 deletions.
83 changes: 80 additions & 3 deletions tests/TestCase/ORM/QueryRegressionTest.php
Expand Up @@ -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',
Expand All @@ -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
*/
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit fefd251

Please sign in to comment.