1
0
mirror of synced 2024-12-13 06:46:03 +03:00

Tests for covering the Doctrine_Collection::loadRelated functionality for basic many-to-many relations

This commit is contained in:
zYne 2006-09-03 17:32:35 +00:00
parent 1d4a59b772
commit c5e4f366d4
4 changed files with 33 additions and 4 deletions

View File

@ -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)";
}
}

View File

@ -1,5 +1,34 @@
<?php
class Doctrine_CollectionTestCase extends Doctrine_UnitTestCase {
public function testLoadRelatedForNormalAssociation() {
$resource = new Doctrine_Collection('Resource');
$resource[0]->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());

View File

@ -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() {

View File

@ -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());