1
0
mirror of synced 2024-12-13 14:56:01 +03:00

Fixes #132, refactored some test cases

Ticket: 132
This commit is contained in:
zYne 2006-09-28 21:21:33 +00:00
parent d5b1c35074
commit 14b95350d0
6 changed files with 90 additions and 72 deletions

View File

@ -783,10 +783,12 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @return boolean * @return boolean
*/ */
public function contains($name) { public function contains($name) {
if(isset($this->data[$name])) $lower = strtolower($name);
if(isset($this->data[$lower]))
return true; return true;
if(isset($this->id[$name])) if(isset($this->id[$lower]))
return true; return true;
if(isset($this->references[$name])) if(isset($this->references[$name]))

View File

@ -41,11 +41,15 @@ class Doctrine_Repository implements Countable, IteratorAggregate {
private $registry = array(); private $registry = array();
/** /**
* constructor * constructor
*
* @param Doctrine_Table $table
*/ */
public function __construct(Doctrine_Table $table) { public function __construct(Doctrine_Table $table) {
$this->table = $table; $this->table = $table;
} }
/** /**
* getTable
*
* @return object Doctrine_Table * @return object Doctrine_Table
*/ */
public function getTable() { public function getTable() {
@ -53,7 +57,9 @@ class Doctrine_Repository implements Countable, IteratorAggregate {
} }
/** /**
* add * add
*
* @param Doctrine_Record $record record to be added into registry * @param Doctrine_Record $record record to be added into registry
* @return boolean
*/ */
public function add(Doctrine_Record $record) { public function add(Doctrine_Record $record) {
$oid = $record->getOID(); $oid = $record->getOID();

View File

@ -20,7 +20,67 @@ class Doctrine_EnumTestCase extends Doctrine_UnitTestCase {
$ret = $query->query('FROM EnumTest WHERE EnumTest.status = open'); $ret = $query->query('FROM EnumTest WHERE EnumTest.status = open');
$this->assertEqual(count($ret), 1); $this->assertEqual(count($ret), 1);
}
public function testEnumType() {
$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");
$this->assertTrue(is_numeric($enum->id));
$enum->refresh();
$this->assertEqual($enum->status, "closed");
}
public function testEnumTypeWithCaseConversion() {
$this->dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_UPPER);
$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");
$this->dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL);
}
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);
} }
} }
?> ?>

View File

@ -927,11 +927,11 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$fk = $table->getRelation("Threads"); $fk = $table->getRelation("Threads");
$this->assertEqual($table->getComponentName(), "Forum_Board"); $this->assertEqual($table->getComponentName(), "Forum_Board");
$this->assertTrue($fk instanceof Doctrine_ForeignKey); $this->assertTrue($fk instanceof Doctrine_Relation_ForeignKey);
$this->assertEqual($fk->getTable()->getComponentName(), "Forum_Thread"); $this->assertEqual($fk->getTable()->getComponentName(), "Forum_Thread");
$entry = new Forum_Entry(); $entry = new Forum_Entry();
$this->assertTrue($entry->getTable()->getRelation("Thread") instanceof Doctrine_LocalKey); $this->assertTrue($entry->getTable()->getRelation("Thread") instanceof Doctrine_Relation_LocalKey);
$board->name = "Doctrine Forum"; $board->name = "Doctrine Forum";

View File

@ -9,6 +9,17 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
$this->tables[] = "GzipTest"; $this->tables[] = "GzipTest";
parent::prepareTables(); parent::prepareTables();
} }
public function testIssetForPrimaryKey() {
$this->assertTrue(isset($this->users[0]->id));
$this->assertTrue(isset($this->users[0]['id']));
$this->assertTrue($this->users[0]->contains('id'));
$user = new User();
$this->assertFalse(isset($user->id));
$this->assertFalse(isset($user['id']));
$this->assertFalse($user->contains('id'));
}
public function testNotNullConstraint() { public function testNotNullConstraint() {
$null = new NotNullTest(); $null = new NotNullTest();
@ -46,67 +57,6 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
$this->assertEqual($gzip->gzip, "compressed 2"); $this->assertEqual($gzip->gzip, "compressed 2");
} }
public function testEnumType() {
$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");
$this->assertTrue(is_numeric($enum->id));
$enum->refresh();
$this->assertEqual($enum->status, "closed");
}
public function testEnumTypeWithCaseConversion() {
$this->dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_UPPER);
$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");
$this->dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL);
}
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);
}
public function testDefaultValues() { public function testDefaultValues() {
$test = new FieldNameTest; $test = new FieldNameTest;
@ -540,7 +490,7 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
$e = new Element(); $e = new Element();
$fk = $e->getTable()->getRelation("Child"); $fk = $e->getTable()->getRelation("Child");
$this->assertTrue($fk instanceof Doctrine_ForeignKey); $this->assertTrue($fk instanceof Doctrine_Relation_ForeignKey);
$this->assertEqual($fk->getType(), Doctrine_Relation::MANY_AGGREGATE); $this->assertEqual($fk->getType(), Doctrine_Relation::MANY_AGGREGATE);
$this->assertEqual($fk->getForeign(), "parent_id"); $this->assertEqual($fk->getForeign(), "parent_id");
$this->assertEqual($fk->getLocal(), "id"); $this->assertEqual($fk->getLocal(), "id");
@ -609,7 +559,7 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
$fk = $e->getTable()->getRelation("Description"); $fk = $e->getTable()->getRelation("Description");
$this->assertTrue($fk instanceof Doctrine_ForeignKey); $this->assertTrue($fk instanceof Doctrine_Relation_ForeignKey);
$this->assertEqual($fk->getLocal(),"file_md5"); $this->assertEqual($fk->getLocal(),"file_md5");
$this->assertEqual($fk->getForeign(),"file_md5"); $this->assertEqual($fk->getForeign(),"file_md5");
$this->assertTrue($fk->getTable() instanceof Doctrine_Table); $this->assertTrue($fk->getTable() instanceof Doctrine_Table);
@ -911,7 +861,7 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
// ACCESSING ASSOCIATION OBJECT PROPERTIES // ACCESSING ASSOCIATION OBJECT PROPERTIES
$user = new User(); $user = new User();
$this->assertTrue($user->getTable()->getRelation("Groupuser") instanceof Doctrine_ForeignKey); $this->assertTrue($user->getTable()->getRelation("Groupuser") instanceof Doctrine_Relation_ForeignKey);
$this->assertTrue($user->Groupuser instanceof Doctrine_Collection); $this->assertTrue($user->Groupuser instanceof Doctrine_Collection);
$this->assertTrue($user->Groupuser[0] instanceof Groupuser); $this->assertTrue($user->Groupuser[0] instanceof Groupuser);

View File

@ -62,14 +62,14 @@ class Doctrine_TableTestCase extends Doctrine_UnitTestCase {
} }
public function testGetForeignKey() { public function testGetForeignKey() {
$fk = $this->objTable->getRelation("Group"); $fk = $this->objTable->getRelation("Group");
$this->assertTrue($fk instanceof Doctrine_Association); $this->assertTrue($fk instanceof Doctrine_Relation_Association);
$this->assertTrue($fk->getTable() instanceof Doctrine_Table); $this->assertTrue($fk->getTable() instanceof Doctrine_Table);
$this->assertTrue($fk->getType() == Doctrine_Relation::MANY_AGGREGATE); $this->assertTrue($fk->getType() == Doctrine_Relation::MANY_AGGREGATE);
$this->assertTrue($fk->getLocal() == "user_id"); $this->assertTrue($fk->getLocal() == "user_id");
$this->assertTrue($fk->getForeign() == "group_id"); $this->assertTrue($fk->getForeign() == "group_id");
$fk = $this->objTable->getRelation("Email"); $fk = $this->objTable->getRelation("Email");
$this->assertTrue($fk instanceof Doctrine_LocalKey); $this->assertTrue($fk instanceof Doctrine_Relation_LocalKey);
$this->assertTrue($fk->getTable() instanceof Doctrine_Table); $this->assertTrue($fk->getTable() instanceof Doctrine_Table);
$this->assertTrue($fk->getType() == Doctrine_Relation::ONE_COMPOSITE); $this->assertTrue($fk->getType() == Doctrine_Relation::ONE_COMPOSITE);
$this->assertTrue($fk->getLocal() == "email_id"); $this->assertTrue($fk->getLocal() == "email_id");
@ -77,7 +77,7 @@ class Doctrine_TableTestCase extends Doctrine_UnitTestCase {
$fk = $this->objTable->getRelation("Phonenumber"); $fk = $this->objTable->getRelation("Phonenumber");
$this->assertTrue($fk instanceof Doctrine_ForeignKey); $this->assertTrue($fk instanceof Doctrine_Relation_ForeignKey);
$this->assertTrue($fk->getTable() instanceof Doctrine_Table); $this->assertTrue($fk->getTable() instanceof Doctrine_Table);
$this->assertTrue($fk->getType() == Doctrine_Relation::MANY_COMPOSITE); $this->assertTrue($fk->getType() == Doctrine_Relation::MANY_COMPOSITE);
$this->assertTrue($fk->getLocal() == $this->objTable->getIdentifier()); $this->assertTrue($fk->getLocal() == $this->objTable->getIdentifier());