From 16c809443fed5f3d411e28898078d72ab424a2d1 Mon Sep 17 00:00:00 2001 From: zYne Date: Tue, 9 Jan 2007 23:11:32 +0000 Subject: [PATCH] added query join test case --- tests/Query/JoinTestCase.php | 77 ++++++++++++++++++++++++++++++++++++ tests/run.php | 6 +-- 2 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 tests/Query/JoinTestCase.php diff --git a/tests/Query/JoinTestCase.php b/tests/Query/JoinTestCase.php new file mode 100644 index 000000000..324e50f72 --- /dev/null +++ b/tests/Query/JoinTestCase.php @@ -0,0 +1,77 @@ +. + */ + +/** + * Doctrine_Query_JoinCondition_TestCase + * + * @package Doctrine + * @author Konsta Vesterinen + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision$ + */ +class Doctrine_Query_Join_TestCase extends Doctrine_UnitTestCase +{ + public function prepareTables() + { + } + public function prepareData() + { + } + public function testInitData() + { + $c = new Record_Country(); + + $c->name = 'Some country'; + + $c->City[0]->name = 'City 1'; + $c->City[1]->name = 'City 2'; + $c->City[2]->name = 'City 3'; + + $c->City[0]->District->name = 'District 1'; + $c->City[2]->District->name = 'District 2'; + + $c->save(); + + $this->connection->clear(); + } + public function testRecordHydrationWorksWithDeeplyNestedStructures() + { + $q = new Doctrine_Query(); + + $q->select('c.*, c2.*, d.*') + ->from('Record_Country c')->leftJoin('c.City c2')->leftJoin('c2.District d') + ->where('c.id = ?', array(1)); + + $this->assertEqual($q->getQuery(), "SELECT r.id AS r__id, r.name AS r__name, r2.id AS r2__id, r2.name AS r2__name, r2.country_id AS r2__country_id, r2.district_id AS r2__district_id, r3.id AS r3__id, r3.name AS r3__name FROM record__country r LEFT JOIN record__city r2 ON r.id = r2.country_id LEFT JOIN record__district r3 ON r2.district_id = r3.id WHERE r.id = ?"); + + $countries = $q->execute(); + $c = $countries[0]; + $this->assertEqual($c->City[0]->name, 'City 1'); + $this->assertEqual($c->City[1]->name, 'City 2'); + $this->assertEqual($c->City[2]->name, 'City 3'); + + $this->assertEqual($c->City[0]->District->name, 'District 1'); + $this->assertEqual($c->City[2]->District->name, 'District 2'); + } +} diff --git a/tests/run.php b/tests/run.php index 6d5396606..b92d4b37b 100644 --- a/tests/run.php +++ b/tests/run.php @@ -57,8 +57,8 @@ print '
';
 
 $test = new GroupTest('Doctrine Framework Unit Tests');
 
-$test->addTestCase(new Doctrine_Query_Join_TestCase());
-/**
+
+
 $test->addTestCase(new Doctrine_Sequence_Firebird_TestCase());
 $test->addTestCase(new Doctrine_Sequence_Informix_TestCase());
 $test->addTestCase(new Doctrine_Sequence_Mysql_TestCase());
@@ -211,8 +211,8 @@ $test->addTestCase(new Doctrine_Query_Select_TestCase());
 $test->addTestCase(new Doctrine_Query_Expression_TestCase());
 $test->addTestCase(new Doctrine_Query_Having_TestCase());
 $test->addTestCase(new Doctrine_Query_JoinCondition_TestCase());
+$test->addTestCase(new Doctrine_Query_Join_TestCase());
 
-*/
 // Cache tests
 //$test->addTestCase(new Doctrine_Cache_Query_SqliteTestCase());
 //$test->addTestCase(new Doctrine_Cache_FileTestCase());