Tests updated for classify / tableize
This commit is contained in:
parent
80dad424a2
commit
8e3aead181
@ -255,13 +255,17 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
|
|||||||
$keys = array_keys($this->tables);
|
$keys = array_keys($this->tables);
|
||||||
|
|
||||||
$name = $this->tables[$keys[0]]->getComponentName();
|
$name = $this->tables[$keys[0]]->getComponentName();
|
||||||
|
|
||||||
|
|
||||||
$stmt = $this->connection->execute($query,$params);
|
$stmt = $this->connection->execute($query,$params);
|
||||||
|
|
||||||
while($data = $stmt->fetch(PDO::FETCH_ASSOC)):
|
while($data = $stmt->fetch(PDO::FETCH_ASSOC)):
|
||||||
|
|
||||||
foreach($data as $key => $value):
|
foreach($data as $key => $value):
|
||||||
$e = explode("__",$key);
|
$e = explode("__",$key);
|
||||||
if(count($e) > 1) {
|
if(count($e) > 1) {
|
||||||
$data[$e[1]] = $value;
|
|
||||||
|
$data[end($e)] = $value;
|
||||||
} else {
|
} else {
|
||||||
$data[$e[0]] = $value;
|
$data[$e[0]] = $value;
|
||||||
}
|
}
|
||||||
@ -269,6 +273,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
|
|||||||
endforeach;
|
endforeach;
|
||||||
$this->data[$name][] = $data;
|
$this->data[$name][] = $data;
|
||||||
endwhile;
|
endwhile;
|
||||||
|
|
||||||
|
|
||||||
return $this->getCollection($keys[0]);
|
return $this->getCollection($keys[0]);
|
||||||
break;
|
break;
|
||||||
@ -278,7 +283,9 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
|
|||||||
|
|
||||||
if($this->isLimitSubqueryUsed())
|
if($this->isLimitSubqueryUsed())
|
||||||
$params = array_merge($params, $params);
|
$params = array_merge($params, $params);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$stmt = $this->connection->execute($query,$params);
|
$stmt = $this->connection->execute($query,$params);
|
||||||
|
|
||||||
$previd = array();
|
$previd = array();
|
||||||
@ -292,6 +299,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
|
|||||||
return $this->hydrateHolders($array);
|
return $this->hydrateHolders($array);
|
||||||
} elseif($return == Doctrine::FETCH_ARRAY)
|
} elseif($return == Doctrine::FETCH_ARRAY)
|
||||||
return $array;
|
return $array;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach($array as $data) {
|
foreach($array as $data) {
|
||||||
/**
|
/**
|
||||||
@ -504,15 +513,15 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
|
|||||||
foreach($data as $key => $value):
|
foreach($data as $key => $value):
|
||||||
$e = explode("__",$key);
|
$e = explode("__",$key);
|
||||||
|
|
||||||
if(count($e) > 1) {
|
$field = array_pop($e);
|
||||||
$data[$e[0]][$e[1]] = $value;
|
$component = implode("__",$e);
|
||||||
} else {
|
$data[$component][$field] = $value;
|
||||||
$data[0][$e[0]] = $value;
|
|
||||||
}
|
|
||||||
unset($data[$key]);
|
unset($data[$key]);
|
||||||
endforeach;
|
endforeach;
|
||||||
$array[] = $data;
|
$array[] = $data;
|
||||||
endwhile;
|
endwhile;
|
||||||
|
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
return $array;
|
return $array;
|
||||||
}
|
}
|
||||||
|
@ -94,8 +94,10 @@ class Doctrine_RawSql extends Doctrine_Hydrate {
|
|||||||
case "group":
|
case "group":
|
||||||
$i = ($k + 1);
|
$i = ($k + 1);
|
||||||
if(isset($e[$i]) && strtolower($e[$i]) === "by") {
|
if(isset($e[$i]) && strtolower($e[$i]) === "by") {
|
||||||
$p = $part;
|
$p = $low;
|
||||||
$parts[$low] = array();
|
$p .= "by";
|
||||||
|
$parts[$low."by"] = array();
|
||||||
|
|
||||||
} else
|
} else
|
||||||
$parts[$p][] = $part;
|
$parts[$p][] = $part;
|
||||||
break;
|
break;
|
||||||
@ -121,7 +123,7 @@ class Doctrine_RawSql extends Doctrine_Hydrate {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getQuery() {
|
public function getQuery() {
|
||||||
$q = array();
|
|
||||||
|
|
||||||
foreach($this->fields as $field) {
|
foreach($this->fields as $field) {
|
||||||
$e = explode(".", $field);
|
$e = explode(".", $field);
|
||||||
@ -157,7 +159,7 @@ class Doctrine_RawSql extends Doctrine_Hydrate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$q[] = "SELECT ".implode(', ', $this->parts['select']);
|
$q = "SELECT ".implode(', ', $this->parts['select']);
|
||||||
|
|
||||||
$string = $this->applyInheritance();
|
$string = $this->applyInheritance();
|
||||||
if( ! empty($string))
|
if( ! empty($string))
|
||||||
@ -165,13 +167,17 @@ class Doctrine_RawSql extends Doctrine_Hydrate {
|
|||||||
|
|
||||||
$copy = $this->parts;
|
$copy = $this->parts;
|
||||||
unset($copy['select']);
|
unset($copy['select']);
|
||||||
foreach($copy as $name => $part) {
|
|
||||||
if(empty($part))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
$q[] = strtoupper($name).' '.implode(' ',$part);
|
$q .= ( ! empty($this->parts['from']))?" FROM ".implode(" ",$this->parts["from"]):'';
|
||||||
}
|
$q .= ( ! empty($this->parts['where']))?" WHERE ".implode(" AND ",$this->parts["where"]):'';
|
||||||
return implode(' ', $q);
|
$q .= ( ! empty($this->parts['groupby']))?" GROUP BY ".implode(", ",$this->parts["groupby"]):'';
|
||||||
|
$q .= ( ! empty($this->parts['having']))?" HAVING ".implode(" ",$this->parts["having"]):'';
|
||||||
|
$q .= ( ! empty($this->parts['orderby']))?" ORDER BY ".implode(" ",$this->parts["orderby"]):'';
|
||||||
|
|
||||||
|
if( ! empty($string))
|
||||||
|
array_pop($this->parts['where']);
|
||||||
|
|
||||||
|
return $q;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* getFields
|
* getFields
|
||||||
|
@ -759,10 +759,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
|
|||||||
if( ! is_array($key))
|
if( ! is_array($key))
|
||||||
$key = array($key);
|
$key = array($key);
|
||||||
|
|
||||||
|
|
||||||
foreach($key as $k) {
|
foreach($key as $k) {
|
||||||
if( ! isset($this->data[$k]))
|
if( ! isset($this->data[$k]))
|
||||||
throw new Doctrine_Exception("No primary key found");
|
throw new Doctrine_Exception("Primary key value for $k wasn't found");
|
||||||
|
|
||||||
$id[] = $this->data[$k];
|
$id[] = $this->data[$k];
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ class Doctrine_Validator_Notblank {
|
|||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function validate(Doctrine_Record $record, $key, $value, $args) {
|
public function validate(Doctrine_Record $record, $key, $value, $args) {
|
||||||
return (trim($var) != "");
|
return (trim($value) != "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
@ -18,6 +18,13 @@ class Doctrine_ManagerTestCase extends Doctrine_UnitTestCase {
|
|||||||
}
|
}
|
||||||
public function testGetConnections() {
|
public function testGetConnections() {
|
||||||
$this->assertEqual(count($this->manager->getConnections()),1);
|
$this->assertEqual(count($this->manager->getConnections()),1);
|
||||||
|
}
|
||||||
|
public function testClassifyTableize() {
|
||||||
|
$name = "Forum_Category";
|
||||||
|
$this->assertEqual(Doctrine::tableize($name), "forum__category");
|
||||||
|
$this->assertEqual(Doctrine::classify(Doctrine::tableize($name)), $name);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public function prepareData() { }
|
public function prepareData() { }
|
||||||
public function prepareTables() { }
|
public function prepareTables() { }
|
||||||
|
@ -110,7 +110,6 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
|
|||||||
$query->where("(((((User.name LIKE 'z%') || User.name LIKE 's%')) && User.name LIKE 'a%'))");
|
$query->where("(((((User.name LIKE 'z%') || User.name LIKE 's%')) && User.name LIKE 'a%'))");
|
||||||
$this->assertEqual($query->getQuery(), $sql);
|
$this->assertEqual($query->getQuery(), $sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSelfReferencing() {
|
public function testSelfReferencing() {
|
||||||
$query = new Doctrine_Query($this->connection);
|
$query = new Doctrine_Query($this->connection);
|
||||||
|
|
||||||
@ -187,7 +186,7 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
|
|||||||
|
|
||||||
$this->assertEqual($count, count($this->dbh));
|
$this->assertEqual($count, count($this->dbh));
|
||||||
|
|
||||||
$query->from("Forum_Category.Parent, Forum_Category.Subcategory")->where("Forum_Category.name = 'Sub 1' OR Forum_Category.name = 'Sub 2'");
|
$query->from("Forum_Category.Parent, Forum_Category.Subcategory")->where("Forum_Category.name = 'Sub 1' || Forum_Category.name = 'Sub 2'");
|
||||||
|
|
||||||
$coll = $query->execute();
|
$coll = $query->execute();
|
||||||
|
|
||||||
@ -891,19 +890,19 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
|
|||||||
$table = $this->connection->getTable("Forum_Thread")->setAttribute(Doctrine::ATTR_FETCHMODE, Doctrine::FETCH_LAZY);
|
$table = $this->connection->getTable("Forum_Thread")->setAttribute(Doctrine::ATTR_FETCHMODE, Doctrine::FETCH_LAZY);
|
||||||
$q->from("Forum_Board.Threads");
|
$q->from("Forum_Board.Threads");
|
||||||
|
|
||||||
$this->assertEqual($q->getQuery(), "SELECT forum_board.id AS forum_board__id, forum_thread.id AS forum_thread__id FROM forum_board LEFT JOIN forum_thread ON forum_board.id = forum_thread.board_id");
|
$this->assertEqual($q->getQuery(), "SELECT forum__board.id AS forum__board__id, forum__thread.id AS forum__thread__id FROM forum__board LEFT JOIN forum__thread ON forum__board.id = forum__thread.board_id");
|
||||||
$coll = $q->execute();
|
$coll = $q->execute();
|
||||||
$this->assertEqual($coll->count(), 1);
|
$this->assertEqual($coll->count(), 1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$q->from("Forum_Board-l.Threads-l");
|
$q->from("Forum_Board-l.Threads-l");
|
||||||
$this->assertEqual($q->getQuery(), "SELECT forum_board.id AS forum_board__id, forum_thread.id AS forum_thread__id FROM forum_board LEFT JOIN forum_thread ON forum_board.id = forum_thread.board_id");
|
$this->assertEqual($q->getQuery(), "SELECT forum__board.id AS forum__board__id, forum__thread.id AS forum__thread__id FROM forum__board LEFT JOIN forum__thread ON forum__board.id = forum__thread.board_id");
|
||||||
|
|
||||||
//$this->connection->clear();
|
//$this->connection->clear();
|
||||||
|
|
||||||
$q->from("Forum_Board-l.Threads-l.Entries-l");
|
$q->from("Forum_Board-l.Threads-l.Entries-l");
|
||||||
$this->assertEqual($q->getQuery(), "SELECT forum_board.id AS forum_board__id, forum_thread.id AS forum_thread__id, forum_entry.id AS forum_entry__id FROM forum_board LEFT JOIN forum_thread ON forum_board.id = forum_thread.board_id LEFT JOIN forum_entry ON forum_thread.id = forum_entry.thread_id");
|
$this->assertEqual($q->getQuery(), "SELECT forum__board.id AS forum__board__id, forum__thread.id AS forum__thread__id, forum__entry.id AS forum__entry__id FROM forum__board LEFT JOIN forum__thread ON forum__board.id = forum__thread.board_id LEFT JOIN forum__entry ON forum__thread.id = forum__entry.thread_id");
|
||||||
$boards = $q->execute();
|
$boards = $q->execute();
|
||||||
$this->assertEqual($boards->count(), 1);
|
$this->assertEqual($boards->count(), 1);
|
||||||
$count = count($this->dbh);
|
$count = count($this->dbh);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
class Doctrine_RawSql_TestCase extends Doctrine_UnitTestCase {
|
class Doctrine_RawSql_TestCase extends Doctrine_UnitTestCase {
|
||||||
|
|
||||||
public function testQueryParser() {
|
public function testQueryParser() {
|
||||||
$sql = "SELECT {p.*} FROM photos p";
|
$sql = "SELECT {p.*} FROM photos p";
|
||||||
$query = new Doctrine_RawSql($this->connection);
|
$query = new Doctrine_RawSql($this->connection);
|
||||||
@ -114,6 +115,7 @@ class Doctrine_RawSql_TestCase extends Doctrine_UnitTestCase {
|
|||||||
$this->assertTrue(is_numeric($coll[3]->id));
|
$this->assertTrue(is_numeric($coll[3]->id));
|
||||||
$this->assertTrue(is_numeric($coll[7]->id));
|
$this->assertTrue(is_numeric($coll[7]->id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testColumnAggregationInheritance() {
|
public function testColumnAggregationInheritance() {
|
||||||
// forcing the select of primary key fields
|
// forcing the select of primary key fields
|
||||||
|
|
||||||
@ -128,5 +130,26 @@ class Doctrine_RawSql_TestCase extends Doctrine_UnitTestCase {
|
|||||||
$this->assertTrue(is_numeric($coll[3]->id));
|
$this->assertTrue(is_numeric($coll[3]->id));
|
||||||
$this->assertTrue(is_numeric($coll[7]->id));
|
$this->assertTrue(is_numeric($coll[7]->id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testColumnAggregationInheritanceWithOrderBy() {
|
||||||
|
// forcing the select of primary key fields
|
||||||
|
|
||||||
|
$query = new Doctrine_RawSql($this->connection);
|
||||||
|
|
||||||
|
$query->parseQuery("SELECT {entity.name} FROM entity ORDER BY entity.name");
|
||||||
|
$query->addComponent("entity", "User");
|
||||||
|
|
||||||
|
$this->assertEqual($query->getQuery(), "SELECT entity.name AS entity__name, entity.id AS entity__id FROM entity WHERE entity.type = 0 ORDER BY entity.name");
|
||||||
|
|
||||||
|
|
||||||
|
$coll = $query->execute();
|
||||||
|
|
||||||
|
$this->assertEqual($coll->count(), 8);
|
||||||
|
$this->assertTrue(is_numeric($coll[0]->id));
|
||||||
|
$this->assertTrue(is_numeric($coll[3]->id));
|
||||||
|
$this->assertTrue(is_numeric($coll[7]->id));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
@ -28,15 +28,15 @@ require_once("QueryLimitTestCase.php");
|
|||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
|
|
||||||
$test = new GroupTest("Doctrine Framework Unit Tests");
|
$test = new GroupTest("Doctrine Framework Unit Tests");
|
||||||
|
/**
|
||||||
$test->addTestCase(new Doctrine_RecordTestCase());
|
$test->addTestCase(new Doctrine_RecordTestCase());
|
||||||
|
|
||||||
$test->addTestCase(new Doctrine_ConnectionTestCase());
|
$test->addTestCase(new Doctrine_ConnectionTestCase());
|
||||||
|
|
||||||
$test->addTestCase(new Doctrine_TableTestCase());
|
$test->addTestCase(new Doctrine_TableTestCase());
|
||||||
|
*/
|
||||||
$test->addTestCase(new Doctrine_ManagerTestCase());
|
$test->addTestCase(new Doctrine_ManagerTestCase());
|
||||||
|
/**
|
||||||
$test->addTestCase(new Doctrine_AccessTestCase());
|
$test->addTestCase(new Doctrine_AccessTestCase());
|
||||||
|
|
||||||
$test->addTestCase(new Doctrine_EventListenerTestCase());
|
$test->addTestCase(new Doctrine_EventListenerTestCase());
|
||||||
@ -63,12 +63,12 @@ $test->addTestCase(new Doctrine_ValidatorTestCase());
|
|||||||
|
|
||||||
$test->addTestCase(new Doctrine_CollectionTestCase());
|
$test->addTestCase(new Doctrine_CollectionTestCase());
|
||||||
|
|
||||||
$test->addTestCase(new Doctrine_QueryTestCase());
|
$test->addTestCase(new Doctrine_QueryTestCase());
|
||||||
|
|
||||||
$test->addTestCase(new Doctrine_RawSql_TestCase());
|
$test->addTestCase(new Doctrine_RawSql_TestCase());
|
||||||
|
|
||||||
$test->addTestCase(new Doctrine_Query_Limit_TestCase());
|
$test->addTestCase(new Doctrine_Query_Limit_TestCase());
|
||||||
|
*/
|
||||||
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
|
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
|
||||||
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
|
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user