2008-05-24 22:18:37 +04:00
< ? php
2009-02-18 10:59:11 +03:00
namespace Doctrine\Tests\ORM\Query ;
2008-05-25 02:04:14 +04:00
2009-12-27 06:26:15 +03:00
use Doctrine\ORM\Query ,
Doctrine\ORM\Query\QueryException ;
2009-10-15 18:39:43 +04:00
2009-02-18 10:59:11 +03:00
require_once __DIR__ . '/../../TestInit.php' ;
class LanguageRecognitionTest extends \Doctrine\Tests\OrmTestCase
2008-05-24 22:18:37 +04:00
{
2009-02-18 10:59:11 +03:00
private $_em ;
protected function setUp ()
{
$this -> _em = $this -> _getTestEntityManager ();
}
2010-12-28 12:17:33 +03:00
public function assertValidDQL ( $dql , $debug = false )
2008-05-24 22:18:37 +04:00
{
try {
2009-07-16 07:22:08 +04:00
$parserResult = $this -> parseDql ( $dql );
2009-12-27 06:26:15 +03:00
} catch ( QueryException $e ) {
2008-08-31 22:27:16 +04:00
if ( $debug ) {
echo $e -> getTraceAsString () . PHP_EOL ;
}
2011-12-20 01:56:19 +04:00
2008-05-24 22:18:37 +04:00
$this -> fail ( $e -> getMessage ());
}
}
2010-12-28 12:17:33 +03:00
public function assertInvalidDQL ( $dql , $debug = false )
2008-05-24 22:18:37 +04:00
{
try {
2009-07-16 07:22:08 +04:00
$parserResult = $this -> parseDql ( $dql );
2011-12-20 01:56:19 +04:00
2008-05-24 22:18:37 +04:00
$this -> fail ( 'No syntax errors were detected, when syntax errors were expected' );
2009-12-27 06:26:15 +03:00
} catch ( QueryException $e ) {
2008-08-31 22:27:16 +04:00
if ( $debug ) {
echo $e -> getMessage () . PHP_EOL ;
echo $e -> getTraceAsString () . PHP_EOL ;
}
2008-05-24 22:18:37 +04:00
}
}
2011-12-20 01:56:19 +04:00
2009-07-18 18:53:21 +04:00
public function parseDql ( $dql , $hints = array ())
2009-07-16 07:22:08 +04:00
{
$query = $this -> _em -> createQuery ( $dql );
2009-10-15 18:39:43 +04:00
$query -> setHint ( Query :: HINT_FORCE_PARTIAL_LOAD , true );
2009-07-16 07:22:08 +04:00
$query -> setDql ( $dql );
2011-12-20 01:56:19 +04:00
2009-07-18 18:53:21 +04:00
foreach ( $hints as $key => $value ) {
$query -> setHint ( $key , $value );
}
2011-12-20 01:56:19 +04:00
2009-07-16 07:22:08 +04:00
$parser = new \Doctrine\ORM\Query\Parser ( $query );
2011-12-20 01:56:19 +04:00
2009-08-13 14:13:06 +04:00
// We do NOT test SQL output here. That only unnecessarily slows down the tests!
$parser -> setCustomOutputTreeWalker ( 'Doctrine\Tests\Mocks\MockTreeWalker' );
2011-12-20 01:56:19 +04:00
2009-07-16 07:22:08 +04:00
return $parser -> parse ();
}
2011-12-20 01:56:19 +04:00
2008-05-24 22:18:37 +04:00
public function testEmptyQueryString ()
{
2010-12-28 12:17:33 +03:00
$this -> assertInvalidDQL ( '' );
2008-05-24 22:18:37 +04:00
}
public function testPlainFromClauseWithAlias ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u' );
2008-05-24 22:18:37 +04:00
}
public function testSelectSingleComponentWithAsterisk ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u' );
2008-05-24 22:18:37 +04:00
}
public function testSelectSingleComponentWithMultipleColumns ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u.name, u.username FROM Doctrine\Tests\Models\CMS\CmsUser u' );
2008-05-24 22:18:37 +04:00
}
2010-07-20 07:51:01 +04:00
public function testSelectMultipleComponentsUsingMultipleFrom ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u, p FROM Doctrine\Tests\Models\CMS\CmsUser u, Doctrine\Tests\Models\CMS\CmsPhonenumber p WHERE u = p.user' );
2010-07-20 07:51:01 +04:00
}
2008-05-24 22:18:37 +04:00
public function testSelectMultipleComponentsWithAsterisk ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u, p FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.phonenumbers p' );
2008-05-24 22:18:37 +04:00
}
public function testSelectDistinctIsSupported ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT DISTINCT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u' );
2008-05-24 22:18:37 +04:00
}
public function testAggregateFunctionInSelect ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT COUNT(u.id) FROM Doctrine\Tests\Models\CMS\CmsUser u' );
2010-01-01 01:48:51 +03:00
}
2011-12-20 01:56:19 +04:00
2010-01-01 01:48:51 +03:00
public function testDuplicatedAliasInAggregateFunction ()
{
2010-12-28 12:17:33 +03:00
$this -> assertInvalidDQL ( 'SELECT COUNT(u.id) AS num, SUM(u.id) AS num FROM Doctrine\Tests\Models\CMS\CmsUser u' );
2008-05-24 22:18:37 +04:00
}
public function testAggregateFunctionWithDistinctInSelect ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT COUNT(DISTINCT u.name) FROM Doctrine\Tests\Models\CMS\CmsUser u' );
2008-05-24 22:18:37 +04:00
}
2009-03-15 00:19:50 +03:00
2008-05-24 22:18:37 +04:00
public function testFunctionalExpressionsSupportedInWherePart ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( " SELECT u.name FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE TRIM(u.name) = 'someone' " );
2008-05-24 22:18:37 +04:00
}
2009-03-15 00:19:50 +03:00
2008-05-24 22:18:37 +04:00
public function testArithmeticExpressionsSupportedInWherePart ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE ((u.id + 5000) * u.id + 3) < 10000000' );
2008-05-24 22:18:37 +04:00
}
2011-12-20 01:56:19 +04:00
2008-05-24 22:18:37 +04:00
public function testInExpressionSupportedInWherePart ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id IN (1, 2)' );
2008-05-24 22:18:37 +04:00
}
2011-12-20 01:56:19 +04:00
2010-03-23 20:42:34 +03:00
public function testInExpressionWithoutSpacesSupportedInWherePart ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id IN (1,2,3)' );
2010-03-23 20:42:34 +03:00
}
2008-05-24 22:18:37 +04:00
public function testNotInExpressionSupportedInWherePart ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id NOT IN (1)' );
2008-05-24 22:18:37 +04:00
}
2009-03-17 01:12:38 +03:00
2010-08-12 07:16:07 +04:00
public function testInExpressionWithSingleValuedAssociationPathExpression ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( " SELECT u FROM Doctrine \T ests \ Models \ Forum \ ForumUser u WHERE u.avatar IN (?1, ?2) " );
2010-08-12 07:16:07 +04:00
}
public function testInvalidInExpressionWithCollectionValuedAssociationPathExpression ()
{
2010-12-28 12:17:33 +03:00
$this -> assertInvalidDQL ( " SELECT u FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE u.phonenumbers IN (?1, ?2) " );
2010-08-12 07:16:07 +04:00
}
2010-07-30 08:30:02 +04:00
public function testInstanceOfExpressionSupportedInWherePart ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF Doctrine\Tests\Models\Company\CompanyEmployee' );
2010-07-30 08:30:02 +04:00
}
public function testInstanceOfExpressionWithInputParamSupportedInWherePart ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF ?1' );
2010-07-30 08:30:02 +04:00
}
public function testNotInstanceOfExpressionSupportedInWherePart ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u NOT INSTANCE OF ?1' );
2010-07-30 08:30:02 +04:00
}
2011-12-20 01:56:19 +04:00
2009-03-15 00:19:50 +03:00
public function testExistsExpressionSupportedInWherePart ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE EXISTS (SELECT p.phonenumber FROM Doctrine\Tests\Models\CMS\CmsPhonenumber p WHERE p.phonenumber = 1234)' );
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
2008-05-24 22:18:37 +04:00
public function testNotExistsExpressionSupportedInWherePart ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE NOT EXISTS (SELECT p.phonenumber FROM Doctrine\Tests\Models\CMS\CmsPhonenumber p WHERE p.phonenumber = 1234)' );
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testAggregateFunctionInHavingClause ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.phonenumbers p HAVING COUNT(p.phonenumber) > 2' );
$this -> assertValidDQL ( " SELECT u.name FROM Doctrine \T ests \ Models \ CMS \ CmsUser u LEFT JOIN u.phonenumbers p HAVING MAX(u.name) = 'romanb' " );
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testLeftJoin ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u, p FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.phonenumbers p' );
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testJoin ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u,p FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.phonenumbers p' );
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testInnerJoin ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u, p FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.phonenumbers p' );
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testMultipleLeftJoin ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u, a, p FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a LEFT JOIN u.phonenumbers p' );
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testMultipleInnerJoin ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.articles a INNER JOIN u.phonenumbers p' );
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testMixingOfJoins ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u.name, a.topic, p.phonenumber FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.articles a LEFT JOIN u.phonenumbers p' );
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testOrderBySingleColumn ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY u.name' );
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testOrderBySingleColumnAscending ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY u.name ASC' );
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testOrderBySingleColumnDescending ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY u.name DESC' );
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testOrderByMultipleColumns ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u.name, u.username FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY u.username DESC, u.name DESC' );
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testSubselectInInExpression ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( " SELECT u FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE u.id NOT IN (SELECT u2.id FROM Doctrine \T ests \ Models \ CMS \ CmsUser u2 WHERE u2.name = 'zYne') " );
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testSubselectInSelectPart ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( " SELECT u.name, (SELECT COUNT(p.phonenumber) FROM Doctrine \T ests \ Models \ CMS \ CmsPhonenumber p WHERE p.phonenumber = 1234) pcount FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE u.name = 'jon' " );
2008-05-24 22:18:37 +04:00
}
2010-08-12 06:12:44 +04:00
public function testArithmeticExpressionInSelectPart ()
2010-07-15 17:55:35 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( " SELECT SUM(u.id) / COUNT(u.id) FROM Doctrine \T ests \ Models \ CMS \ CmsUser u " );
2010-08-12 06:12:44 +04:00
}
2010-07-15 17:55:35 +04:00
2010-08-12 06:12:44 +04:00
public function testArithmeticExpressionInSubselectPart ()
2010-07-15 17:55:35 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( " SELECT (SELECT SUM(u.id) / COUNT(u.id) FROM Doctrine \T ests \ Models \ CMS \ CmsUser u2) value FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE u.name = 'jon' " );
2010-08-12 06:12:44 +04:00
}
public function testArithmeticExpressionWithParenthesisInSubselectPart ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( " SELECT (SELECT (SUM(u.id) / COUNT(u.id)) FROM Doctrine \T ests \ Models \ CMS \ CmsUser u2) value FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE u.name = 'jon' " );
2010-08-12 06:12:44 +04:00
}
2011-03-27 16:04:53 +04:00
/**
* @ group DDC - 1079
*/
public function testSelectLiteralInSubselect ()
{
$this -> assertValidDQL ( 'SELECT (SELECT 1 FROM Doctrine\Tests\Models\CMS\CmsUser u2) value FROM Doctrine\Tests\Models\CMS\CmsUser u' );
$this -> assertValidDQL ( 'SELECT (SELECT 0 FROM Doctrine\Tests\Models\CMS\CmsUser u2) value FROM Doctrine\Tests\Models\CMS\CmsUser u' );
}
2011-03-27 23:10:50 +04:00
/**
* @ group DDC - 1077
*/
public function testConstantValueInSelect ()
{
$this -> assertValidDQL ( " SELECT u.name, 'foo' AS bar FROM Doctrine \T ests \ Models \ CMS \ CmsUser u " , true );
}
2010-08-12 06:12:44 +04:00
public function testDuplicateAliasInSubselectPart ()
{
2010-12-28 12:17:33 +03:00
$this -> assertInvalidDQL ( " SELECT (SELECT SUM(u.id) / COUNT(u.id) AS foo FROM Doctrine \T ests \ Models \ CMS \ CmsUser u2) foo FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE u.name = 'jon' " );
2010-08-12 06:12:44 +04:00
}
2010-07-15 17:55:35 +04:00
2009-03-19 15:43:48 +03:00
public function testPositionalInputParameter ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = ?1' );
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testNamedInputParameter ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :id' );
2008-05-24 22:18:37 +04:00
}
2010-02-20 00:28:17 +03:00
public function testJoinConditionOverrideNotSupported ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertInvalidDQL ( " SELECT u.name, p FROM Doctrine \T ests \ Models \ CMS \ CmsUser u LEFT JOIN u.phonenumbers p ON p.phonenumber = '123 123' " );
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testIndexByClauseWithOneComponent ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u INDEX BY u.id' );
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testIndexBySupportsJoins ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a INDEX BY a.id' ); // INDEX BY is now referring to articles
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testIndexBySupportsJoins2 ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u, p FROM Doctrine\Tests\Models\CMS\CmsUser u INDEX BY u.id LEFT JOIN u.phonenumbers p INDEX BY p.phonenumber' );
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testBetweenExpressionSupported ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( " SELECT u FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE u.name BETWEEN 'jepso' AND 'zYne' " );
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testNotBetweenExpressionSupported ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( " SELECT u FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE u.name NOT BETWEEN 'jepso' AND 'zYne' " );
2008-05-24 22:18:37 +04:00
}
2008-05-25 02:04:14 +04:00
2009-03-19 15:43:48 +03:00
public function testLikeExpression ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( " SELECT u.id FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE u.name LIKE 'z%' " );
2008-05-24 22:18:37 +04:00
}
2008-05-25 02:04:14 +04:00
2009-03-19 15:43:48 +03:00
public function testNotLikeExpression ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( " SELECT u.id FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE u.name NOT LIKE 'z%' " );
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testLikeExpressionWithCustomEscapeCharacter ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( " SELECT u.id FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE u.name LIKE 'z|%' ESCAPE '|' " );
2008-05-24 22:18:37 +04:00
}
2009-07-21 09:22:22 +04:00
2009-12-27 06:26:15 +03:00
public function testFieldComparisonWithoutAlias ()
{
2010-12-28 12:17:33 +03:00
$this -> assertInvalidDQL ( " SELECT u FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE id = 1 " );
2009-12-27 06:26:15 +03:00
}
2011-12-20 01:56:19 +04:00
2009-12-27 06:26:15 +03:00
public function testDuplicatedAliasDeclaration ()
{
2010-12-28 12:17:33 +03:00
$this -> assertInvalidDQL ( " SELECT u FROM Doctrine \T ests \ Models \ CMS \ CmsUser u INNER JOIN u.articles u WHERE u.id = 1 " );
2009-12-27 06:26:15 +03:00
}
2010-02-20 00:28:17 +03:00
public function testImplicitJoinInWhereOnSingleValuedAssociationPathExpression ()
2008-05-24 22:18:37 +04:00
{
2009-03-19 15:43:48 +03:00
// This should be allowed because avatar is a single-value association.
// SQL: SELECT ... FROM forum_user fu INNER JOIN forum_avatar fa ON fu.avatar_id = fa.id WHERE fa.id = ?
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( " SELECT u FROM Doctrine \T ests \ Models \ Forum \ ForumUser u JOIN u.avatar a WHERE a.id = ?1 " );
2010-02-20 00:28:17 +03:00
}
2009-07-21 09:22:22 +04:00
2009-03-19 15:43:48 +03:00
public function testImplicitJoinInWhereOnCollectionValuedPathExpression ()
2008-05-24 22:18:37 +04:00
{
2009-03-19 15:43:48 +03:00
// This should be forbidden, because articles is a collection
2010-12-28 12:17:33 +03:00
$this -> assertInvalidDQL ( " SELECT u FROM Doctrine \T ests \ Models \ CMS \ CmsUser u JOIN u.articles a WHERE a.title = ? " );
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testInvalidSyntaxIsRejected ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertInvalidDQL ( " FOOBAR CmsUser " );
$this -> assertInvalidDQL ( " DELETE FROM Doctrine \T ests \ Models \ CMS \ CmsUser.articles " );
$this -> assertInvalidDQL ( " SELECT u FROM Doctrine \T ests \ Models \ CMS \ CmsUser u JOIN u.articles.comments " );
2008-05-25 02:04:14 +04:00
2009-03-19 15:43:48 +03:00
// Currently UNDEFINED OFFSET error
2010-12-28 12:17:33 +03:00
$this -> assertInvalidDQL ( " SELECT c FROM CmsUser.articles.comments c " );
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testUpdateWorksWithOneField ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( " UPDATE Doctrine \T ests \ Models \ CMS \ CmsUser u SET u.name = 'someone' " );
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testUpdateWorksWithMultipleFields ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( " UPDATE Doctrine \T ests \ Models \ CMS \ CmsUser u SET u.name = 'someone', u.username = 'some' " );
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testUpdateSupportsConditions ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( " UPDATE Doctrine \T ests \ Models \ CMS \ CmsUser u SET u.name = 'someone' WHERE u.id = 5 " );
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testDeleteAll ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'DELETE FROM Doctrine\Tests\Models\CMS\CmsUser u' );
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
public function testDeleteWithCondition ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'DELETE FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = 3' );
2008-05-24 22:18:37 +04:00
}
2009-03-19 15:43:48 +03:00
/**
* The main use case for this generalized style of join is when a join condition
* does not involve a foreign key relationship that is mapped to an entity relationship .
*/
public function testImplicitJoinWithCartesianProductAndConditionInWhere ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( " SELECT u, a FROM Doctrine \T ests \ Models \ CMS \ CmsUser u, Doctrine \T ests \ Models \ CMS \ CmsArticle a WHERE u.name = a.topic " );
2008-05-24 22:18:37 +04:00
}
2009-03-28 20:10:41 +03:00
public function testAllExpressionWithCorrelatedSubquery ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id > ALL (SELECT u2.id FROM Doctrine\Tests\Models\CMS\CmsUser u2 WHERE u2.name = u.name)' );
2008-05-24 22:18:37 +04:00
}
2009-03-28 20:10:41 +03:00
public function testCustomJoinsAndWithKeywordSupported ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u, p FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.phonenumbers p WITH p.phonenumber = 123 WHERE u.id = 1' );
2008-05-24 22:18:37 +04:00
}
2008-08-31 22:27:16 +04:00
public function testAnyExpressionWithCorrelatedSubquery ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id > ANY (SELECT u2.id FROM Doctrine\Tests\Models\CMS\CmsUser u2 WHERE u2.name = u.name)' );
2008-05-24 22:18:37 +04:00
}
2008-08-31 22:27:16 +04:00
public function testSomeExpressionWithCorrelatedSubquery ()
2008-05-24 22:18:37 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id > SOME (SELECT u2.id FROM Doctrine\Tests\Models\CMS\CmsUser u2 WHERE u2.name = u.name)' );
2008-05-24 22:18:37 +04:00
}
2010-02-20 21:27:05 +03:00
2010-08-12 06:12:44 +04:00
public function testArithmeticExpressionWithoutParenthesisInWhereClause ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE SIZE(u.phonenumbers) + 1 > 10' );
2010-08-12 06:12:44 +04:00
}
2009-06-14 21:34:28 +04:00
public function testMemberOfExpression ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE :param MEMBER OF u.phonenumbers' );
//$this->assertValidDQL("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE 'Joe' MEMBER OF u.nicknames");
2009-06-14 21:34:28 +04:00
}
2011-12-20 01:56:19 +04:00
2009-08-05 19:47:41 +04:00
public function testSizeFunction ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE SIZE(u.phonenumbers) > 1' );
2009-08-05 19:47:41 +04:00
}
2011-12-20 01:56:19 +04:00
2009-08-05 19:47:41 +04:00
public function testEmptyCollectionComparisonExpression ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.phonenumbers IS EMPTY' );
2009-08-05 19:47:41 +04:00
}
2011-12-20 01:56:19 +04:00
2009-08-13 14:13:06 +04:00
public function testSingleValuedAssociationFieldInWhere ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.address = ?1' );
$this -> assertValidDQL ( 'SELECT p FROM Doctrine\Tests\Models\CMS\CmsPhonenumber p WHERE p.user = ?1' );
2009-08-13 14:13:06 +04:00
}
2011-12-20 01:56:19 +04:00
2009-10-13 14:48:46 +04:00
public function testBooleanLiteralInWhere ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT b FROM Doctrine\Tests\Models\Generic\BooleanModel b WHERE b.booleanField = true' );
2009-10-13 14:48:46 +04:00
}
2011-12-20 01:56:19 +04:00
2009-12-27 21:46:53 +03:00
public function testSubqueryInSelectExpression ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'select u, (select max(p.phonenumber) from Doctrine\Tests\Models\CMS\CmsPhonenumber p) maxId from Doctrine\Tests\Models\CMS\CmsUser u' );
2009-12-27 21:46:53 +03:00
}
2011-12-20 01:56:19 +04:00
2009-12-27 21:46:53 +03:00
public function testUsageOfQComponentOutsideSubquery ()
{
2010-12-28 12:17:33 +03:00
$this -> assertInvalidDQL ( 'select u, (select max(p.phonenumber) from Doctrine\Tests\Models\CMS\CmsPhonenumber p) maxId from Doctrine\Tests\Models\CMS\CmsUser u WHERE p.user = ?1' );
2009-12-27 21:46:53 +03:00
}
2011-12-20 01:56:19 +04:00
2009-12-27 22:02:07 +03:00
public function testUnknownAbstractSchemaName ()
{
2010-12-28 12:17:33 +03:00
$this -> assertInvalidDQL ( 'SELECT u FROM UnknownClassName u' );
2009-12-27 22:02:07 +03:00
}
2011-12-20 01:56:19 +04:00
2010-02-20 00:28:17 +03:00
public function testCorrectPartialObjectLoad ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT PARTIAL u.{id,name} FROM Doctrine\Tests\Models\CMS\CmsUser u' );
2010-02-20 00:28:17 +03:00
}
2011-12-20 01:56:19 +04:00
2010-02-20 00:28:17 +03:00
public function testIncorrectPartialObjectLoadBecauseOfMissingIdentifier ()
{
2010-12-28 12:17:33 +03:00
$this -> assertInvalidDQL ( 'SELECT PARTIAL u.{name} FROM Doctrine\Tests\Models\CMS\CmsUser u' );
2010-02-20 00:28:17 +03:00
}
2011-12-20 01:56:19 +04:00
2010-02-20 00:28:17 +03:00
public function testScalarExpressionInSelect ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u, 42 + u.id AS someNumber FROM Doctrine\Tests\Models\CMS\CmsUser u' );
2010-02-20 00:28:17 +03:00
}
2011-12-20 01:56:19 +04:00
2010-02-20 00:28:17 +03:00
public function testInputParameterInSelect ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u, u.id + ?1 AS someNumber FROM Doctrine\Tests\Models\CMS\CmsUser u' );
2010-02-20 00:28:17 +03:00
}
2010-05-19 00:19:08 +04:00
2011-05-01 13:01:30 +04:00
/**
* @ group DDC - 1091
*/
public function testCustomFunctionsReturningStringInStringPrimary ()
{
$this -> _em -> getConfiguration () -> addCustomStringFunction ( 'CC' , 'Doctrine\ORM\Query\AST\Functions\ConcatFunction' );
$this -> assertValidDQL ( " SELECT u FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE CC('%', u.name) LIKE '%foo%' " , true );
}
2010-05-19 00:19:08 +04:00
/**
* @ group DDC - 505
*/
2010-02-20 21:27:05 +03:00
public function testDQLKeywordInJoinIsAllowed ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT u FROM ' . __NAMESPACE__ . '\DQLKeywordsModelUser u JOIN u.group g' );
2010-02-20 21:27:05 +03:00
}
2010-02-20 00:28:17 +03:00
2010-05-19 00:19:08 +04:00
/**
* @ group DDC - 505
*/
public function testDQLKeywordInConditionIsAllowed ()
{
2010-12-28 12:17:33 +03:00
$this -> assertValidDQL ( 'SELECT g FROM ' . __NAMESPACE__ . '\DQLKeywordsModelGroup g WHERE g.from=0' );
2010-05-19 00:19:08 +04:00
}
2010-02-20 00:28:17 +03:00
/* The exception is currently thrown in the SQLWalker , not earlier .
public function testInverseSideSingleValuedAssociationPathNotAllowed ()
2009-07-16 07:22:08 +04:00
{
2010-12-28 12:17:33 +03:00
$this -> assertInvalidDQL ( 'SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.address = ?1' );
2009-07-16 07:22:08 +04:00
}
2010-02-20 00:28:17 +03:00
*/
2011-12-20 01:56:19 +04:00
2010-12-28 12:17:33 +03:00
/**
* @ group DDC - 617
*/
public function testSelectOnlyNonRootEntityAlias ()
{
$this -> assertInvalidDQL ( 'SELECT g FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.groups g' );
}
2011-01-01 20:17:19 +03:00
2011-04-30 14:27:16 +04:00
/**
* @ group DDC - 1108
*/
public function testInputParameterSingleChar ()
{
$this -> assertValidDQL ( 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = :q' );
}
2011-03-20 16:07:33 +03:00
/**
* @ group DDC - 1053
*/
public function testGroupBy ()
{
$this -> assertValidDQL ( 'SELECT g.id, count(u.id) FROM Doctrine\Tests\Models\CMS\CmsGroup g JOIN g.users u GROUP BY g.id' );
}
/**
* @ group DDC - 1053
*/
public function testGroupByIdentificationVariable ()
{
$this -> assertValidDQL ( 'SELECT g, count(u.id) FROM Doctrine\Tests\Models\CMS\CmsGroup g JOIN g.users u GROUP BY g' );
}
/**
* @ group DDC - 1053
*/
public function testGroupByUnknownIdentificationVariable ()
{
$this -> assertInvalidDQL ( 'SELECT g, count(u.id) FROM Doctrine\Tests\Models\CMS\CmsGroup g JOIN g.users u GROUP BY m' );
}
2011-01-01 20:17:19 +03:00
/**
* @ group DDC - 117
*/
public function testSizeOfForeignKeyOneToManyPrimaryKeyEntity ()
{
$this -> assertValidDQL ( " SELECT a, t FROM Doctrine \T ests \ Models \ DDC117 \ DDC117Article a JOIN a.translations t WHERE SIZE(a.translations) > 0 " );
}
/**
* @ group DDC - 117
*/
public function testSizeOfForeignKeyManyToManyPrimaryKeyEntity ()
{
$this -> assertValidDQL ( " SELECT e, t FROM Doctrine \T ests \ Models \ DDC117 \ DDC117Editor e JOIN e.reviewingTranslations t WHERE SIZE(e.reviewingTranslations) > 0 " );
}
2011-12-20 01:56:19 +04:00
2011-06-17 23:16:22 +04:00
public function testCaseSupportContainingNullIfExpression ()
{
$this -> assertValidDQL ( " SELECT u.id, NULLIF(u.name, u.name) AS shouldBeNull FROM Doctrine \T ests \ Models \ CMS \ CmsUser u " );
}
2011-12-20 01:56:19 +04:00
2011-06-17 23:16:22 +04:00
public function testCaseSupportContainingCoalesceExpression ()
{
$this -> assertValidDQL ( " select COALESCE(NULLIF(u.name, ''), u.username) as Display FROM Doctrine \T ests \ Models \ CMS \ CmsUser u " );
}
2010-02-20 21:27:05 +03:00
}
/** @Entity */
class DQLKeywordsModelUser
{
/** @Id @Column(type="integer") @GeneratedValue */
private $id ;
/** @OneToOne(targetEntity="DQLKeywordsModelGroup") */
private $group ;
}
/** @Entity */
class DQLKeywordsModelGroup
{
/** @Id @Column(type="integer") @GeneratedValue */
private $id ;
2010-05-19 00:19:08 +04:00
/** @Column */
private $from ;
2010-02-20 21:27:05 +03:00
}