2006-10-26 01:12:30 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Doctrine_Relation_ManyToMany_TestCase extends Doctrine_UnitTestCase {
|
|
|
|
public function prepareData() { }
|
|
|
|
public function prepareTables() {
|
|
|
|
parent::prepareTables();
|
|
|
|
}
|
2006-10-30 02:24:50 +03:00
|
|
|
|
|
|
|
public function testManyToManyRelationWithAliasesAndCustomPKs() {
|
|
|
|
$component = new M2MTest2();
|
|
|
|
|
|
|
|
try {
|
|
|
|
$rel = $component->getTable()->getRelation('RTC5');
|
|
|
|
$this->pass();
|
|
|
|
} catch(Doctrine_Exception $e) {
|
|
|
|
$this->fail();
|
|
|
|
}
|
|
|
|
$this->assertTrue($rel instanceof Doctrine_Relation_Association);
|
|
|
|
|
|
|
|
$this->assertTrue($component->RTC5 instanceof Doctrine_Collection);
|
|
|
|
|
|
|
|
try {
|
|
|
|
$rel = $component->getTable()->getRelation('JC3');
|
|
|
|
$this->pass();
|
|
|
|
} catch(Doctrine_Exception $e) {
|
|
|
|
$this->fail();
|
|
|
|
}
|
|
|
|
$this->assertEqual($rel->getLocal(), 'oid');
|
|
|
|
}
|
2008-01-05 22:55:56 +03:00
|
|
|
|
2006-10-30 02:24:50 +03:00
|
|
|
public function testJoinComponent() {
|
|
|
|
$component = new JC3();
|
|
|
|
|
|
|
|
try {
|
|
|
|
$rel = $component->getTable()->getRelation('M2MTest2');
|
|
|
|
$this->pass();
|
|
|
|
} catch(Doctrine_Exception $e) {
|
|
|
|
$this->fail();
|
|
|
|
}
|
|
|
|
$this->assertEqual($rel->getForeign(), 'oid');
|
|
|
|
try {
|
|
|
|
$rel = $component->getTable()->getRelation('RTC4');
|
|
|
|
$this->pass();
|
|
|
|
} catch(Doctrine_Exception $e) {
|
|
|
|
$this->fail();
|
|
|
|
}
|
|
|
|
$this->assertEqual($rel->getForeign(), 'oid');
|
|
|
|
}
|
2007-05-27 22:56:54 +04:00
|
|
|
|
2006-10-30 02:24:50 +03:00
|
|
|
public function testManyToManyRelationFetchingWithAliasesAndCustomPKs2() {
|
|
|
|
$q = new Doctrine_Query();
|
2007-04-11 23:12:52 +04:00
|
|
|
|
2006-10-30 02:24:50 +03:00
|
|
|
try {
|
|
|
|
$q->from('M2MTest2 m INNER JOIN m.JC3');
|
|
|
|
$this->pass();
|
|
|
|
} catch(Doctrine_Exception $e) {
|
|
|
|
$this->fail();
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
$q->execute();
|
|
|
|
$this->pass();
|
|
|
|
} catch(Doctrine_Exception $e) {
|
|
|
|
$this->fail();
|
|
|
|
}
|
|
|
|
}
|
2006-10-26 01:12:30 +04:00
|
|
|
public function testManyToManyHasRelationWithAliases4() {
|
|
|
|
|
|
|
|
try {
|
2007-04-11 23:12:52 +04:00
|
|
|
$component = new M2MTest();
|
|
|
|
|
2006-10-26 01:12:30 +04:00
|
|
|
$this->pass();
|
|
|
|
} catch(Doctrine_Exception $e) {
|
|
|
|
$this->fail();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testManyToManyHasRelationWithAliases3() {
|
|
|
|
$component = new M2MTest();
|
|
|
|
|
|
|
|
try {
|
|
|
|
$rel = $component->getTable()->getRelation('RTC3');
|
|
|
|
$this->pass();
|
|
|
|
} catch(Doctrine_Exception $e) {
|
|
|
|
$this->fail();
|
|
|
|
}
|
|
|
|
$this->assertTrue($rel instanceof Doctrine_Relation_Association);
|
|
|
|
|
|
|
|
$this->assertTrue($component->RTC3 instanceof Doctrine_Collection);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testManyToManyHasRelationWithAliases() {
|
|
|
|
$component = new M2MTest();
|
2007-04-11 23:12:52 +04:00
|
|
|
|
2006-10-26 01:12:30 +04:00
|
|
|
try {
|
|
|
|
$rel = $component->getTable()->getRelation('RTC1');
|
|
|
|
$this->pass();
|
|
|
|
} catch(Doctrine_Exception $e) {
|
|
|
|
$this->fail();
|
|
|
|
}
|
|
|
|
$this->assertTrue($rel instanceof Doctrine_Relation_Association);
|
|
|
|
|
|
|
|
$this->assertTrue($component->RTC1 instanceof Doctrine_Collection);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testManyToManyHasRelationWithAliases2() {
|
|
|
|
$component = new M2MTest();
|
2007-04-11 23:12:52 +04:00
|
|
|
|
2006-10-26 01:12:30 +04:00
|
|
|
try {
|
|
|
|
$rel = $component->getTable()->getRelation('RTC2');
|
|
|
|
$this->pass();
|
|
|
|
} catch(Doctrine_Exception $e) {
|
|
|
|
$this->fail();
|
|
|
|
}
|
|
|
|
$this->assertTrue($rel instanceof Doctrine_Relation_Association);
|
|
|
|
|
|
|
|
$this->assertTrue($component->RTC1 instanceof Doctrine_Collection);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testManyToManyRelationSaving() {
|
|
|
|
$component = new M2MTest();
|
|
|
|
|
|
|
|
$component->RTC1[0]->name = '1';
|
|
|
|
$component->RTC1[1]->name = '2';
|
|
|
|
$component->name = '2';
|
|
|
|
|
|
|
|
$count = $this->dbh->count();
|
|
|
|
|
|
|
|
$component->save();
|
|
|
|
|
|
|
|
$this->assertEqual($this->dbh->count(), ($count + 5));
|
|
|
|
|
|
|
|
$this->assertEqual($component->RTC1->count(), 2);
|
|
|
|
|
|
|
|
$component = $component->getTable()->find($component->id);
|
|
|
|
|
|
|
|
$this->assertEqual($component->RTC1->count(), 2);
|
|
|
|
|
|
|
|
// check that it doesn't matter saving the other M2M components as well
|
|
|
|
|
|
|
|
$component->RTC2[0]->name = '1';
|
|
|
|
$component->RTC2[1]->name = '2';
|
|
|
|
|
|
|
|
$count = $this->dbh->count();
|
|
|
|
|
|
|
|
$component->save();
|
|
|
|
|
|
|
|
$this->assertEqual($this->dbh->count(), ($count + 4));
|
|
|
|
|
|
|
|
$this->assertEqual($component->RTC2->count(), 2);
|
|
|
|
|
|
|
|
$component = $component->getTable()->find($component->id);
|
|
|
|
|
|
|
|
$this->assertEqual($component->RTC2->count(), 2);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testManyToManyRelationSaving2() {
|
|
|
|
$component = new M2MTest();
|
|
|
|
|
|
|
|
$component->RTC2[0]->name = '1';
|
|
|
|
$component->RTC2[1]->name = '2';
|
|
|
|
$component->name = '2';
|
|
|
|
|
|
|
|
$count = $this->dbh->count();
|
|
|
|
|
|
|
|
$component->save();
|
|
|
|
|
|
|
|
$this->assertEqual($this->dbh->count(), ($count + 5));
|
|
|
|
|
|
|
|
$this->assertEqual($component->RTC2->count(), 2);
|
|
|
|
|
|
|
|
$component = $component->getTable()->find($component->id);
|
|
|
|
|
|
|
|
$this->assertEqual($component->RTC2->count(), 2);
|
|
|
|
|
|
|
|
// check that it doesn't matter saving the other M2M components as well
|
|
|
|
|
|
|
|
$component->RTC1[0]->name = '1';
|
|
|
|
$component->RTC1[1]->name = '2';
|
|
|
|
|
|
|
|
$count = $this->dbh->count();
|
|
|
|
|
|
|
|
$component->save();
|
|
|
|
|
|
|
|
$this->assertEqual($this->dbh->count(), ($count + 4));
|
|
|
|
|
|
|
|
$this->assertEqual($component->RTC1->count(), 2);
|
|
|
|
|
|
|
|
$component = $component->getTable()->find($component->id);
|
|
|
|
|
|
|
|
$this->assertEqual($component->RTC1->count(), 2);
|
2006-11-18 23:27:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testManyToManySimpleUpdate() {
|
|
|
|
$component = $this->connection->getTable('M2MTest')->find(1);
|
|
|
|
|
|
|
|
$this->assertEqual($component->name, 2);
|
|
|
|
|
|
|
|
$component->name = 'changed name';
|
|
|
|
|
|
|
|
$component->save();
|
|
|
|
|
|
|
|
$this->assertEqual($component->name, 'changed name');
|
2006-10-26 01:12:30 +04:00
|
|
|
}
|
|
|
|
}
|