diff --git a/tests/QueryComponentAliasTestCase.php b/tests/QueryComponentAliasTestCase.php new file mode 100644 index 000000000..fae1e426e --- /dev/null +++ b/tests/QueryComponentAliasTestCase.php @@ -0,0 +1,5 @@ +<?php +class Doctrine_Query_ComponentAlias_TestCase { + +} +?> diff --git a/tests/QueryConditionTestCase.php b/tests/QueryConditionTestCase.php new file mode 100644 index 000000000..715a4d540 --- /dev/null +++ b/tests/QueryConditionTestCase.php @@ -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); + } +} +?> diff --git a/tests/QueryWhereTestCase.php b/tests/QueryWhereTestCase.php new file mode 100644 index 000000000..7d0eb7890 --- /dev/null +++ b/tests/QueryWhereTestCase.php @@ -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'); + } +} +?>