1
0
mirror of synced 2025-01-18 06:21:40 +03:00
This commit is contained in:
zYne 2007-05-23 21:02:19 +00:00
parent 8c54e8d736
commit cab55d0d06

View File

@ -38,7 +38,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase {
$this->tables[] = "GzipTest";
parent::prepareTables();
}
/**
public function testIssetForPrimaryKey() {
$this->assertTrue(isset($this->users[0]->id));
$this->assertTrue(isset($this->users[0]['id']));
@ -103,33 +103,34 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase {
$this->assertTrue(is_object($test->someObject));
$this->assertEqual($test->someInt, 11);
}
*/
public function testJoinTableSelfReferencingInsertingData() {
$e = new Entity();
$e->name = "Entity test";
$this->assertTrue($e->Entity[0] instanceof Entity);
$this->assertTrue($e->Entity[1] instanceof Entity);
$this->assertEqual($e->Entity[0]->state(), Doctrine_Record::STATE_TCLEAN);
$this->assertEqual($e->Entity[1]->state(), Doctrine_Record::STATE_TCLEAN);
$e->Entity[0]->name = "Friend 1";
$e->Entity[1]->name = "Friend 2";
$e->Entity[0]->name = 'Friend 1';
$e->Entity[1]->name = 'Friend 2';
$e->Entity[0]->Entity[0]->name = "Friend 1 1";
$e->Entity[0]->Entity[1]->name = "Friend 1 2";
$e->Entity[0]->Entity[0]->name = 'Friend 1 1';
$e->Entity[0]->Entity[1]->name = 'Friend 1 2';
$e->Entity[1]->Entity[0]->name = "Friend 2 1";
$e->Entity[1]->Entity[1]->name = "Friend 2 2";
$e->Entity[1]->Entity[0]->name = 'Friend 2 1';
$e->Entity[1]->Entity[1]->name = 'Friend 2 2';
$this->assertEqual($e->Entity[0]->name, "Friend 1");
$this->assertEqual($e->Entity[1]->name, "Friend 2");
$this->assertEqual($e->Entity[0]->name, 'Friend 1');
$this->assertEqual($e->Entity[1]->name, 'Friend 2');
$this->assertEqual($e->Entity[0]->Entity[0]->name, "Friend 1 1");
$this->assertEqual($e->Entity[0]->Entity[1]->name, "Friend 1 2");
$this->assertEqual($e->Entity[0]->Entity[0]->name, 'Friend 1 1');
$this->assertEqual($e->Entity[0]->Entity[1]->name, 'Friend 1 2');
$this->assertEqual($e->Entity[1]->Entity[0]->name, "Friend 2 1");
$this->assertEqual($e->Entity[1]->Entity[1]->name, "Friend 2 2");
$this->assertEqual($e->Entity[1]->Entity[0]->name, 'Friend 2 1');
$this->assertEqual($e->Entity[1]->Entity[1]->name, 'Friend 2 2');
$this->assertEqual($e->Entity[0]->state(), Doctrine_Record::STATE_TDIRTY);
@ -145,21 +146,21 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase {
$this->assertTrue($e->Entity[0] instanceof Entity);
$this->assertTrue($e->Entity[1] instanceof Entity);
$this->assertEqual($e->Entity[0]->name, "Friend 1");
$this->assertEqual($e->Entity[1]->name, "Friend 2");
$this->assertEqual($e->Entity[0]->name, 'Friend 1');
$this->assertEqual($e->Entity[1]->name, 'Friend 2');
$this->assertEqual($e->Entity[0]->Entity[0]->name, "Friend 1 1");
$this->assertEqual($e->Entity[0]->Entity[1]->name, "Friend 1 2");
$this->assertEqual($e->Entity[0]->Entity[0]->name, 'Friend 1 1');
$this->assertEqual($e->Entity[0]->Entity[1]->name, 'Friend 1 2');
$this->assertEqual($e->Entity[1]->Entity[0]->name, "Friend 2 1");
$this->assertEqual($e->Entity[1]->Entity[1]->name, "Friend 2 2");
$this->assertEqual($e->Entity[1]->Entity[0]->name, 'Friend 2 1');
$this->assertEqual($e->Entity[1]->Entity[1]->name, 'Friend 2 2');
$this->assertEqual($e->Entity[0]->state(), Doctrine_Record::STATE_CLEAN);
$this->assertEqual($e->Entity[1]->state(), Doctrine_Record::STATE_CLEAN);
$this->assertTrue(is_numeric($e->id));
$result = $this->dbh->query("SELECT * FROM entity_reference")->fetchAll(PDO::FETCH_ASSOC);
$result = $this->dbh->query('SELECT * FROM entity_reference')->fetchAll(PDO::FETCH_ASSOC);
$this->assertEqual(count($result), 6);
@ -188,13 +189,13 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($e->Entity[0]->name, "Friend 1");
$this->assertEqual($e->Entity[1]->name, "Friend 2");
$this->assertEqual($e->Entity[0]->Entity[0]->name, "Friend 1 1");
$this->assertEqual($e->Entity[0]->Entity[1]->name, "Friend 1 2");
$this->assertEqual($e->Entity[0]->Entity[0]->name, "Entity test");
$this->assertEqual($e->Entity[0]->Entity[1]->name, "Friend 1 1");
$this->assertEqual(count($this->dbh), ($count + 2));
$this->assertEqual($e->Entity[1]->Entity[0]->name, "Friend 2 1");
$this->assertEqual($e->Entity[1]->Entity[1]->name, "Friend 2 2");
$this->assertEqual($e->Entity[1]->Entity[0]->name, "Entity test");
$this->assertEqual($e->Entity[1]->Entity[1]->name, "Friend 2 1");
$this->assertEqual(count($this->dbh), ($count + 3));
@ -209,14 +210,12 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase {
$query = new Doctrine_Query($this->connection);
$query->from("Entity.Entity")->where("Entity.Entity.name = 'Friend 1 1'");
$query->from('Entity.Entity e')->where("e.name = 'Friend 1 1'");
$coll = $query->execute();
$this->assertEqual($coll->count(), 1);
$this->assertEqual($coll->count(), 2);
}
public function testToArray() {
$user = new User();
@ -264,26 +263,11 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase {
public function testReferences2() {
$user = new User();
$user->Phonenumber[0]->phonenumber = '123 123';
$this->assertEqual($user->Phonenumber[0]->entity_id, $user);
$ref = $user->Phonenumber[0]->entity_id;
$this->assertEqual($ref->getOid(), $user->getOid());
}
public function testCountRelated() {
$user = $this->connection->getTable('Entity')->find(5);
$c = $user->countRelated('Phonenumber');
$this->assertEqual($c, 3);
$user = $this->connection->getTable('Entity')->find(7);
$c = $user->countRelated('Phonenumber');
$this->assertEqual($c, 1);
$user = $this->connection->getTable('Entity')->find(8);
$c = $user->countRelated('Phonenumber');
$this->assertEqual($c, 3);
}
public function testUpdatingWithNullValue() {
$user = $this->connection->getTable('User')->find(5);
$user->name = null;
@ -292,20 +276,21 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase {
$user->save();
$this->assertEqual($user->name, null);
$this->connection->clear();
$user = $this->connection->getTable('User')->find(5);
$this->assertEqual($user->name, null);
}
public function testSerialize() {
$user = $this->connection->getTable("User")->find(4);
$str = serialize($user);
$user2 = unserialize($str);
$this->assertTrue($user2 instanceof User);
$this->assertEqual($user2->obtainIdentifier(),$user->obtainIdentifier());
$this->assertEqual($user2->obtainIdentifier(), $user->obtainIdentifier());
}
public function testCallback() {
@ -316,6 +301,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase {
$user->call('substr', 'name', 0, 1);
$this->assertEqual($user->name, 'z');
}
public function testCompositePK() {
$record = new EntityReference();
$this->assertEqual($record->getTable()->getIdentifier(), array("entity1","entity2"));
@ -373,20 +359,19 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase {
$record->entity1 = 2;
$record->save();
$coll = $this->connection->query("FROM EntityReference-b");
$coll = $this->connection->query("FROM EntityReference");
$this->assertTrue($coll[0] instanceof EntityReference);
$this->assertEqual($coll[0]->state(), Doctrine_Record::STATE_CLEAN);
$this->assertTrue($coll[1] instanceof EntityReference);
$this->assertEqual($coll[1]->state(), Doctrine_Record::STATE_CLEAN);
$coll = $this->connection->query("FROM EntityReference-b WHERE EntityReference.entity2 = 5");
$coll = $this->connection->query("FROM EntityReference WHERE EntityReference.entity2 = 5");
$this->assertEqual($coll->count(), 1);
}
public function testManyToManyTreeStructure() {
$task = $this->connection->create("Task");
$this->assertEqual($task->getTable()->getAlias("Resource"), "ResourceAlias");
$task->name = "Task 1";
$task->ResourceAlias[0]->name = "Resource 1";
@ -434,7 +419,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase {
$account->amount = 1000;
$this->assertTrue($account instanceof Account);
$this->assertEqual($account->state(), Doctrine_Record::STATE_TDIRTY);
$this->assertEqual($account->entity_id, $user);
$this->assertEqual($account->entity_id->getOid(), $user->getOid());
$this->assertEqual($account->amount, 1000);
$this->assertEqual($user->name, "Richard Linklater");
@ -539,7 +524,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase {
$this->connection->flush();
$elements = $this->connection->query("FROM Element-l");
$elements = $this->connection->query("FROM Element");
$this->assertEqual($elements->count(), 5);
$e = $e->getTable()->find(1);
@ -564,38 +549,38 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase {
public function testUniqueKeyComponent() {
$e = new Error();
$e->message = "user error";
$e->message = 'user error';
$e->file_md5 = md5(0);
$e->code = 1;
// ADDING NEW RECORD
$this->assertEqual($e->code,1);
$this->assertEqual($e->file_md5, md5(0));
$this->assertEqual($e->message, "user error");
$this->assertEqual($e->message, 'user error');
$e2 = new Error();
$e2->message = "user error2";
$e2->message = 'user error2';
$e2->file_md5 = md5(1);
$e2->code = 2;
$this->assertEqual($e2->code,2);
$this->assertEqual($e2->file_md5, md5(1));
$this->assertEqual($e2->message, "user error2");
$this->assertEqual($e2->message, 'user error2');
$fk = $e->getTable()->getRelation("Description");
$fk = $e->getTable()->getRelation('Description');
$this->assertTrue($fk instanceof Doctrine_Relation_ForeignKey);
$this->assertEqual($fk->getLocal(),"file_md5");
$this->assertEqual($fk->getForeign(),"file_md5");
$this->assertEqual($fk->getLocal(),'file_md5');
$this->assertEqual($fk->getForeign(),'file_md5');
$this->assertTrue($fk->getTable() instanceof Doctrine_Table);
$e->Description[0]->description = "This is the 1st description";
$e->Description[1]->description = "This is the 2nd description";
$this->assertEqual($e->Description[0]->description, "This is the 1st description");
$this->assertEqual($e->Description[1]->description, "This is the 2nd description");
$e->Description[0]->description = 'This is the 1st description';
$e->Description[1]->description = 'This is the 2nd description';
$this->assertEqual($e->Description[0]->description, 'This is the 1st description');
$this->assertEqual($e->Description[1]->description, 'This is the 2nd description');
$this->assertEqual($e->Description[0]->file_md5, $e->file_md5);
$this->assertEqual($e->Description[1]->file_md5, $e->file_md5);
$this->assertEqual($e2->Description[0]->description, null);
$this->assertEqual($e2->Description[1]->description, null);
$this->assertEqual($e2->Description[0]->file_md5, $e2->file_md5);
@ -603,39 +588,39 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase {
$e->save();
$coll = $this->connection->query("FROM Error-I");
$coll = $this->connection->query('FROM Error');
$e = $coll[0];
$this->assertEqual($e->code,1);
$this->assertEqual($e->file_md5, md5(0));
$this->assertEqual($e->message, "user error");
$this->assertEqual($e->message, 'user error');
$this->assertTrue($e->Description instanceof Doctrine_Collection);
$this->assertTrue($e->Description[0] instanceof Description);
$this->assertTrue($e->Description[1] instanceof Description);
$this->assertEqual($e->Description[0]->description, "This is the 1st description");
$this->assertEqual($e->Description[1]->description, "This is the 2nd description");
$this->assertEqual($e->Description[0]->description, 'This is the 1st description');
$this->assertEqual($e->Description[1]->description, 'This is the 2nd description');
// UPDATING
$e->code = 2;
$e->message = "changed message";
$e->Description[0]->description = "1st changed description";
$e->Description[1]->description = "2nd changed description";
$e->message = 'changed message';
$e->Description[0]->description = '1st changed description';
$e->Description[1]->description = '2nd changed description';
$this->assertEqual($e->code,2);
$this->assertEqual($e->message,"changed message");
$this->assertEqual($e->Description[0]->description, "1st changed description");
$this->assertEqual($e->Description[1]->description, "2nd changed description");
$this->assertEqual($e->message,'changed message');
$this->assertEqual($e->Description[0]->description, '1st changed description');
$this->assertEqual($e->Description[1]->description, '2nd changed description');
$e->save();
$this->assertEqual($e->code,2);
$this->assertEqual($e->message,"changed message");
$this->assertEqual($e->Description[0]->description, "1st changed description");
$this->assertEqual($e->Description[1]->description, "2nd changed description");
$this->assertEqual($e->message,'changed message');
$this->assertEqual($e->Description[0]->description, '1st changed description');
$this->assertEqual($e->Description[1]->description, '2nd changed description');
}
public function testInsert() {
@ -702,14 +687,12 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase {
public function testReferences()
{
$user = $this->objTable->find(5);
$pf = $this->connection->getTable("Phonenumber");
$user = $this->connection->getTable('User')->find(5);
$this->assertTrue($user->Phonenumber instanceof Doctrine_Collection);
$this->assertEqual($user->Phonenumber->count(), 3);
$coll = new Doctrine_Collection($pf);
$coll = new Doctrine_Collection('Phonenumber');
$user->Phonenumber = $coll;
$this->assertEqual($user->Phonenumber->count(), 0);
@ -720,7 +703,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase {
$user = $this->objTable->find(5);
$this->assertEqual($user->Phonenumber->count(), 0);
$this->assertEqual(get_class($user->Phonenumber), "Doctrine_Collection_Immediate");
$this->assertEqual(get_class($user->Phonenumber), 'Doctrine_Collection');
$user->Phonenumber[0]->phonenumber;
$this->assertEqual($user->Phonenumber->count(), 1);
@ -772,7 +755,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase {
// REPLACING ONE-TO-MANY REFERENCE
unset($coll);
$coll = new Doctrine_Collection($pf);
$coll = new Doctrine_Collection('Phonenumber');
$coll[0]->phonenumber = "123 123";
$coll["home"]->phonenumber = "444 444";
$coll["work"]->phonenumber = "444 444";
@ -832,6 +815,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase {
$this->assertTrue($user->Phonenumber->count() == 0);
}
public function testSaveAssociations() {
$user = $this->objTable->find(5);
@ -845,55 +829,62 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase {
$record = $gf->find(1);
$record2 = $gf->find(2);
$user->Group[0] = $record;
$user->Group[1] = $record2;
$user->Group[1] = $record;
$user->Group[2] = $record2;
$this->assertTrue($user->Group->count() == 2);
$this->assertTrue($user->Group->count() == 3);
$user->save();
$coll = $user->Group;
// UNSETTING ASSOCIATED REFERENCES
unset($user);
$user = $this->objTable->find(5);
$this->assertTrue($user->Group->count() == 2);
unset($user->Group[0]);
$this->assertTrue($user->Group->count() == 1);
$this->assertTrue($user->Group->count() == 3);
unset($user->Group[1]);
$this->assertTrue($user->Group->count() == 0);
$this->assertTrue($user->Group->count() == 2);
unset($user->Group[2]);
$this->assertTrue($user->Group->count() == 1);
$user->save();
$this->assertTrue($user->Group->count() == 0);
$this->assertTrue($user->Group->count() == 1);
unset($user);
// CHECKING THE PERSISTENCE OF UNSET ASSOCIATED REFERENCES
$this->connection->clear();
$user = $this->objTable->find(5);
$this->assertTrue($user->Group->count() == 0);
$this->assertEqual($user->Group->count(), 1);
// REPLACING OLD ASSOCIATED REFERENCE
$user->Group[0] = $record;
$user->Group[1] = $record;
$user->save();
$user->Group[0] = $record2;
$user->Group[1] = $record2;
$user->save();
$this->assertEqual($user->Group->count(), 1);
$this->assertEqual($user->Group[0]->obtainIdentifier(), $record2->obtainIdentifier());
$this->assertFalse($user->Group[0]->obtainIdentifier() == $record->obtainIdentifier());
$this->assertEqual($user->Group->count(), 2);
$this->assertEqual($user->Group[1]->obtainIdentifier(), $record2->obtainIdentifier());
$this->assertFalse($user->Group[1]->obtainIdentifier() == $record->obtainIdentifier());
$user->Group[0] = $record;
$user->Group[1] = $gf->find(3);
$record = $gf->find(3);
$user->Group[1] = $record;
$user->save();
$this->assertEqual($user->Group->count(), 2);
@ -913,6 +904,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase {
$user = new User();
$this->assertTrue($user->getTable()->getRelation("Groupuser") instanceof Doctrine_Relation_ForeignKey);
$this->assertTrue($user->Groupuser instanceof Doctrine_Collection);
$this->assertTrue($user->Groupuser[0] instanceof Groupuser);
@ -932,6 +924,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase {
$user->refresh();
$this->assertEqual($user->Groupuser[0]->added, $t1);
$this->assertEqual($user->Groupuser[1]->added, $t2);
}