Association table tests are pretty messy, still more fixes to go
This commit is contained in:
parent
6d72afb462
commit
1db6dfa30b
@ -742,75 +742,69 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
|||||||
$gf = $this->connection->getTable("Group");
|
$gf = $this->connection->getTable("Group");
|
||||||
|
|
||||||
$this->assertTrue($user->Group instanceof Doctrine_Collection);
|
$this->assertTrue($user->Group instanceof Doctrine_Collection);
|
||||||
$this->assertTrue($user->Group[0]->id == 3);
|
$this->assertEqual($user->Group->count(), 1);
|
||||||
|
$this->assertEqual($user->Group[0]->id, 3);
|
||||||
|
|
||||||
|
|
||||||
// ADDING ASSOCIATED REFERENCES
|
// ADDING ASSOCIATED REFERENCES
|
||||||
|
|
||||||
|
|
||||||
$record = $gf->find(1);
|
$group1 = $gf->find(1);
|
||||||
$record2 = $gf->find(2);
|
$group2 = $gf->find(2);
|
||||||
$user->Group[1] = $record;
|
$user->Group[1] = $group1;
|
||||||
$user->Group[2] = $record2;
|
$user->Group[2] = $group2;
|
||||||
|
|
||||||
$this->assertTrue($user->Group->count() == 3);
|
$this->assertEqual($user->Group->count(), 3);
|
||||||
|
|
||||||
$user->save();
|
$user->save();
|
||||||
$coll = $user->Group;
|
$coll = $user->Group;
|
||||||
|
|
||||||
|
|
||||||
// UNSETTING ASSOCIATED REFERENCES
|
// UNSETTING ASSOCIATED REFERENCES
|
||||||
|
|
||||||
|
|
||||||
unset($user);
|
unset($user);
|
||||||
$user = $this->objTable->find(5);
|
$user = $this->objTable->find(5);
|
||||||
$this->assertTrue($user->Group->count() == 3);
|
$this->assertEqual($user->Group->count(), 3);
|
||||||
|
$this->assertEqual($user->Group[1]->id, 2);
|
||||||
|
$this->assertEqual($user->Group[2]->id, 3);
|
||||||
|
|
||||||
unset($user->Group[1]);
|
unset($user->Group[1]);
|
||||||
$this->assertTrue($user->Group->count() == 2);
|
$this->assertEqual($user->Group->count(), 2);
|
||||||
|
|
||||||
unset($user->Group[2]);
|
unset($user->Group[2]);
|
||||||
$this->assertTrue($user->Group->count() == 1);
|
$this->assertEqual($user->Group->count(), 1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$user->save();
|
$user->save();
|
||||||
$this->assertTrue($user->Group->count() == 1);
|
$this->assertEqual($user->Group->count(), 1);
|
||||||
unset($user);
|
unset($user);
|
||||||
|
|
||||||
|
|
||||||
// CHECKING THE PERSISTENCE OF UNSET ASSOCIATED REFERENCES
|
// CHECKING THE PERSISTENCE OF UNSET ASSOCIATED REFERENCES
|
||||||
|
|
||||||
$this->connection->clear();
|
$this->connection->clear();
|
||||||
$user = $this->objTable->find(5);
|
$user = $this->objTable->find(5);
|
||||||
$this->assertEqual($user->Group->count(), 1);
|
$this->assertEqual($user->Group->count(), 1);
|
||||||
$this->assertTrue($user->Group[0]->id == 3);
|
$this->assertEqual($user->Group[0]->id, 1);
|
||||||
$this->assertTrue($gf->findAll()->count() == 3);
|
$this->assertEqual($gf->findAll()->count(), 3);
|
||||||
|
|
||||||
|
|
||||||
// REPLACING OLD ASSOCIATED REFERENCE
|
// REPLACING OLD ASSOCIATED REFERENCE
|
||||||
|
$user->Group[1] = $group1;
|
||||||
|
|
||||||
$user->Group[1] = $record;
|
|
||||||
$user->save();
|
$user->save();
|
||||||
|
|
||||||
$user->Group[1] = $record2;
|
$user->Group[0] = $group2;
|
||||||
$user->save();
|
$user->save();
|
||||||
|
|
||||||
$this->assertEqual($user->Group->count(), 2);
|
$this->assertEqual($user->Group->count(), 2);
|
||||||
$this->assertEqual($user->Group[1]->identifier(), $record2->identifier());
|
$this->assertEqual($user->Group[0]->identifier(), $group2->identifier());
|
||||||
$this->assertFalse($user->Group[1]->identifier() == $record->identifier());
|
$this->assertEqual($user->Group[1]->identifier(), $group1->identifier());
|
||||||
|
|
||||||
|
|
||||||
$user->Group[0] = $record;
|
$group3 = $gf->find(3);
|
||||||
|
if ($group3 === false) {
|
||||||
$record = $gf->find(3);
|
|
||||||
if ($record === false) {
|
|
||||||
$this->fail("Group record with id 3 couldn't be retrived");
|
$this->fail("Group record with id 3 couldn't be retrived");
|
||||||
} else {
|
} else {
|
||||||
$user->Group[1] = $record;
|
$user->Group[1] = $group3;
|
||||||
}
|
}
|
||||||
|
$user->Group[0] = $group1;
|
||||||
|
|
||||||
|
|
||||||
$user->save();
|
$user->save();
|
||||||
|
Loading…
Reference in New Issue
Block a user