2006-04-14 00:37:28 +04:00
|
|
|
<?php
|
2006-06-07 00:37:56 +04:00
|
|
|
require_once("UnitTestCase.php");
|
2006-04-14 00:37:28 +04:00
|
|
|
|
|
|
|
class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
|
2006-09-03 23:20:02 +04:00
|
|
|
|
2006-06-18 02:46:03 +04:00
|
|
|
public function prepareTables() {
|
|
|
|
$this->tables[] = "enumTest";
|
|
|
|
parent::prepareTables();
|
|
|
|
}
|
2006-09-12 01:46:01 +04:00
|
|
|
|
2006-09-09 03:20:51 +04:00
|
|
|
public function testJoinTableSelfReferencingInsertingData() {
|
2006-06-30 03:04:39 +04:00
|
|
|
$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]->getState(), Doctrine_Record::STATE_TCLEAN);
|
|
|
|
$this->assertEqual($e->Entity[1]->getState(), Doctrine_Record::STATE_TCLEAN);
|
|
|
|
|
|
|
|
$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[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]->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[0]->getState(), Doctrine_Record::STATE_TDIRTY);
|
|
|
|
$this->assertEqual($e->Entity[1]->getState(), Doctrine_Record::STATE_TDIRTY);
|
|
|
|
|
2006-09-01 02:00:44 +04:00
|
|
|
$count = count($this->dbh);
|
|
|
|
|
2006-06-30 03:04:39 +04:00
|
|
|
$e->save();
|
|
|
|
|
2006-09-01 02:00:44 +04:00
|
|
|
$this->assertEqual(($count + 13), $this->dbh->count());
|
|
|
|
$this->assertEqual($e->getState(), Doctrine_Record::STATE_CLEAN);
|
|
|
|
|
2006-06-30 03:04:39 +04:00
|
|
|
$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]->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[0]->getState(), Doctrine_Record::STATE_CLEAN);
|
|
|
|
$this->assertEqual($e->Entity[1]->getState(), Doctrine_Record::STATE_CLEAN);
|
2006-09-09 03:20:51 +04:00
|
|
|
|
2006-09-01 02:00:44 +04:00
|
|
|
$this->assertTrue(is_numeric($e->id));
|
2006-06-30 03:04:39 +04:00
|
|
|
|
2006-09-09 03:20:51 +04:00
|
|
|
$result = $this->dbh->query("SELECT * FROM entity_reference")->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
$this->assertEqual(count($result), 6);
|
|
|
|
|
2006-09-13 01:36:36 +04:00
|
|
|
//$stmt = $this->dbh->prepare($q);
|
2006-09-09 03:20:51 +04:00
|
|
|
|
2006-09-13 01:36:36 +04:00
|
|
|
//$stmt->execute(array(18));
|
|
|
|
//$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
//print_r($result);
|
2006-09-09 03:20:51 +04:00
|
|
|
|
|
|
|
$this->connection->clear();
|
|
|
|
|
2006-07-10 13:18:09 +04:00
|
|
|
$e = $e->getTable()->find($e->id);
|
2006-09-01 02:00:44 +04:00
|
|
|
|
2006-09-09 03:20:51 +04:00
|
|
|
$count = count($this->dbh);
|
|
|
|
|
2006-09-01 02:00:44 +04:00
|
|
|
$this->assertTrue($e instanceof Entity);
|
|
|
|
|
2006-06-30 03:04:39 +04:00
|
|
|
$this->assertTrue($e->Entity[0] instanceof Entity);
|
|
|
|
$this->assertTrue($e->Entity[1] instanceof Entity);
|
2006-09-12 01:46:01 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
2006-09-09 03:20:51 +04:00
|
|
|
$this->assertEqual(count($this->dbh), ($count + 1));
|
2006-06-30 03:04:39 +04:00
|
|
|
|
|
|
|
$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");
|
|
|
|
|
2006-09-09 03:20:51 +04:00
|
|
|
$this->assertEqual(count($this->dbh), ($count + 2));
|
|
|
|
|
2006-06-30 03:04:39 +04:00
|
|
|
$this->assertEqual($e->Entity[1]->Entity[0]->name, "Friend 2 1");
|
|
|
|
$this->assertEqual($e->Entity[1]->Entity[1]->name, "Friend 2 2");
|
|
|
|
|
2006-09-09 03:20:51 +04:00
|
|
|
$this->assertEqual(count($this->dbh), ($count + 3));
|
|
|
|
|
2006-06-30 03:04:39 +04:00
|
|
|
$this->assertEqual($e->Entity[0]->getState(), Doctrine_Record::STATE_CLEAN);
|
|
|
|
$this->assertEqual($e->Entity[1]->getState(), Doctrine_Record::STATE_CLEAN);
|
|
|
|
|
2006-08-22 03:20:33 +04:00
|
|
|
$coll = $this->connection->query("FROM Entity WHERE Entity.name = 'Friend 1'");
|
2006-06-30 03:04:39 +04:00
|
|
|
$this->assertEqual($coll->count(), 1);
|
|
|
|
$this->assertEqual($coll[0]->getState(), Doctrine_Record::STATE_CLEAN);
|
|
|
|
|
|
|
|
$this->assertEqual($coll[0]->name, "Friend 1");
|
|
|
|
|
2006-08-22 03:20:33 +04:00
|
|
|
$query = new Doctrine_Query($this->connection);
|
2006-06-30 03:04:39 +04:00
|
|
|
|
|
|
|
$query->from("Entity.Entity")->where("Entity.Entity.name = 'Friend 1 1'");
|
|
|
|
|
|
|
|
$coll = $query->execute();
|
|
|
|
|
|
|
|
$this->assertEqual($coll->count(), 1);
|
|
|
|
}
|
2006-09-12 01:46:01 +04:00
|
|
|
|
|
|
|
|
2006-09-09 03:20:51 +04:00
|
|
|
public function testToArray() {
|
|
|
|
$user = new User();
|
|
|
|
|
|
|
|
$a = $user->toArray();
|
|
|
|
|
|
|
|
$this->assertTrue(is_array($a));
|
|
|
|
$this->assertTrue(array_key_exists('name', $a));
|
|
|
|
$this->assertEqual($a['name'], null);
|
|
|
|
$this->assertTrue(array_key_exists('id', $a));
|
|
|
|
$this->assertEqual($a['id'], null);
|
|
|
|
|
|
|
|
$user->name = 'Someone';
|
|
|
|
|
|
|
|
$user->save();
|
|
|
|
|
|
|
|
$a = $user->toArray();
|
|
|
|
|
|
|
|
$this->assertTrue(is_array($a));
|
|
|
|
$this->assertTrue(array_key_exists('name', $a));
|
|
|
|
$this->assertEqual($a['name'], 'Someone');
|
|
|
|
$this->assertTrue(array_key_exists('id', $a));
|
|
|
|
$this->assertTrue(is_numeric($a['id']));
|
|
|
|
|
|
|
|
$user->refresh();
|
|
|
|
|
|
|
|
$a = $user->toArray();
|
|
|
|
|
|
|
|
$this->assertTrue(is_array($a));
|
|
|
|
$this->assertTrue(array_key_exists('name', $a));
|
|
|
|
$this->assertEqual($a['name'], 'Someone');
|
|
|
|
$this->assertTrue(array_key_exists('id', $a));
|
|
|
|
$this->assertTrue(is_numeric($a['id']));
|
|
|
|
$this->connection->clear();
|
|
|
|
$user = $user->getTable()->find($user->id);
|
|
|
|
|
|
|
|
$a = $user->toArray();
|
|
|
|
|
|
|
|
$this->assertTrue(is_array($a));
|
|
|
|
$this->assertTrue(array_key_exists('name', $a));
|
|
|
|
$this->assertEqual($a['name'], 'Someone');
|
|
|
|
$this->assertTrue(array_key_exists('id', $a));
|
|
|
|
$this->assertTrue(is_numeric($a['id']));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testReferences2() {
|
|
|
|
$user = new User();
|
|
|
|
$user->Phonenumber[0]->phonenumber = '123 123';
|
|
|
|
$this->assertEqual($user->Phonenumber[0]->entity_id, $user);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-26 03:50:55 +04:00
|
|
|
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);
|
|
|
|
}
|
2006-08-26 00:13:37 +04:00
|
|
|
public function testUpdatingWithNullValue() {
|
|
|
|
$user = $this->connection->getTable('User')->find(5);
|
|
|
|
$user->name = null;
|
|
|
|
$this->assertEqual($user->name, null);
|
|
|
|
|
|
|
|
$user->save();
|
|
|
|
|
|
|
|
$this->assertEqual($user->name, null);
|
|
|
|
|
|
|
|
$this->connection->clear();
|
|
|
|
|
|
|
|
$user = $this->connection->getTable('User')->find(5);
|
|
|
|
$this->assertEqual($user->name, null);
|
|
|
|
|
|
|
|
}
|
2006-08-25 22:17:20 +04:00
|
|
|
|
|
|
|
public function testDateTimeType() {
|
|
|
|
$date = new DateTest();
|
2006-08-26 00:13:37 +04:00
|
|
|
|
2006-08-25 22:17:20 +04:00
|
|
|
|
2006-09-03 23:20:02 +04:00
|
|
|
}
|
|
|
|
|
2006-06-18 02:46:03 +04:00
|
|
|
public function testEnumType() {
|
2006-09-03 23:20:02 +04:00
|
|
|
|
|
|
|
$enum = new EnumTest();
|
|
|
|
$enum->status = "open";
|
|
|
|
$this->assertEqual($enum->status, "open");
|
|
|
|
$enum->save();
|
|
|
|
$this->assertEqual($enum->status, "open");
|
|
|
|
$enum->refresh();
|
|
|
|
$this->assertEqual($enum->status, "open");
|
|
|
|
|
|
|
|
$enum->status = "closed";
|
|
|
|
|
|
|
|
$this->assertEqual($enum->status, "closed");
|
|
|
|
|
|
|
|
$enum->save();
|
|
|
|
$this->assertEqual($enum->status, "closed");
|
|
|
|
|
|
|
|
$enum->refresh();
|
|
|
|
$this->assertEqual($enum->status, "closed");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testEnumTypeWithCaseConversion() {
|
|
|
|
$this->dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_UPPER);
|
|
|
|
|
2006-06-18 02:46:03 +04:00
|
|
|
$enum = new EnumTest();
|
2006-09-03 23:20:02 +04:00
|
|
|
|
2006-06-18 02:46:03 +04:00
|
|
|
$enum->status = "open";
|
|
|
|
$this->assertEqual($enum->status, "open");
|
2006-09-03 23:20:02 +04:00
|
|
|
|
2006-06-18 02:46:03 +04:00
|
|
|
$enum->save();
|
|
|
|
$this->assertEqual($enum->status, "open");
|
2006-09-03 23:20:02 +04:00
|
|
|
|
2006-06-18 02:46:03 +04:00
|
|
|
$enum->refresh();
|
|
|
|
$this->assertEqual($enum->status, "open");
|
|
|
|
|
|
|
|
$enum->status = "closed";
|
|
|
|
|
|
|
|
$this->assertEqual($enum->status, "closed");
|
|
|
|
|
|
|
|
$enum->save();
|
|
|
|
$this->assertEqual($enum->status, "closed");
|
|
|
|
|
|
|
|
$enum->refresh();
|
|
|
|
$this->assertEqual($enum->status, "closed");
|
2006-09-13 01:36:36 +04:00
|
|
|
|
|
|
|
$this->dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL);
|
2006-06-18 02:46:03 +04:00
|
|
|
}
|
2006-09-03 23:20:02 +04:00
|
|
|
public function testFailingRefresh() {
|
|
|
|
$enum = $this->connection->getTable('EnumTest')->find(1);
|
|
|
|
|
|
|
|
$this->dbh->query('DELETE FROM enum_test WHERE id = 1');
|
|
|
|
|
|
|
|
$f = false;
|
|
|
|
try {
|
|
|
|
$enum->refresh();
|
|
|
|
} catch(Doctrine_Record_Exception $e) {
|
|
|
|
$f = true;
|
|
|
|
}
|
|
|
|
$this->assertTrue($f);
|
2006-09-13 01:36:36 +04:00
|
|
|
}
|
|
|
|
|
2006-06-03 13:10:43 +04:00
|
|
|
public function testSerialize() {
|
2006-08-22 03:20:33 +04:00
|
|
|
$user = $this->connection->getTable("User")->find(4);
|
2006-06-05 13:57:53 +04:00
|
|
|
$str = serialize($user);
|
|
|
|
$user2 = unserialize($str);
|
|
|
|
|
|
|
|
$this->assertTrue($user2 instanceof User);
|
|
|
|
$this->assertEqual($user2->getID(),$user->getID());
|
2006-06-03 13:10:43 +04:00
|
|
|
}
|
|
|
|
|
2006-05-31 02:47:01 +04:00
|
|
|
public function testCallback() {
|
|
|
|
$user = new User();
|
|
|
|
$user->name = " zYne ";
|
|
|
|
$user->trim('name');
|
|
|
|
$this->assertEqual($user->name, 'zYne');
|
2006-05-31 12:46:44 +04:00
|
|
|
$user->substr('name',0,1);
|
|
|
|
$this->assertEqual($user->name, 'z');
|
2006-05-31 02:47:01 +04:00
|
|
|
}
|
2006-06-03 13:10:43 +04:00
|
|
|
|
2006-05-17 13:37:41 +04:00
|
|
|
|
2006-05-13 12:37:52 +04:00
|
|
|
|
2006-05-17 00:37:26 +04:00
|
|
|
public function testCompositePK() {
|
|
|
|
$record = new EntityReference();
|
|
|
|
$this->assertEqual($record->getTable()->getIdentifier(), array("entity1","entity2"));
|
|
|
|
$this->assertEqual($record->getTable()->getIdentifierType(), Doctrine_Identifier::COMPOSITE);
|
|
|
|
$this->assertEqual($record->getID(), array("entity1" => null, "entity2" => null));
|
|
|
|
$this->assertEqual($record->getState(), Doctrine_Record::STATE_TCLEAN);
|
|
|
|
|
|
|
|
$record->entity1 = 3;
|
|
|
|
$record->entity2 = 4;
|
|
|
|
$this->assertEqual($record->entity2, 4);
|
|
|
|
$this->assertEqual($record->entity1, 3);
|
|
|
|
$this->assertEqual($record->getState(), Doctrine_Record::STATE_TDIRTY);
|
|
|
|
$this->assertEqual($record->getID(), array("entity1" => null, "entity2" => null));
|
|
|
|
|
|
|
|
$record->save();
|
|
|
|
$this->assertEqual($record->getState(), Doctrine_Record::STATE_CLEAN);
|
|
|
|
$this->assertEqual($record->entity2, 4);
|
|
|
|
$this->assertEqual($record->entity1, 3);
|
|
|
|
$this->assertEqual($record->getID(), array("entity1" => 3, "entity2" => 4));
|
|
|
|
|
|
|
|
$record = $record->getTable()->find($record->getID());
|
|
|
|
$this->assertEqual($record->getState(), Doctrine_Record::STATE_CLEAN);
|
|
|
|
$this->assertEqual($record->entity2, 4);
|
|
|
|
$this->assertEqual($record->entity1, 3);
|
|
|
|
|
|
|
|
$this->assertEqual($record->getID(), array("entity1" => 3, "entity2" => 4));
|
|
|
|
|
|
|
|
$record->entity2 = 5;
|
|
|
|
$record->entity1 = 2;
|
|
|
|
$this->assertEqual($record->getState(), Doctrine_Record::STATE_DIRTY);
|
|
|
|
$this->assertEqual($record->entity2, 5);
|
|
|
|
$this->assertEqual($record->entity1, 2);
|
|
|
|
$this->assertEqual($record->getID(), array("entity1" => 3, "entity2" => 4));
|
|
|
|
|
|
|
|
$record->save();
|
|
|
|
$this->assertEqual($record->getState(), Doctrine_Record::STATE_CLEAN);
|
|
|
|
$this->assertEqual($record->entity2, 5);
|
|
|
|
$this->assertEqual($record->entity1, 2);
|
|
|
|
$this->assertEqual($record->getID(), array("entity1" => 2, "entity2" => 5));
|
|
|
|
$record = $record->getTable()->find($record->getID());
|
|
|
|
|
|
|
|
$this->assertEqual($record->getState(), Doctrine_Record::STATE_CLEAN);
|
|
|
|
$this->assertEqual($record->entity2, 5);
|
|
|
|
$this->assertEqual($record->entity1, 2);
|
|
|
|
$this->assertEqual($record->getID(), array("entity1" => 2, "entity2" => 5));
|
2006-05-17 13:37:41 +04:00
|
|
|
|
|
|
|
$record->refresh();
|
|
|
|
$this->assertEqual($record->getState(), Doctrine_Record::STATE_CLEAN);
|
|
|
|
$this->assertEqual($record->entity2, 5);
|
|
|
|
$this->assertEqual($record->entity1, 2);
|
|
|
|
$this->assertEqual($record->getID(), array("entity1" => 2, "entity2" => 5));
|
|
|
|
|
|
|
|
$record = new EntityReference();
|
|
|
|
$record->entity2 = 6;
|
|
|
|
$record->entity1 = 2;
|
|
|
|
$record->save();
|
|
|
|
|
2006-08-22 03:20:33 +04:00
|
|
|
$coll = $this->connection->query("FROM EntityReference-b");
|
2006-05-17 13:37:41 +04:00
|
|
|
$this->assertTrue($coll[0] instanceof EntityReference);
|
|
|
|
$this->assertEqual($coll[0]->getState(), Doctrine_Record::STATE_CLEAN);
|
|
|
|
$this->assertTrue($coll[1] instanceof EntityReference);
|
|
|
|
$this->assertEqual($coll[1]->getState(), Doctrine_Record::STATE_CLEAN);
|
|
|
|
|
2006-08-22 03:20:33 +04:00
|
|
|
$coll = $this->connection->query("FROM EntityReference-b WHERE EntityReference.entity2 = 5");
|
2006-05-17 13:37:41 +04:00
|
|
|
$this->assertEqual($coll->count(), 1);
|
2006-05-17 00:37:26 +04:00
|
|
|
}
|
|
|
|
|
2006-04-28 00:24:59 +04:00
|
|
|
public function testManyToManyTreeStructure() {
|
2006-05-19 00:44:02 +04:00
|
|
|
|
2006-08-22 03:20:33 +04:00
|
|
|
$task = $this->connection->create("Task");
|
2006-05-17 00:37:26 +04:00
|
|
|
$this->assertEqual($task->getTable()->getAlias("Resource"), "ResourceAlias");
|
2006-04-28 00:24:59 +04:00
|
|
|
|
|
|
|
$task->name = "Task 1";
|
2006-05-17 00:37:26 +04:00
|
|
|
$task->ResourceAlias[0]->name = "Resource 1";
|
2006-04-28 00:24:59 +04:00
|
|
|
|
2006-08-22 03:20:33 +04:00
|
|
|
$this->connection->flush();
|
2006-05-17 00:37:26 +04:00
|
|
|
|
|
|
|
$this->assertTrue($task->ResourceAlias[0] instanceof Resource);
|
|
|
|
$this->assertEqual($task->ResourceAlias[0]->name, "Resource 1");
|
2006-04-28 00:24:59 +04:00
|
|
|
$this->assertEqual($this->dbh->query("SELECT COUNT(*) FROM assignment")->fetch(PDO::FETCH_NUM),array(1));
|
|
|
|
|
|
|
|
$task = new Task();
|
|
|
|
$this->assertTrue($task instanceof Task);
|
|
|
|
$this->assertEqual($task->getState(), Doctrine_Record::STATE_TCLEAN);
|
2006-05-13 12:37:52 +04:00
|
|
|
$this->assertTrue($task->Subtask[0] instanceof Task);
|
2006-04-28 00:24:59 +04:00
|
|
|
|
2006-05-19 00:44:02 +04:00
|
|
|
//$this->assertEqual($task->Subtask[0]->getState(), Doctrine_Record::STATE_TDIRTY);
|
2006-05-17 00:37:26 +04:00
|
|
|
$this->assertTrue($task->ResourceAlias[0] instanceof Resource);
|
|
|
|
$this->assertEqual($task->ResourceAlias[0]->getState(), Doctrine_Record::STATE_TCLEAN);
|
2006-04-28 00:24:59 +04:00
|
|
|
|
|
|
|
$task->name = "Task 1";
|
2006-05-17 00:37:26 +04:00
|
|
|
$task->ResourceAlias[0]->name = "Resource 1";
|
2006-05-13 12:37:52 +04:00
|
|
|
$task->Subtask[0]->name = "Subtask 1";
|
2006-04-28 00:24:59 +04:00
|
|
|
|
|
|
|
$this->assertEqual($task->name, "Task 1");
|
2006-05-17 00:37:26 +04:00
|
|
|
$this->assertEqual($task->ResourceAlias[0]->name, "Resource 1");
|
|
|
|
$this->assertEqual($task->ResourceAlias->count(), 1);
|
2006-05-13 12:37:52 +04:00
|
|
|
$this->assertEqual($task->Subtask[0]->name, "Subtask 1");
|
2006-04-28 00:24:59 +04:00
|
|
|
|
2006-08-22 03:20:33 +04:00
|
|
|
$this->connection->flush();
|
2006-05-17 00:37:26 +04:00
|
|
|
|
2006-04-28 00:24:59 +04:00
|
|
|
$task = $task->getTable()->find($task->getID());
|
|
|
|
|
|
|
|
$this->assertEqual($task->name, "Task 1");
|
2006-05-17 00:37:26 +04:00
|
|
|
$this->assertEqual($task->ResourceAlias[0]->name, "Resource 1");
|
|
|
|
$this->assertEqual($task->ResourceAlias->count(), 1);
|
2006-05-15 16:15:20 +04:00
|
|
|
$this->assertEqual($task->Subtask[0]->name, "Subtask 1");
|
2006-04-28 00:24:59 +04:00
|
|
|
|
2006-05-17 00:37:26 +04:00
|
|
|
}
|
2006-04-14 14:20:19 +04:00
|
|
|
|
2006-04-21 12:39:09 +04:00
|
|
|
public function testOne2OneForeign() {
|
|
|
|
|
|
|
|
$user = new User();
|
|
|
|
$user->name = "Richard Linklater";
|
|
|
|
$account = $user->Account;
|
|
|
|
$account->amount = 1000;
|
|
|
|
$this->assertTrue($account instanceof Account);
|
|
|
|
$this->assertEqual($account->getState(), Doctrine_Record::STATE_TDIRTY);
|
|
|
|
$this->assertEqual($account->entity_id, $user);
|
|
|
|
$this->assertEqual($account->amount, 1000);
|
|
|
|
$this->assertEqual($user->name, "Richard Linklater");
|
|
|
|
|
|
|
|
$user->save();
|
|
|
|
|
|
|
|
$user->refresh();
|
|
|
|
$account = $user->Account;
|
|
|
|
$this->assertTrue($account instanceof Account);
|
|
|
|
$this->assertEqual($account->getState(), Doctrine_Record::STATE_CLEAN);
|
2006-07-10 13:18:09 +04:00
|
|
|
$this->assertEqual($account->entity_id, $user->id);
|
2006-04-21 12:39:09 +04:00
|
|
|
$this->assertEqual($account->amount, 1000);
|
|
|
|
$this->assertEqual($user->name, "Richard Linklater");
|
|
|
|
|
|
|
|
|
|
|
|
$user = new User();
|
|
|
|
$user->name = "John Rambo";
|
|
|
|
$account = $user->Account;
|
|
|
|
$account->amount = 2000;
|
|
|
|
$this->assertEqual($account->getTable()->getColumnNames(), array("id","entity_id","amount"));
|
|
|
|
|
2006-08-22 03:20:33 +04:00
|
|
|
$this->connection->flush();
|
2006-04-21 12:39:09 +04:00
|
|
|
$this->assertEqual($user->getState(), Doctrine_Record::STATE_CLEAN);
|
|
|
|
$this->assertTrue($account instanceof Account);
|
|
|
|
|
|
|
|
$this->assertEqual($account->getTable()->getColumnNames(), array("id","entity_id","amount"));
|
2006-07-10 13:18:09 +04:00
|
|
|
$this->assertEqual($account->entity_id, $user->id);
|
2006-04-21 12:39:09 +04:00
|
|
|
$this->assertEqual($account->amount, 2000);
|
|
|
|
|
|
|
|
|
2006-07-10 13:18:09 +04:00
|
|
|
$user = $user->getTable()->find($user->id);
|
2006-04-21 12:39:09 +04:00
|
|
|
$this->assertEqual($user->getState(), Doctrine_Record::STATE_CLEAN);
|
|
|
|
|
|
|
|
|
|
|
|
$account = $user->Account;
|
|
|
|
$this->assertTrue($account instanceof Account);
|
|
|
|
|
|
|
|
$this->assertEqual($account->getState(), Doctrine_Record::STATE_CLEAN);
|
|
|
|
$this->assertEqual($account->getTable()->getColumnNames(), array("id","entity_id","amount"));
|
|
|
|
|
2006-07-10 13:18:09 +04:00
|
|
|
$this->assertEqual($account->entity_id, $user->id);
|
2006-04-21 12:39:09 +04:00
|
|
|
$this->assertEqual($account->amount, 2000);
|
|
|
|
$this->assertEqual($user->name, "John Rambo");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-04-14 00:37:28 +04:00
|
|
|
public function testGet() {
|
|
|
|
$user = new User();
|
|
|
|
$user->name = "Jack Daniels";
|
|
|
|
$this->assertEqual($user->name, "Jack Daniels");
|
|
|
|
$this->assertEqual($user->created, null);
|
|
|
|
$this->assertEqual($user->updated, null);
|
|
|
|
$user->save();
|
|
|
|
$id = $user->getID();
|
|
|
|
$user = $user->getTable()->find($id);
|
|
|
|
$this->assertEqual($user->name, "Jack Daniels");
|
|
|
|
$this->assertEqual($user->created, null);
|
|
|
|
$this->assertEqual($user->updated, null);
|
2006-05-15 16:15:20 +04:00
|
|
|
$this->assertEqual($user->getTable()->getData(), array());
|
2006-04-14 00:37:28 +04:00
|
|
|
|
|
|
|
}
|
2006-05-15 16:15:20 +04:00
|
|
|
|
2006-04-14 00:37:28 +04:00
|
|
|
public function testNewOperator() {
|
2006-08-22 03:20:33 +04:00
|
|
|
$table = $this->connection->getTable("User");
|
2006-05-15 16:15:20 +04:00
|
|
|
|
2006-08-22 03:20:33 +04:00
|
|
|
$this->assertEqual($this->connection->getTable("User")->getData(), array());
|
2006-04-14 00:37:28 +04:00
|
|
|
$user = new User();
|
2006-05-15 16:15:20 +04:00
|
|
|
$this->assertEqual(Doctrine_Lib::getRecordStateAsString($user->getState()), Doctrine_Lib::getRecordStateAsString(Doctrine_Record::STATE_TCLEAN));
|
2006-04-14 00:37:28 +04:00
|
|
|
$user->name = "John Locke";
|
|
|
|
|
|
|
|
$this->assertTrue($user->name,"John Locke");
|
|
|
|
$this->assertTrue($user->getState() == Doctrine_Record::STATE_TDIRTY);
|
|
|
|
$user->save();
|
|
|
|
$this->assertTrue($user->getState() == Doctrine_Record::STATE_CLEAN);
|
|
|
|
$this->assertTrue($user->name,"John Locke");
|
|
|
|
}
|
2006-05-13 12:37:52 +04:00
|
|
|
|
2006-04-14 00:37:28 +04:00
|
|
|
public function testTreeStructure() {
|
|
|
|
$e = new Element();
|
2006-05-13 12:37:52 +04:00
|
|
|
|
2006-08-31 13:04:14 +04:00
|
|
|
$fk = $e->getTable()->getRelation("Child");
|
2006-05-13 12:37:52 +04:00
|
|
|
$this->assertTrue($fk instanceof Doctrine_ForeignKey);
|
|
|
|
$this->assertEqual($fk->getType(), Doctrine_Relation::MANY_AGGREGATE);
|
|
|
|
$this->assertEqual($fk->getForeign(), "parent_id");
|
|
|
|
$this->assertEqual($fk->getLocal(), "id");
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-04-14 00:37:28 +04:00
|
|
|
$e->name = "parent";
|
2006-05-13 12:37:52 +04:00
|
|
|
$e->Child[0]->name = "child 1";
|
|
|
|
$e->Child[1]->name = "child 2";
|
2006-04-14 14:20:19 +04:00
|
|
|
|
2006-05-13 12:37:52 +04:00
|
|
|
$e->Child[1]->Child[0]->name = "child 1's child 1";
|
|
|
|
$e->Child[1]->Child[1]->name = "child 1's child 1";
|
2006-04-14 00:37:28 +04:00
|
|
|
|
|
|
|
$this->assertEqual($e->name,"parent");
|
|
|
|
|
2006-05-13 12:37:52 +04:00
|
|
|
$this->assertEqual($e->Child[0]->name,"child 1");
|
|
|
|
$this->assertEqual($e->Child[1]->name,"child 2");
|
|
|
|
$this->assertEqual($e->Child[1]->Child[0]->name,"child 1's child 1");
|
|
|
|
$this->assertEqual($e->Child[1]->Child[1]->name,"child 1's child 1");
|
2006-04-14 00:37:28 +04:00
|
|
|
|
2006-04-14 14:20:19 +04:00
|
|
|
|
|
|
|
|
2006-08-22 03:20:33 +04:00
|
|
|
$this->connection->flush();
|
|
|
|
$elements = $this->connection->query("FROM Element-l");
|
2006-06-03 13:10:43 +04:00
|
|
|
$this->assertEqual($elements->count(), 5);
|
2006-04-14 14:20:19 +04:00
|
|
|
|
|
|
|
$e = $e->getTable()->find(1);
|
2006-04-14 00:37:28 +04:00
|
|
|
$this->assertEqual($e->name,"parent");
|
2006-04-14 14:20:19 +04:00
|
|
|
|
2006-05-13 12:37:52 +04:00
|
|
|
$this->assertEqual($e->Child[0]->name,"child 1");
|
2006-04-14 14:20:19 +04:00
|
|
|
|
|
|
|
$c = $e->getTable()->find(2);
|
|
|
|
$this->assertEqual($c->name, "child 1");
|
|
|
|
|
2006-05-13 12:37:52 +04:00
|
|
|
$this->assertEqual($e->Child[0]->parent_id, 1);
|
|
|
|
$this->assertEqual($e->Child[0]->Parent->getID(), $e->getID());
|
2006-06-03 13:10:43 +04:00
|
|
|
|
2006-05-13 12:37:52 +04:00
|
|
|
|
|
|
|
$this->assertEqual($e->Child[1]->parent_id, 1);
|
|
|
|
$this->assertEqual($e->Child[1]->Child[0]->name,"child 1's child 1");
|
|
|
|
$this->assertEqual($e->Child[1]->Child[1]->name,"child 1's child 1");
|
|
|
|
$this->assertEqual($e->Child[1]->Child[0]->parent_id, 3);
|
|
|
|
$this->assertEqual($e->Child[1]->Child[1]->parent_id, 3);
|
2006-04-14 14:20:19 +04:00
|
|
|
|
2006-04-14 00:37:28 +04:00
|
|
|
}
|
2006-04-14 14:20:19 +04:00
|
|
|
|
2006-04-14 00:37:28 +04:00
|
|
|
public function testUniqueKeyComponent() {
|
|
|
|
$e = new Error();
|
|
|
|
$e->message = "user error";
|
|
|
|
$e->file_md5 = md5(0);
|
|
|
|
$e->code = 1;
|
|
|
|
|
2006-04-14 14:20:19 +04:00
|
|
|
// ADDING NEW RECORD
|
2006-04-14 00:37:28 +04:00
|
|
|
$this->assertEqual($e->code,1);
|
|
|
|
$this->assertEqual($e->file_md5, md5(0));
|
|
|
|
$this->assertEqual($e->message, "user error");
|
|
|
|
|
|
|
|
$e2 = new Error();
|
|
|
|
$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");
|
|
|
|
|
|
|
|
|
2006-08-31 13:04:14 +04:00
|
|
|
$fk = $e->getTable()->getRelation("Description");
|
2006-04-14 00:37:28 +04:00
|
|
|
$this->assertTrue($fk instanceof Doctrine_ForeignKey);
|
|
|
|
$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");
|
|
|
|
$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);
|
|
|
|
$this->assertEqual($e2->Description[1]->file_md5, $e2->file_md5);
|
|
|
|
|
|
|
|
$e->save();
|
2006-04-23 12:12:01 +04:00
|
|
|
|
2006-08-22 03:20:33 +04:00
|
|
|
$coll = $this->connection->query("FROM Error-I");
|
2006-04-14 00:37:28 +04:00
|
|
|
$e = $coll[0];
|
2006-04-23 12:12:01 +04:00
|
|
|
|
2006-04-14 00:37:28 +04:00
|
|
|
|
|
|
|
$this->assertEqual($e->code,1);
|
|
|
|
$this->assertEqual($e->file_md5, md5(0));
|
|
|
|
$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");
|
|
|
|
|
2006-04-14 14:20:19 +04:00
|
|
|
// UPDATING
|
2006-04-14 00:37:28 +04:00
|
|
|
|
|
|
|
$e->code = 2;
|
|
|
|
$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");
|
|
|
|
|
|
|
|
$e->save();
|
|
|
|
$this->assertEqual($e->code,2);
|
|
|
|
$this->assertEqual($e->message,"changed message");
|
|
|
|
$this->assertEqual($e->Description[0]->description, "1st changed description");
|
2006-05-17 00:37:26 +04:00
|
|
|
$this->assertEqual($e->Description[1]->description, "2nd changed description");
|
2006-04-14 00:37:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testInsert() {
|
2006-05-15 16:15:20 +04:00
|
|
|
$user = new User();
|
|
|
|
$user->name = "John Locke";
|
|
|
|
$user->save();
|
2006-04-14 00:37:28 +04:00
|
|
|
|
2006-05-15 16:15:20 +04:00
|
|
|
$this->assertTrue($user->getModified() == array());
|
|
|
|
$this->assertTrue($user->getState() == Doctrine_Record::STATE_CLEAN);
|
2006-04-14 00:37:28 +04:00
|
|
|
|
|
|
|
$debug = $this->listener->getMessages();
|
|
|
|
$p = array_pop($debug);
|
2006-08-22 03:20:33 +04:00
|
|
|
$this->assertTrue($p->getObject() instanceof Doctrine_Connection);
|
2006-06-03 13:10:43 +04:00
|
|
|
$this->assertTrue($p->getCode() == Doctrine_EventListener_Debugger::EVENT_COMMIT);
|
2006-04-14 00:37:28 +04:00
|
|
|
|
2006-05-15 16:15:20 +04:00
|
|
|
$user->delete();
|
|
|
|
$this->assertTrue($user->getState() == Doctrine_Record::STATE_TCLEAN);
|
2006-04-14 00:37:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdate() {
|
2006-08-22 03:20:33 +04:00
|
|
|
$user = $this->connection->getTable("User")->find(4);
|
2006-05-15 16:15:20 +04:00
|
|
|
$user->set("name","Jack Daniels",true);
|
2006-04-14 00:37:28 +04:00
|
|
|
|
|
|
|
|
2006-05-15 16:15:20 +04:00
|
|
|
$user->save();
|
2006-04-14 00:37:28 +04:00
|
|
|
//print $this->old->name;
|
|
|
|
|
2006-05-15 16:15:20 +04:00
|
|
|
$this->assertEqual($user->getModified(), array());
|
|
|
|
$this->assertEqual($user->name, "Jack Daniels");
|
2006-04-14 00:37:28 +04:00
|
|
|
|
|
|
|
$debug = $this->listener->getMessages();
|
|
|
|
$p = array_pop($debug);
|
2006-08-22 03:20:33 +04:00
|
|
|
$this->assertTrue($p->getObject() instanceof Doctrine_Connection);
|
2006-06-03 13:10:43 +04:00
|
|
|
$this->assertTrue($p->getCode() == Doctrine_EventListener_Debugger::EVENT_COMMIT);
|
2006-04-14 00:37:28 +04:00
|
|
|
|
|
|
|
$p = array_pop($debug);
|
|
|
|
$this->assertTrue($p->getObject() instanceof Doctrine_Record);
|
2006-06-03 13:10:43 +04:00
|
|
|
$this->assertTrue($p->getCode() == Doctrine_EventListener_Debugger::EVENT_SAVE);
|
2006-04-14 00:37:28 +04:00
|
|
|
|
|
|
|
$p = array_pop($debug);
|
|
|
|
$this->assertTrue($p->getObject() instanceof Doctrine_Record);
|
2006-06-03 13:10:43 +04:00
|
|
|
$this->assertTrue($p->getCode() == Doctrine_EventListener_Debugger::EVENT_UPDATE);
|
2006-04-14 00:37:28 +04:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
public function testCopy() {
|
2006-08-22 03:20:33 +04:00
|
|
|
$user = $this->connection->getTable("User")->find(4);
|
2006-05-15 16:15:20 +04:00
|
|
|
$new = $user->copy();
|
2006-04-14 00:37:28 +04:00
|
|
|
$this->assertTrue($new instanceof Doctrine_Record);
|
|
|
|
$this->assertTrue($new->getState() == Doctrine_Record::STATE_TDIRTY);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testReferences() {
|
|
|
|
|
|
|
|
$user = $this->objTable->find(5);
|
|
|
|
|
2006-08-22 03:20:33 +04:00
|
|
|
$pf = $this->connection->getTable("Phonenumber");
|
2006-04-14 00:37:28 +04:00
|
|
|
|
|
|
|
$this->assertTrue($user->Phonenumber instanceof Doctrine_Collection);
|
2006-04-21 12:39:09 +04:00
|
|
|
$this->assertEqual($user->Phonenumber->count(), 3);
|
2006-04-14 00:37:28 +04:00
|
|
|
|
|
|
|
$coll = new Doctrine_Collection($pf);
|
|
|
|
|
|
|
|
$user->Phonenumber = $coll;
|
2006-07-10 13:18:09 +04:00
|
|
|
$this->assertEqual($user->Phonenumber->count(), 0);
|
2006-04-14 00:37:28 +04:00
|
|
|
$user->save();
|
2006-07-10 13:18:09 +04:00
|
|
|
|
|
|
|
$user->getTable()->clear();
|
|
|
|
|
2006-04-14 00:37:28 +04:00
|
|
|
$user = $this->objTable->find(5);
|
|
|
|
|
|
|
|
$this->assertEqual($user->Phonenumber->count(), 0);
|
|
|
|
|
2006-07-10 13:18:09 +04:00
|
|
|
$this->assertEqual(get_class($user->Phonenumber), "Doctrine_Collection_Immediate");
|
|
|
|
|
|
|
|
$user->Phonenumber[0]->phonenumber;
|
|
|
|
$this->assertEqual($user->Phonenumber->count(), 1);
|
|
|
|
|
2006-04-14 00:37:28 +04:00
|
|
|
// ADDING REFERENCES
|
|
|
|
|
|
|
|
$user->Phonenumber[0]->phonenumber = "123 123";
|
|
|
|
|
2006-07-10 13:18:09 +04:00
|
|
|
$this->assertEqual($user->Phonenumber->count(), 1);
|
2006-04-14 00:37:28 +04:00
|
|
|
$user->Phonenumber[1]->phonenumber = "123 123";
|
2006-07-10 13:18:09 +04:00
|
|
|
$this->assertEqual($user->Phonenumber->count(), 2);
|
|
|
|
|
2006-04-14 00:37:28 +04:00
|
|
|
$user->save();
|
|
|
|
|
|
|
|
|
2006-07-10 13:18:09 +04:00
|
|
|
$this->assertEqual($user->Phonenumber->count(), 2);
|
2006-04-14 00:37:28 +04:00
|
|
|
|
|
|
|
unset($user);
|
|
|
|
$user = $this->objTable->find(5);
|
|
|
|
$this->assertEqual($user->Phonenumber->count(), 2);
|
|
|
|
|
|
|
|
$user->Phonenumber[3]->phonenumber = "123 123";
|
|
|
|
$user->save();
|
|
|
|
|
2006-07-10 13:18:09 +04:00
|
|
|
$this->assertEqual($user->Phonenumber->count(), 3);
|
2006-04-14 00:37:28 +04:00
|
|
|
unset($user);
|
|
|
|
$user = $this->objTable->find(5);
|
2006-07-10 13:18:09 +04:00
|
|
|
$this->assertEqual($user->Phonenumber->count(), 3);
|
2006-04-14 00:37:28 +04:00
|
|
|
|
|
|
|
// DELETING REFERENCES
|
|
|
|
|
|
|
|
$user->Phonenumber->delete();
|
|
|
|
|
2006-07-10 13:18:09 +04:00
|
|
|
$this->assertEqual($user->Phonenumber->count(), 0);
|
2006-04-14 00:37:28 +04:00
|
|
|
unset($user);
|
|
|
|
$user = $this->objTable->find(5);
|
2006-07-10 13:18:09 +04:00
|
|
|
$this->assertEqual($user->Phonenumber->count(), 0);
|
|
|
|
|
2006-04-14 00:37:28 +04:00
|
|
|
// ADDING REFERENCES WITH STRING KEYS
|
|
|
|
|
|
|
|
$user->Phonenumber["home"]->phonenumber = "123 123";
|
|
|
|
$user->Phonenumber["work"]->phonenumber = "444 444";
|
|
|
|
$user->save();
|
|
|
|
|
2006-07-10 13:18:09 +04:00
|
|
|
$this->assertEqual($user->Phonenumber->count(), 2);
|
2006-04-14 00:37:28 +04:00
|
|
|
unset($user);
|
|
|
|
$user = $this->objTable->find(5);
|
2006-07-10 13:18:09 +04:00
|
|
|
$this->assertEqual($user->Phonenumber->count(), 2);
|
2006-04-14 00:37:28 +04:00
|
|
|
|
|
|
|
// REPLACING ONE-TO-MANY REFERENCE
|
|
|
|
unset($coll);
|
|
|
|
$coll = new Doctrine_Collection($pf);
|
|
|
|
$coll[0]->phonenumber = "123 123";
|
|
|
|
$coll["home"]->phonenumber = "444 444";
|
|
|
|
$coll["work"]->phonenumber = "444 444";
|
|
|
|
|
|
|
|
$user->Phonenumber = $coll;
|
|
|
|
$user->save();
|
|
|
|
$this->assertEqual($user->Phonenumber->count(), 3);
|
2006-04-14 14:20:19 +04:00
|
|
|
|
2006-04-14 00:37:28 +04:00
|
|
|
$user = $this->objTable->find(5);
|
2006-04-14 14:20:19 +04:00
|
|
|
//$this->assertEqual($user->Phonenumber->count(), 3);
|
|
|
|
|
2006-04-14 00:37:28 +04:00
|
|
|
|
|
|
|
// ONE-TO-ONE REFERENCES
|
|
|
|
|
|
|
|
$user->Email->address = "drinker@drinkmore.info";
|
2006-04-14 14:20:19 +04:00
|
|
|
$this->assertTrue($user->Email instanceof Email);
|
|
|
|
$this->assertEqual($user->Email->address, "drinker@drinkmore.info");
|
|
|
|
|
2006-04-14 00:37:28 +04:00
|
|
|
$user->save();
|
2006-04-14 14:20:19 +04:00
|
|
|
|
2006-04-14 00:37:28 +04:00
|
|
|
$this->assertTrue($user->Email instanceof Email);
|
2006-04-14 14:20:19 +04:00
|
|
|
$this->assertEqual($user->Email->address, "drinker@drinkmore.info");
|
2006-07-10 13:18:09 +04:00
|
|
|
$this->assertEqual($user->Email->id, $user->email_id);
|
2006-04-14 14:20:19 +04:00
|
|
|
|
2006-04-14 00:37:28 +04:00
|
|
|
$user = $this->objTable->find(5);
|
2006-04-14 14:20:19 +04:00
|
|
|
|
|
|
|
$this->assertTrue($user->Email instanceof Email);
|
2006-07-10 13:18:09 +04:00
|
|
|
$this->assertEqual($user->Email->id, $user->email_id);
|
2006-04-14 14:20:19 +04:00
|
|
|
$this->assertEqual($user->Email->getState(), Doctrine_Record::STATE_CLEAN);
|
2006-04-14 00:37:28 +04:00
|
|
|
$this->assertEqual($user->Email->address, "drinker@drinkmore.info");
|
2006-07-10 13:18:09 +04:00
|
|
|
$id = $user->Email->id;
|
2006-04-14 00:37:28 +04:00
|
|
|
|
|
|
|
// REPLACING ONE-TO-ONE REFERENCES
|
|
|
|
|
2006-08-22 03:20:33 +04:00
|
|
|
$email = $this->connection->create("Email");
|
2006-04-14 00:37:28 +04:00
|
|
|
$email->address = "absolutist@nottodrink.com";
|
|
|
|
$user->Email = $email;
|
|
|
|
|
|
|
|
$this->assertTrue($user->Email instanceof Email);
|
|
|
|
$this->assertEqual($user->Email->address, "absolutist@nottodrink.com");
|
|
|
|
$user->save();
|
|
|
|
unset($user);
|
|
|
|
|
|
|
|
$user = $this->objTable->find(5);
|
|
|
|
$this->assertTrue($user->Email instanceof Email);
|
|
|
|
$this->assertEqual($user->Email->address, "absolutist@nottodrink.com");
|
|
|
|
|
2006-08-22 03:20:33 +04:00
|
|
|
$emails = $this->connection->query("FROM Email WHERE Email.id = $id");
|
2006-04-14 14:20:19 +04:00
|
|
|
//$this->assertEqual(count($emails),0);
|
|
|
|
|
2006-04-14 00:37:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testDeleteReference() {
|
|
|
|
$user = $this->objTable->find(5);
|
|
|
|
$int = $user->Phonenumber->delete();
|
|
|
|
|
|
|
|
$this->assertTrue($user->Phonenumber->count() == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSaveAssociations() {
|
|
|
|
$user = $this->objTable->find(5);
|
|
|
|
|
2006-08-22 03:20:33 +04:00
|
|
|
$gf = $this->connection->getTable("Group");
|
2006-04-14 00:37:28 +04:00
|
|
|
|
|
|
|
$this->assertTrue($user->Group instanceof Doctrine_Collection);
|
|
|
|
|
|
|
|
|
|
|
|
// ADDING ASSOCIATED REFERENCES
|
|
|
|
|
|
|
|
|
|
|
|
$record = $gf->find(1);
|
|
|
|
$record2 = $gf->find(2);
|
|
|
|
$user->Group[0] = $record;
|
|
|
|
$user->Group[1] = $record2;
|
|
|
|
|
|
|
|
$this->assertTrue($user->Group->count() == 2);
|
|
|
|
|
|
|
|
$user->save();
|
|
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
unset($user->Group[1]);
|
|
|
|
$this->assertTrue($user->Group->count() == 0);
|
|
|
|
|
|
|
|
$user->save();
|
|
|
|
$this->assertTrue($user->Group->count() == 0);
|
|
|
|
unset($user);
|
|
|
|
|
|
|
|
|
|
|
|
// CHECKING THE PERSISTENCE OF UNSET ASSOCIATED REFERENCES
|
|
|
|
|
|
|
|
|
|
|
|
$user = $this->objTable->find(5);
|
|
|
|
$this->assertTrue($user->Group->count() == 0);
|
|
|
|
|
|
|
|
|
|
|
|
// REPLACING OLD ASSOCIATED REFERENCE
|
|
|
|
|
|
|
|
|
|
|
|
$user->Group[0] = $record;
|
|
|
|
$user->save();
|
|
|
|
|
|
|
|
$user->Group[0] = $record2;
|
|
|
|
$user->save();
|
|
|
|
|
|
|
|
$this->assertEqual($user->Group->count(), 1);
|
|
|
|
$this->assertEqual($user->Group[0]->getID(), $record2->getID());
|
|
|
|
$this->assertFalse($user->Group[0]->getID() == $record->getID());
|
|
|
|
|
|
|
|
|
|
|
|
$user->Group[0] = $record;
|
|
|
|
$user->Group[1] = $gf->find(3);
|
|
|
|
|
|
|
|
$user->save();
|
|
|
|
$this->assertEqual($user->Group->count(), 2);
|
|
|
|
$user = $this->objTable->find(5);
|
|
|
|
$this->assertEqual($user->Group->count(), 2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$user->Group = new Doctrine_Collection($gf);
|
|
|
|
$user->save();
|
|
|
|
$this->assertEqual($user->Group->count(), 0);
|
|
|
|
$user = $this->objTable->find(5);
|
|
|
|
$this->assertEqual($user->Group->count(), 0);
|
|
|
|
|
|
|
|
|
|
|
|
// ACCESSING ASSOCIATION OBJECT PROPERTIES
|
|
|
|
|
|
|
|
$user = new User();
|
2006-08-31 13:04:14 +04:00
|
|
|
$this->assertTrue($user->getTable()->getRelation("Groupuser") instanceof Doctrine_ForeignKey);
|
2006-04-14 00:37:28 +04:00
|
|
|
$this->assertTrue($user->Groupuser instanceof Doctrine_Collection);
|
|
|
|
$this->assertTrue($user->Groupuser[0] instanceof Groupuser);
|
|
|
|
|
|
|
|
$user->name = "Jack Daniels";
|
|
|
|
$user->Group[0]->name = "Group #1";
|
|
|
|
$user->Group[1]->name = "Group #2";
|
|
|
|
$t1 = time();
|
|
|
|
$t2 = time();
|
|
|
|
$user->Groupuser[0]->added = $t1;
|
|
|
|
$user->Groupuser[1]->added = $t2;
|
|
|
|
|
|
|
|
$this->assertEqual($user->Groupuser[0]->added, $t1);
|
|
|
|
$this->assertEqual($user->Groupuser[1]->added, $t2);
|
|
|
|
|
|
|
|
$user->save();
|
|
|
|
|
|
|
|
$user->refresh();
|
|
|
|
$this->assertEqual($user->Groupuser[0]->added, $t1);
|
|
|
|
$this->assertEqual($user->Groupuser[1]->added, $t2);
|
|
|
|
}
|
|
|
|
|
2006-09-13 01:36:36 +04:00
|
|
|
|
2006-04-14 00:37:28 +04:00
|
|
|
public function testCount() {
|
2006-08-22 03:20:33 +04:00
|
|
|
$user = $this->connection->getTable("User")->find(4);
|
2006-05-15 16:15:20 +04:00
|
|
|
|
|
|
|
$this->assertTrue(is_integer($user->count()));
|
2006-04-14 00:37:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetReference() {
|
2006-08-22 03:20:33 +04:00
|
|
|
$user = $this->connection->getTable("User")->find(4);
|
2006-04-14 00:37:28 +04:00
|
|
|
|
2006-05-15 16:15:20 +04:00
|
|
|
$this->assertTrue($user->Email instanceof Doctrine_Record);
|
|
|
|
$this->assertTrue($user->Phonenumber instanceof Doctrine_Collection);
|
|
|
|
$this->assertTrue($user->Group instanceof Doctrine_Collection);
|
|
|
|
|
|
|
|
$this->assertTrue($user->Phonenumber->count() == 1);
|
2006-04-14 00:37:28 +04:00
|
|
|
}
|
|
|
|
public function testGetIterator() {
|
2006-08-22 03:20:33 +04:00
|
|
|
$user = $this->connection->getTable("User")->find(4);
|
2006-05-15 16:15:20 +04:00
|
|
|
$this->assertTrue($user->getIterator() instanceof ArrayIterator);
|
2006-04-14 00:37:28 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|