From fefd251ad62faca0616b7d5d3319334251c5baf3 Mon Sep 17 00:00:00 2001 From: saeid Date: Sun, 2 Oct 2016 00:27:11 +0330 Subject: [PATCH] add tests --- tests/TestCase/ORM/QueryRegressionTest.php | 83 +++++++++++++++++++++- 1 file changed, 80 insertions(+), 3 deletions(-) diff --git a/tests/TestCase/ORM/QueryRegressionTest.php b/tests/TestCase/ORM/QueryRegressionTest.php index d8432736f52..ffb0941fd09 100644 --- a/tests/TestCase/ORM/QueryRegressionTest.php +++ b/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); } /**