added missing test cases
This commit is contained in:
parent
6210a60611
commit
766aec2c94
5
tests/QueryComponentAliasTestCase.php
Normal file
5
tests/QueryComponentAliasTestCase.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
class Doctrine_Query_ComponentAlias_TestCase {
|
||||
|
||||
}
|
||||
?>
|
86
tests/QueryConditionTestCase.php
Normal file
86
tests/QueryConditionTestCase.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
class Doctrine_Query_Condition_TestCase extends Doctrine_UnitTestCase {
|
||||
public function prepareData() { }
|
||||
public function prepareTables() { }
|
||||
|
||||
public function testBracktExplode() {
|
||||
$str = "item OR item || item";
|
||||
$parts = Doctrine_Query::bracketExplode($str, array(' \|\| ', ' OR '), "(", ")");
|
||||
|
||||
$this->assertEqual($parts, array('item','item','item'));
|
||||
|
||||
}
|
||||
public function testConditionParser() {
|
||||
$query = new Doctrine_Query($this->connection);
|
||||
|
||||
$query->from("User(id)")->where("User.name LIKE 'z%' || User.name LIKE 's%'");
|
||||
|
||||
$sql = "SELECT entity.id AS entity__id FROM entity WHERE (entity.name LIKE 'z%' OR entity.name LIKE 's%') AND (entity.type = 0)";
|
||||
$this->assertEqual($query->getQuery(), $sql);
|
||||
|
||||
$query->where("(User.name LIKE 'z%') || (User.name LIKE 's%')");
|
||||
$this->assertEqual($query->getQuery(), $sql);
|
||||
|
||||
$query->where("((User.name LIKE 'z%') || (User.name LIKE 's%'))");
|
||||
$this->assertEqual($query->getQuery(), $sql);
|
||||
|
||||
$query->where("(((User.name LIKE 'z%') || (User.name LIKE 's%')))");
|
||||
$this->assertEqual($query->getQuery(), $sql);
|
||||
|
||||
$query->where("(((User.name LIKE 'z%') || User.name LIKE 's%'))");
|
||||
$this->assertEqual($query->getQuery(), $sql);
|
||||
|
||||
$query->where("(User.name LIKE 'z%') || User.name LIKE 's%' && User.name LIKE 'a%'");
|
||||
|
||||
$sql = "SELECT entity.id AS entity__id FROM entity WHERE ((entity.name LIKE 'z%' OR entity.name LIKE 's%') AND entity.name LIKE 'a%') AND (entity.type = 0)";
|
||||
|
||||
$this->assertEqual($query->getQuery(), $sql);
|
||||
|
||||
$query->where("(((User.name LIKE 'z%') || User.name LIKE 's%')) && User.name LIKE 'a%'");
|
||||
$this->assertEqual($query->getQuery(), $sql);
|
||||
|
||||
$query->where("((((User.name LIKE 'z%') || User.name LIKE 's%')) && User.name LIKE 'a%')");
|
||||
$this->assertEqual($query->getQuery(), $sql);
|
||||
|
||||
$query->where("(((((User.name LIKE 'z%') || User.name LIKE 's%')) && User.name LIKE 'a%'))");
|
||||
$this->assertEqual($query->getQuery(), $sql);
|
||||
|
||||
}
|
||||
|
||||
public function testConditionParser2() {
|
||||
$query = new Doctrine_Query($this->connection);
|
||||
|
||||
$query->from("User(id)")->where("User.name LIKE 'z%' || User.name LIKE 's%'");
|
||||
|
||||
$sql = "SELECT entity.id AS entity__id FROM entity WHERE (entity.name LIKE 'z%' OR entity.name LIKE 's%') AND (entity.type = 0)";
|
||||
$this->assertEqual($query->getQuery(), $sql);
|
||||
|
||||
$query->where("(User.name LIKE 'z%') OR (User.name LIKE 's%')");
|
||||
$this->assertEqual($query->getQuery(), $sql);
|
||||
|
||||
$query->where("((User.name LIKE 'z%') OR (User.name LIKE 's%'))");
|
||||
$this->assertEqual($query->getQuery(), $sql);
|
||||
|
||||
$query->where("(((User.name LIKE 'z%') OR (User.name LIKE 's%')))");
|
||||
$this->assertEqual($query->getQuery(), $sql);
|
||||
|
||||
$query->where("(((User.name LIKE 'z%') OR User.name LIKE 's%'))");
|
||||
$this->assertEqual($query->getQuery(), $sql);
|
||||
|
||||
$query->where("(User.name LIKE 'z%') OR User.name LIKE 's%' AND User.name LIKE 'a%'");
|
||||
|
||||
$sql = "SELECT entity.id AS entity__id FROM entity WHERE ((entity.name LIKE 'z%' OR entity.name LIKE 's%') AND entity.name LIKE 'a%') AND (entity.type = 0)";
|
||||
|
||||
$this->assertEqual($query->getQuery(), $sql);
|
||||
|
||||
$query->where("(((User.name LIKE 'z%') OR User.name LIKE 's%')) AND User.name LIKE 'a%'");
|
||||
$this->assertEqual($query->getQuery(), $sql);
|
||||
|
||||
$query->where("((((User.name LIKE 'z%') OR User.name LIKE 's%')) AND User.name LIKE 'a%')");
|
||||
$this->assertEqual($query->getQuery(), $sql);
|
||||
|
||||
$query->where("(((((User.name LIKE 'z%') OR User.name LIKE 's%')) AND User.name LIKE 'a%'))");
|
||||
$this->assertEqual($query->getQuery(), $sql);
|
||||
}
|
||||
}
|
||||
?>
|
40
tests/QueryWhereTestCase.php
Normal file
40
tests/QueryWhereTestCase.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
class Doctrine_Query_Where_TestCase extends Doctrine_UnitTestCase {
|
||||
public function prepareData() { }
|
||||
public function prepareTables() {
|
||||
$this->tables = array('entity');
|
||||
parent::prepareTables();
|
||||
}
|
||||
public function testQueryWithDirectParameterSetting() {
|
||||
$this->connection->clear();
|
||||
|
||||
$user = new User();
|
||||
$user->name = 'someone';
|
||||
$user->save();
|
||||
|
||||
$q = new Doctrine_Query();
|
||||
|
||||
$q->from('User(id)')->addWhere('User.id = ?',1);
|
||||
|
||||
$users = $q->execute();
|
||||
|
||||
$this->assertEqual($users->count(), 1);
|
||||
$this->assertEqual($users[0]->name, 'someone');
|
||||
}
|
||||
public function testQueryWithDirectMultipleParameterSetting() {
|
||||
$user = new User();
|
||||
$user->name = 'someone 2';
|
||||
$user->save();
|
||||
|
||||
$q = new Doctrine_Query();
|
||||
|
||||
$q->from('User(id)')->addWhere('User.id IN (?, ?)',array(1,2));
|
||||
|
||||
$users = $q->execute();
|
||||
|
||||
$this->assertEqual($users->count(), 2);
|
||||
$this->assertEqual($users[0]->name, 'someone');
|
||||
$this->assertEqual($users[1]->name, 'someone 2');
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user