. */ /** * Doctrine_Query_TestCase * * @package Doctrine * @author Konsta Vesterinen * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @category Object Relational Mapping * @link www.phpdoctrine.org * @since 1.0 * @version $Revision$ */ class Doctrine_Query_TestCase extends Doctrine_UnitTestCase { public function testGetQueryHookResetsTheManuallyAddedDqlParts() { $q = new MyQuery(); $q->from('User u'); $this->assertEqual($q->getQuery(), 'SELECT e.id AS e__id, e.name AS e__name, e.loginname AS e__loginname, e.password AS e__password, e.type AS e__type, e.created AS e__created, e.updated AS e__updated, e.email_id AS e__email_id FROM entity e WHERE e.id = 4 AND (e.type = 0)'); // test consequent calls $this->assertEqual($q->getQuery(), 'SELECT e.id AS e__id, e.name AS e__name, e.loginname AS e__loginname, e.password AS e__password, e.type AS e__type, e.created AS e__created, e.updated AS e__updated, e.email_id AS e__email_id FROM entity e WHERE e.id = 4 AND (e.type = 0)'); } public function testParseClauseSupportsArithmeticOperators() { $q = new Doctrine_Query(); $str = $q->parseClause('2 + 3'); $this->assertEqual($str, '2 + 3'); $str = $q->parseClause('2 + 3 - 5 * 6'); $this->assertEqual($str, '2 + 3 - 5 * 6'); } public function testParseClauseSupportsArithmeticOperatorsWithFunctions() { $q = new Doctrine_Query(); $str = $q->parseClause('ACOS(2) + 3'); $this->assertEqual($str, 'ACOS(2) + 3'); } public function testParseClauseSupportsArithmeticOperatorsWithParenthesis() { $q = new Doctrine_Query(); $str = $q->parseClause('(3 + 3)*3'); $this->assertEqual($str, '(3 + 3)*3'); $str = $q->parseClause('((3 + 3)*3 - 123) * 12 * (13 + 31)'); $this->assertEqual($str, '((3 + 3)*3 - 123) * 12 * (13 + 31)'); } public function testParseClauseSupportsArithmeticOperatorsWithParenthesisAndFunctions() { $q = new Doctrine_Query(); $str = $q->parseClause('(3 + 3)*ACOS(3)'); $this->assertEqual($str, '(3 + 3)*ACOS(3)'); $str = $q->parseClause('((3 + 3)*3 - 123) * ACOS(12) * (13 + 31)'); $this->assertEqual($str, '((3 + 3)*3 - 123) * ACOS(12) * (13 + 31)'); } public function testParseClauseSupportsComponentReferences() { $q = new Doctrine_Query(); $q->from('User u')->leftJoin('u.Phonenumber p'); $q->getQuery(); //Doctrine::dump($q->getCachedForm(array('foo' => 'bar'))); $this->assertEqual($q->parseClause("CONCAT('u.name', u.name)"), "'u.name' || e.name"); } public function testUsingDuplicateClassAliasThrowsException() { $q = new Doctrine_Query(); $q->from('User u')->leftJoin('u.Phonenumber u'); try { $q->getSqlQuery(); $this->fail(); } catch (Doctrine_Query_Exception $e) { $this->pass(); } $q = new Doctrine_Query(); $q->parseDqlQuery('FROM User u, u.Phonenumber u'); try { $q->getSqlQuery(); $this->fail(); } catch (Doctrine_Query_Exception $e) { $this->pass(); } } } class MyQuery extends Doctrine_Query { public function preQuery() { $this->where('u.id = 4'); } }