From c5e4f366d4bd1ab824544e7425fa6a4c9b114b32 Mon Sep 17 00:00:00 2001 From: zYne Date: Sun, 3 Sep 2006 17:32:35 +0000 Subject: [PATCH] Tests for covering the Doctrine_Collection::loadRelated functionality for basic many-to-many relations --- Doctrine/Collection.php | 4 ++-- tests/CollectionTestCase.php | 29 +++++++++++++++++++++++++++++ tests/classes.php | 2 +- tests/run.php | 2 +- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/Doctrine/Collection.php b/Doctrine/Collection.php index ecc211f8e..1f23165ad 100644 --- a/Doctrine/Collection.php +++ b/Doctrine/Collection.php @@ -288,12 +288,12 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator } elseif($this->relation instanceof Doctrine_Association) { $asf = $this->relation->getAssociationFactory(); - $query = "SELECT ".$foreign." FROM ".$asf->getTableName()." WHERE ".$local."=".$this->getIncremented(); + $query = 'SELECT '.$foreign." FROM ".$asf->getTableName()." WHERE ".$local."=".$this->getIncremented(); $table = $fk->getTable(); $graph = new Doctrine_Query($table->getConnection()); - $q = "FROM ".$table->getComponentName()." WHERE ".$table->getComponentName().".".$table->getIdentifier()." IN ($query)"; + $q = 'FROM ' . $table->getComponentName() . ' WHERE ' . $table->getComponentName() . '.' . $table->getIdentifier()." IN ($query)"; } } diff --git a/tests/CollectionTestCase.php b/tests/CollectionTestCase.php index 15cf1611c..4b61daf88 100644 --- a/tests/CollectionTestCase.php +++ b/tests/CollectionTestCase.php @@ -1,5 +1,34 @@ name = 'resource 1'; + $resource[0]->Type[0]->type = 'type 1'; + $resource[0]->Type[1]->type = 'type 2'; + $resource[1]->name = 'resource 2'; + $resource[1]->Type[0]->type = 'type 3'; + $resource[1]->Type[1]->type = 'type 4'; + + $resource->save(); + + $this->connection->clear(); + + $resources = $this->connection->query('FROM Resource'); + + $count = $this->dbh->count(); + $resources->loadRelated('Type'); + + $this->assertEqual(($count + 1), $this->dbh->count()); + $this->assertEqual($resources[0]->name, 'resource 1'); + $this->assertEqual($resource[0]->Type[0]->type, 'type 1'); + $this->assertEqual($resource[0]->Type[1]->type, 'type 2'); + $this->assertEqual(($count + 1), $this->dbh->count()); + + $this->assertEqual($resource[1]->name, 'resource 2'); + $this->assertEqual($resource[1]->Type[0]->type, 'type 3'); + $this->assertEqual($resource[1]->Type[1]->type, 'type 4'); + $this->assertEqual(($count + 1), $this->dbh->count()); + } public function testAdd() { $coll = new Doctrine_Collection($this->objTable); $coll->add(new User()); diff --git a/tests/classes.php b/tests/classes.php index 60b054b62..a3a350dc7 100644 --- a/tests/classes.php +++ b/tests/classes.php @@ -147,7 +147,7 @@ class Task extends Doctrine_Record { class Resource extends Doctrine_Record { public function setUp() { - $this->hasMany("Task as TaskAlias","Assignment.task_id"); + $this->hasMany("Task as TaskAlias", "Assignment.task_id"); $this->hasMany("ResourceType as Type", "ResourceReference.type_id"); } public function setTableDefinition() { diff --git a/tests/run.php b/tests/run.php index 8397f9313..6c1471160 100644 --- a/tests/run.php +++ b/tests/run.php @@ -62,7 +62,7 @@ $test->addTestCase(new Doctrine_Filter_TestCase()); $test->addTestCase(new Doctrine_ValueHolder_TestCase()); -$test->addTestCase(new Doctrine_ValidatorTestCase()); +$test->addTestCase(new Doctrine_ValidatorTestCase()); $test->addTestCase(new Doctrine_QueryTestCase());