Commit 871f3c41 authored by zYne's avatar zYne

DQL enum type support (still not working for prepared queries)

parent 0cbc7031
...@@ -30,7 +30,21 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition { ...@@ -30,7 +30,21 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition {
$table = $this->query->load($reference, false); $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; return $where;
} }
......
...@@ -903,8 +903,12 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { ...@@ -903,8 +903,12 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
* enumIndex * enumIndex
*/ */
final public function enumIndex($field, $value) { final public function enumIndex($field, $value) {
$v = array_search($value, $this->enum[$field]); if( ! isset($this->enum[$field]))
return $v; $values = array();
else
$values = $this->enum[$field];
return array_search($value, $values);
} }
/** /**
* @return integer * @return integer
......
...@@ -258,6 +258,7 @@ class Doctrine_Validator_Country { ...@@ -258,6 +258,7 @@ class Doctrine_Validator_Country {
* @return boolean * @return boolean
*/ */
public function validate(Doctrine_Record $record, $key, $value, $args) { public function validate(Doctrine_Record $record, $key, $value, $args) {
$value = srttolower($value);
return isset(self::$countries[$value]); return isset(self::$countries[$value]);
} }
......
...@@ -5,6 +5,31 @@ class Doctrine_AccessTestCase extends Doctrine_UnitTestCase { ...@@ -5,6 +5,31 @@ class Doctrine_AccessTestCase extends Doctrine_UnitTestCase {
$this->tables = array("Entity", "User"); $this->tables = array("Entity", "User");
parent::prepareTables(); 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() { public function testOffsetMethods() {
$user = new User(); $user = new User();
$this->assertEqual($user["name"],null); $this->assertEqual($user["name"],null);
......
...@@ -10,6 +10,11 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase { ...@@ -10,6 +10,11 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this->tables[] = "ORM_TestItem"; $this->tables[] = "ORM_TestItem";
$this->tables[] = "Log_Status"; $this->tables[] = "Log_Status";
$this->tables[] = "Log_Entry"; $this->tables[] = "Log_Entry";
$this->tables[] = "EnumTest";
$this->tables[] = "Task";
$this->tables[] = "Resource";
$this->tables[] = "ResourceType";
try { try {
$this->dbh->query("DROP TABLE test_items"); $this->dbh->query("DROP TABLE test_items");
...@@ -22,8 +27,39 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase { ...@@ -22,8 +27,39 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
} }
parent::prepareTables(); 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() { public function testManyToManyFetchingWithColumnAggregationInheritance() {
$query = new Doctrine_Query($this->connection); $query = new Doctrine_Query($this->connection);
......
...@@ -84,7 +84,7 @@ class Doctrine_UnitTestCase extends UnitTestCase { ...@@ -84,7 +84,7 @@ class Doctrine_UnitTestCase extends UnitTestCase {
} }
public function prepareTables() { public function prepareTables() {
foreach($this->tables as $name) { foreach($this->tables as $name) {
$query = "DROP TABLE ".strtolower($name); $query = "DROP TABLE ".Doctrine::tableize($name);
try { try {
$this->dbh->query($query); $this->dbh->query($query);
} catch(PDOException $e) { } catch(PDOException $e) {
......
...@@ -32,6 +32,8 @@ error_reporting(E_ALL); ...@@ -32,6 +32,8 @@ error_reporting(E_ALL);
$test = new GroupTest("Doctrine Framework Unit Tests"); $test = new GroupTest("Doctrine Framework Unit Tests");
$test->addTestCase(new Doctrine_AccessTestCase());
$test->addTestCase(new Doctrine_EventListenerTestCase()); $test->addTestCase(new Doctrine_EventListenerTestCase());
$test->addTestCase(new Doctrine_RecordTestCase()); $test->addTestCase(new Doctrine_RecordTestCase());
...@@ -42,8 +44,6 @@ $test->addTestCase(new Doctrine_ConnectionTestCase()); ...@@ -42,8 +44,6 @@ $test->addTestCase(new Doctrine_ConnectionTestCase());
$test->addTestCase(new Doctrine_ManagerTestCase()); $test->addTestCase(new Doctrine_ManagerTestCase());
$test->addTestCase(new Doctrine_AccessTestCase());
$test->addTestCase(new Doctrine_BatchIteratorTestCase()); $test->addTestCase(new Doctrine_BatchIteratorTestCase());
$test->addTestCase(new Doctrine_ConfigurableTestCase()); $test->addTestCase(new Doctrine_ConfigurableTestCase());
...@@ -70,11 +70,12 @@ $test->addTestCase(new Doctrine_SchemaTestCase()); ...@@ -70,11 +70,12 @@ $test->addTestCase(new Doctrine_SchemaTestCase());
$test->addTestCase(new Doctrine_ImportTestCase()); $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_QueryTestCase());
$test->addTestCase(new Doctrine_CollectionTestCase());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment