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);
|
||||
|
||||
$name = $this->tables[$keys[0]]->getComponentName();
|
||||
|
||||
|
||||
$stmt = $this->connection->execute($query,$params);
|
||||
|
||||
while($data = $stmt->fetch(PDO::FETCH_ASSOC)):
|
||||
|
||||
foreach($data as $key => $value):
|
||||
$e = explode("__",$key);
|
||||
if(count($e) > 1) {
|
||||
$data[$e[1]] = $value;
|
||||
|
||||
$data[end($e)] = $value;
|
||||
} else {
|
||||
$data[$e[0]] = $value;
|
||||
}
|
||||
@ -269,6 +273,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
|
||||
endforeach;
|
||||
$this->data[$name][] = $data;
|
||||
endwhile;
|
||||
|
||||
|
||||
return $this->getCollection($keys[0]);
|
||||
break;
|
||||
@ -278,7 +283,9 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
|
||||
|
||||
if($this->isLimitSubqueryUsed())
|
||||
$params = array_merge($params, $params);
|
||||
|
||||
|
||||
|
||||
$stmt = $this->connection->execute($query,$params);
|
||||
|
||||
$previd = array();
|
||||
@ -292,6 +299,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
|
||||
return $this->hydrateHolders($array);
|
||||
} elseif($return == Doctrine::FETCH_ARRAY)
|
||||
return $array;
|
||||
|
||||
|
||||
|
||||
foreach($array as $data) {
|
||||
/**
|
||||
@ -504,15 +513,15 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
|
||||
foreach($data as $key => $value):
|
||||
$e = explode("__",$key);
|
||||
|
||||
if(count($e) > 1) {
|
||||
$data[$e[0]][$e[1]] = $value;
|
||||
} else {
|
||||
$data[0][$e[0]] = $value;
|
||||
}
|
||||
$field = array_pop($e);
|
||||
$component = implode("__",$e);
|
||||
$data[$component][$field] = $value;
|
||||
|
||||
unset($data[$key]);
|
||||
endforeach;
|
||||
$array[] = $data;
|
||||
endwhile;
|
||||
|
||||
$stmt->closeCursor();
|
||||
return $array;
|
||||
}
|
||||
|
@ -94,8 +94,10 @@ class Doctrine_RawSql extends Doctrine_Hydrate {
|
||||
case "group":
|
||||
$i = ($k + 1);
|
||||
if(isset($e[$i]) && strtolower($e[$i]) === "by") {
|
||||
$p = $part;
|
||||
$parts[$low] = array();
|
||||
$p = $low;
|
||||
$p .= "by";
|
||||
$parts[$low."by"] = array();
|
||||
|
||||
} else
|
||||
$parts[$p][] = $part;
|
||||
break;
|
||||
@ -121,7 +123,7 @@ class Doctrine_RawSql extends Doctrine_Hydrate {
|
||||
* @return string
|
||||
*/
|
||||
public function getQuery() {
|
||||
$q = array();
|
||||
|
||||
|
||||
foreach($this->fields as $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();
|
||||
if( ! empty($string))
|
||||
@ -165,13 +167,17 @@ class Doctrine_RawSql extends Doctrine_Hydrate {
|
||||
|
||||
$copy = $this->parts;
|
||||
unset($copy['select']);
|
||||
foreach($copy as $name => $part) {
|
||||
if(empty($part))
|
||||
continue;
|
||||
|
||||
$q[] = strtoupper($name).' '.implode(' ',$part);
|
||||
}
|
||||
return implode(' ', $q);
|
||||
$q .= ( ! empty($this->parts['from']))?" FROM ".implode(" ",$this->parts["from"]):'';
|
||||
$q .= ( ! empty($this->parts['where']))?" WHERE ".implode(" AND ",$this->parts["where"]):'';
|
||||
$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
|
||||
|
@ -759,10 +759,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
|
||||
if( ! is_array($key))
|
||||
$key = array($key);
|
||||
|
||||
|
||||
foreach($key as $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];
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ class Doctrine_Validator_Notblank {
|
||||
* @return boolean
|
||||
*/
|
||||
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() {
|
||||
$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 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%'))");
|
||||
$this->assertEqual($query->getQuery(), $sql);
|
||||
}
|
||||
|
||||
public function testSelfReferencing() {
|
||||
$query = new Doctrine_Query($this->connection);
|
||||
|
||||
@ -187,7 +186,7 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
|
||||
|
||||
$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();
|
||||
|
||||
@ -891,19 +890,19 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
|
||||
$table = $this->connection->getTable("Forum_Thread")->setAttribute(Doctrine::ATTR_FETCHMODE, Doctrine::FETCH_LAZY);
|
||||
$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();
|
||||
$this->assertEqual($coll->count(), 1);
|
||||
|
||||
|
||||
|
||||
$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();
|
||||
|
||||
$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();
|
||||
$this->assertEqual($boards->count(), 1);
|
||||
$count = count($this->dbh);
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
class Doctrine_RawSql_TestCase extends Doctrine_UnitTestCase {
|
||||
|
||||
public function testQueryParser() {
|
||||
$sql = "SELECT {p.*} FROM photos p";
|
||||
$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[7]->id));
|
||||
}
|
||||
|
||||
public function testColumnAggregationInheritance() {
|
||||
// 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[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);
|
||||
|
||||
$test = new GroupTest("Doctrine Framework Unit Tests");
|
||||
|
||||
/**
|
||||
$test->addTestCase(new Doctrine_RecordTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_ConnectionTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_TableTestCase());
|
||||
|
||||
*/
|
||||
$test->addTestCase(new Doctrine_ManagerTestCase());
|
||||
|
||||
/**
|
||||
$test->addTestCase(new Doctrine_AccessTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_EventListenerTestCase());
|
||||
@ -63,12 +63,12 @@ $test->addTestCase(new Doctrine_ValidatorTestCase());
|
||||
|
||||
$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_Query_Limit_TestCase());
|
||||
|
||||
*/
|
||||
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
|
||||
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user