Skip to content

Commit

Permalink
Adding test for quoting identifiers in conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Nov 6, 2013
1 parent 842ea5b commit e4e6a4a
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions Cake/Test/TestCase/Database/QueryTest.php
Expand Up @@ -2104,6 +2104,50 @@ public function testQuotingJoinsAndAlias() {
$this->assertRegExp('/JOIN \(bar\) [`"]foo[`"]/', $sql);
}

/**
* Tests automatic identifier quoting in the group by clause
*
* @return void
*/
public function testQuotingGroupBy() {
$this->connection->driver()->autoQuoting(true);
$query = new Query($this->connection);
$sql = $query->select('*')->group(['something'])->sql();
$this->assertRegExp('/GROUP BY [`"]something[`"]/', $sql);

$query = new Query($this->connection);
$sql = $query->select('*')->group([$query->newExpr()->add('bar')])->sql();
$this->assertRegExp('/GROUP BY \(bar\)/', $sql);

$query = new Query($this->connection);
$sql = $query->select('*')->group([new FieldExpression('bar')])->sql();
$this->assertRegExp('/GROUP BY \([`"]bar[`"]\)/', $sql);
}

/**
* Tests automatic identifier quoting strings inside conditions expressions
*
* @return void
*/
public function testQuotingExpressions() {
$this->connection->driver()->autoQuoting(true);
$query = new Query($this->connection);
$sql = $query->select('*')
->where(['something' => 'value'])
->sql();
$this->assertRegExp('/WHERE [`"]something[`"] = :c0/', $sql);

$query = new Query($this->connection);
$sql = $query->select('*')
->where([
'something' => 'value',
'OR' => ['foo' => 'bar', 'baz' => 'cake']
])
->sql();
$this->assertRegExp('/[`"]something[`"] = :c0 AND/', $sql);
$this->assertRegExp('/\([`"]foo[`"] = :c1 OR [`"]baz[`"] = :c2\)/', $sql);
}

/**
* Assertion for comparing a table's contents with what is in it.
*
Expand Down

0 comments on commit e4e6a4a

Please sign in to comment.