diff --git a/Doctrine/Query/Where.php b/Doctrine/Query/Where.php index be59e5364..5624bb346 100644 --- a/Doctrine/Query/Where.php +++ b/Doctrine/Query/Where.php @@ -30,7 +30,21 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition { $table = $this->query->load($reference, false); - $where = $this->query->getTableAlias($reference).".".$field." ".$operator." ".$value; + switch($operator) { + case '=': + $alias = $this->query->getTableAlias($reference); + $table = $this->query->getTable($alias); + $enumIndex = $table->enumIndex($field, trim($value,"'")); + + if($enumIndex !== false) + $value = $enumIndex; + + $where = $alias.'.'.$field.' '.$operator.' '.$value; + break; + default: + + $where = $this->query->getTableAlias($reference).'.'.$field.' '.$operator.' '.$value; + } } return $where; } diff --git a/Doctrine/Table.php b/Doctrine/Table.php index 682a350ca..7dddbad3f 100644 --- a/Doctrine/Table.php +++ b/Doctrine/Table.php @@ -903,8 +903,12 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { * enumIndex */ final public function enumIndex($field, $value) { - $v = array_search($value, $this->enum[$field]); - return $v; + if( ! isset($this->enum[$field])) + $values = array(); + else + $values = $this->enum[$field]; + + return array_search($value, $values); } /** * @return integer diff --git a/Doctrine/Validator/Country.php b/Doctrine/Validator/Country.php index 0c4e57f57..ee25905da 100644 --- a/Doctrine/Validator/Country.php +++ b/Doctrine/Validator/Country.php @@ -258,6 +258,7 @@ class Doctrine_Validator_Country { * @return boolean */ public function validate(Doctrine_Record $record, $key, $value, $args) { + $value = srttolower($value); return isset(self::$countries[$value]); } diff --git a/tests/AccessTestCase.php b/tests/AccessTestCase.php index 7e04c7f2e..43494dd2c 100644 --- a/tests/AccessTestCase.php +++ b/tests/AccessTestCase.php @@ -5,6 +5,31 @@ class Doctrine_AccessTestCase extends Doctrine_UnitTestCase { $this->tables = array("Entity", "User"); parent::prepareTables(); } + public function testUnset() { + + + + } + public function testIsset() { + $user = new User(); + + $this->assertTrue(isset($user->name)); + $this->assertFalse(isset($user->unknown)); + + $this->assertTrue(isset($user['name'])); + $this->assertFalse(isset($user['unknown'])); + + $coll = new Doctrine_Collection('User'); + + $this->assertFalse(isset($coll[0])); + // test repeated call + $this->assertFalse(isset($coll[0])); + $coll[0]; + + $this->assertTrue(isset($coll[0])); + // test repeated call + $this->assertTrue(isset($coll[0])); + } public function testOffsetMethods() { $user = new User(); $this->assertEqual($user["name"],null); diff --git a/tests/QueryTestCase.php b/tests/QueryTestCase.php index f0e8b358a..b69f781b5 100644 --- a/tests/QueryTestCase.php +++ b/tests/QueryTestCase.php @@ -10,6 +10,11 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase { $this->tables[] = "ORM_TestItem"; $this->tables[] = "Log_Status"; $this->tables[] = "Log_Entry"; + $this->tables[] = "EnumTest"; + + $this->tables[] = "Task"; + $this->tables[] = "Resource"; + $this->tables[] = "ResourceType"; try { $this->dbh->query("DROP TABLE test_items"); @@ -22,8 +27,39 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase { } parent::prepareTables(); - + $this->connection->clear(); } + + public function testEnumConversion() { + $e[0] = new EnumTest(); + $e[0]->status = 'open'; + + $e[1] = new EnumTest(); + $e[1]->status = 'verified'; + + $this->connection->flush(); + $this->assertEqual($e[0]->id, 1); + $this->assertEqual($e[1]->id, 2); + + $q = new Doctrine_Query; + + $coll = $q->from('EnumTest') + ->where("EnumTest.status = 'open'") + ->execute(); + + $this->assertEqual($q->getQuery(), 'SELECT enum_test.id AS enum_test__id, enum_test.status AS enum_test__status FROM enum_test WHERE enum_test.status = 0'); + $this->assertEqual($coll->count(), 1); + + $q = new Doctrine_Query; + + $coll = $q->from('EnumTest') + ->where("EnumTest.status = 'verified'") + ->execute(); + + $this->assertEqual($q->getQuery(), 'SELECT enum_test.id AS enum_test__id, enum_test.status AS enum_test__status FROM enum_test WHERE enum_test.status = 1'); + $this->assertEqual($coll->count(), 1); + } + public function testManyToManyFetchingWithColumnAggregationInheritance() { $query = new Doctrine_Query($this->connection); diff --git a/tests/UnitTestCase.php b/tests/UnitTestCase.php index 19c1c9e67..a5983cdb5 100644 --- a/tests/UnitTestCase.php +++ b/tests/UnitTestCase.php @@ -84,7 +84,7 @@ class Doctrine_UnitTestCase extends UnitTestCase { } public function prepareTables() { foreach($this->tables as $name) { - $query = "DROP TABLE ".strtolower($name); + $query = "DROP TABLE ".Doctrine::tableize($name); try { $this->dbh->query($query); } catch(PDOException $e) { diff --git a/tests/run.php b/tests/run.php index a214ac566..3dc185107 100644 --- a/tests/run.php +++ b/tests/run.php @@ -32,6 +32,8 @@ error_reporting(E_ALL); $test = new GroupTest("Doctrine Framework Unit Tests"); +$test->addTestCase(new Doctrine_AccessTestCase()); + $test->addTestCase(new Doctrine_EventListenerTestCase()); $test->addTestCase(new Doctrine_RecordTestCase()); @@ -42,8 +44,6 @@ $test->addTestCase(new Doctrine_ConnectionTestCase()); $test->addTestCase(new Doctrine_ManagerTestCase()); -$test->addTestCase(new Doctrine_AccessTestCase()); - $test->addTestCase(new Doctrine_BatchIteratorTestCase()); $test->addTestCase(new Doctrine_ConfigurableTestCase()); @@ -70,11 +70,12 @@ $test->addTestCase(new Doctrine_SchemaTestCase()); $test->addTestCase(new Doctrine_ImportTestCase()); -$test->addTestCase(new Doctrine_ValidatorTestCase()); +$test->addTestCase(new Doctrine_ValidatorTestCase()); + +$test->addTestCase(new Doctrine_CollectionTestCase()); $test->addTestCase(new Doctrine_QueryTestCase()); -$test->addTestCase(new Doctrine_CollectionTestCase());