diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index 578b2f237..9cdfaf639 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -783,10 +783,12 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite * @return boolean */ public function contains($name) { - if(isset($this->data[$name])) + $lower = strtolower($name); + + if(isset($this->data[$lower])) return true; - if(isset($this->id[$name])) + if(isset($this->id[$lower])) return true; if(isset($this->references[$name])) diff --git a/lib/Doctrine/Repository.php b/lib/Doctrine/Repository.php index 87c0a1d0f..00719b063 100644 --- a/lib/Doctrine/Repository.php +++ b/lib/Doctrine/Repository.php @@ -41,11 +41,15 @@ class Doctrine_Repository implements Countable, IteratorAggregate { private $registry = array(); /** * constructor + * + * @param Doctrine_Table $table */ public function __construct(Doctrine_Table $table) { $this->table = $table; } - /** + /** + * getTable + * * @return object Doctrine_Table */ public function getTable() { @@ -53,7 +57,9 @@ class Doctrine_Repository implements Countable, IteratorAggregate { } /** * add + * * @param Doctrine_Record $record record to be added into registry + * @return boolean */ public function add(Doctrine_Record $record) { $oid = $record->getOID(); diff --git a/tests/EnumTestCase.php b/tests/EnumTestCase.php index dfd5a3b67..ea1faeb4d 100644 --- a/tests/EnumTestCase.php +++ b/tests/EnumTestCase.php @@ -20,7 +20,67 @@ class Doctrine_EnumTestCase extends Doctrine_UnitTestCase { $ret = $query->query('FROM EnumTest WHERE EnumTest.status = open'); $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); } } ?> diff --git a/tests/QueryTestCase.php b/tests/QueryTestCase.php index 79b9e23ef..e5213d113 100644 --- a/tests/QueryTestCase.php +++ b/tests/QueryTestCase.php @@ -927,11 +927,11 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase { $fk = $table->getRelation("Threads"); $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"); $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"; diff --git a/tests/RecordTestCase.php b/tests/RecordTestCase.php index ffae8a9a7..3f32dcd2c 100644 --- a/tests/RecordTestCase.php +++ b/tests/RecordTestCase.php @@ -9,6 +9,17 @@ class Doctrine_RecordTestCase 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'])); + $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() { $null = new NotNullTest(); @@ -46,67 +57,6 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase { $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() { $test = new FieldNameTest; @@ -540,7 +490,7 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase { $e = new Element(); $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->getForeign(), "parent_id"); $this->assertEqual($fk->getLocal(), "id"); @@ -609,7 +559,7 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase { $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->getForeign(),"file_md5"); $this->assertTrue($fk->getTable() instanceof Doctrine_Table); @@ -911,7 +861,7 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase { // ACCESSING ASSOCIATION OBJECT PROPERTIES $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[0] instanceof Groupuser); diff --git a/tests/TableTestCase.php b/tests/TableTestCase.php index e2088e935..6e187f160 100644 --- a/tests/TableTestCase.php +++ b/tests/TableTestCase.php @@ -62,14 +62,14 @@ class Doctrine_TableTestCase extends Doctrine_UnitTestCase { } public function testGetForeignKey() { $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->getType() == Doctrine_Relation::MANY_AGGREGATE); $this->assertTrue($fk->getLocal() == "user_id"); $this->assertTrue($fk->getForeign() == "group_id"); $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->getType() == Doctrine_Relation::ONE_COMPOSITE); $this->assertTrue($fk->getLocal() == "email_id"); @@ -77,7 +77,7 @@ class Doctrine_TableTestCase extends Doctrine_UnitTestCase { $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->getType() == Doctrine_Relation::MANY_COMPOSITE); $this->assertTrue($fk->getLocal() == $this->objTable->getIdentifier());