Skip to content

Commit

Permalink
Using a regexp newtural char for the fake quote marker in
Browse files Browse the repository at this point in the history
assertQuotedString
  • Loading branch information
lorenzo committed Nov 8, 2013
1 parent 226d1ab commit cdec5b6
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions Cake/Test/TestCase/Database/QueryTest.php
Expand Up @@ -1515,7 +1515,7 @@ public function testDeleteWithFrom() {
->where('1 = 1');

$result = $query->sql();
$this->assertQuotedQuery('DELETE FROM [authors]', $result, true);
$this->assertQuotedQuery('DELETE FROM <authors>', $result, true);

This comment has been minimized.

Copy link
@AD7six

AD7six Nov 8, 2013

Member

I still prefer

$this->assertQuotedQuery('DELETE FROM ☞authors☜', $result, true);

=)

This comment has been minimized.

Copy link
@lorenzo

lorenzo Nov 8, 2013

Author Member

:trollface:


$result = $query->execute();
$this->assertInstanceOf('Cake\Database\StatementInterface', $result);
Expand All @@ -1534,7 +1534,7 @@ public function testDeleteNoFrom() {
->where('1 = 1');

$result = $query->sql();
$this->assertQuotedQuery('DELETE FROM [authors]', $result, true);
$this->assertQuotedQuery('DELETE FROM <authors>', $result, true);

$result = $query->execute();
$this->assertInstanceOf('Cake\Database\StatementInterface', $result);
Expand All @@ -1553,7 +1553,7 @@ public function testSelectAndDeleteOnSameQuery() {
->where('1 = 1');
$result = $query->sql();

$this->assertQuotedQuery('DELETE FROM [authors]', $result, true);
$this->assertQuotedQuery('DELETE FROM <authors>', $result, true);
$this->assertContains(' WHERE 1 = 1', $result);
}

Expand All @@ -1568,7 +1568,7 @@ public function testUpdateSimple() {
->set('name', 'mark')
->where(['id' => 1]);
$result = $query->sql();
$this->assertQuotedQuery('UPDATE [authors] SET [name] = :', $result, true);
$this->assertQuotedQuery('UPDATE <authors> SET <name> = :', $result, true);

$result = $query->execute();
$this->assertCount(1, $result);
Expand All @@ -1588,12 +1588,12 @@ public function testUpdateMultipleFields() {
$result = $query->sql();

$this->assertQuotedQuery(
'UPDATE [articles] SET [title] = :c0 , [body] = :c1',
'UPDATE <articles> SET <title> = :c0 , <body> = :c1',
$result,
true
);

$this->assertQuotedQuery(' WHERE [id] = :c2$', $result, true);
$this->assertQuotedQuery(' WHERE <id> = :c2$', $result, true);
$result = $query->execute();
$this->assertCount(1, $result);
}
Expand All @@ -1614,11 +1614,11 @@ public function testUpdateMultipleFieldsArray() {
$result = $query->sql();

$this->assertQuotedQuery(
'UPDATE [articles] SET [title] = :c0 , [body] = :c1',
'UPDATE <articles> SET <title> = :c0 , <body> = :c1',
$result,
true
);
$this->assertQuotedQuery('WHERE [id] = :', $result, true);
$this->assertQuotedQuery('WHERE <id> = :', $result, true);

$result = $query->execute();
$this->assertCount(1, $result);
Expand All @@ -1641,7 +1641,7 @@ public function testUpdateWithExpression() {
$result = $query->sql();

$this->assertQuotedQuery(
'UPDATE [articles] SET title = author_id WHERE [id] = :',
'UPDATE <articles> SET title = author_id WHERE <id> = :',
$result,
true
);
Expand Down Expand Up @@ -1679,7 +1679,7 @@ public function testInsertSimple() {
]);
$result = $query->sql();
$this->assertQuotedQuery(
'INSERT INTO [articles] \([title], [body]\) ' .
'INSERT INTO <articles> \(<title>, <body>\) ' .
'VALUES \(\?, \?\)',
$result,
true
Expand Down Expand Up @@ -1714,7 +1714,7 @@ public function testInsertSparseRow() {
]);
$result = $query->sql();
$this->assertQuotedQuery(
'INSERT INTO [articles] \([title], [body]\) ' .
'INSERT INTO <articles> \(<title>, <body>\) ' .
'VALUES \(\?, \?\)',
$result,
true
Expand Down Expand Up @@ -1792,12 +1792,12 @@ public function testInsertFromSelect() {

$result = $query->sql();
$this->assertQuotedQuery(
'INSERT INTO [articles] \([title], [body], [author_id]\) SELECT',
'INSERT INTO <articles> \(<title>, <body>, <author_id>\) SELECT',
$result,
true
);
$this->assertQuotedQuery(
'SELECT [name], \'some text\', 99 FROM [authors]', $result, true);
'SELECT <name>, \'some text\', 99 FROM <authors>', $result, true);
$result = $query->execute();

$this->assertCount(1, $result);
Expand Down Expand Up @@ -2038,27 +2038,27 @@ public function testQuotingSelectFieldsAndAlias() {
$this->connection->driver()->autoQuoting(true);
$query = new Query($this->connection);
$sql = $query->select(['something'])->sql();
$this->assertQuotedQuery('SELECT [something]$', $sql);
$this->assertQuotedQuery('SELECT <something>$', $sql);

$query = new Query($this->connection);
$sql = $query->select(['foo' => 'something'])->sql();
$this->assertQuotedQuery('SELECT [something] AS [foo]$', $sql);
$this->assertQuotedQuery('SELECT <something> AS <foo>$', $sql);

$query = new Query($this->connection);
$sql = $query->select(['foo' => 1])->sql();
$this->assertQuotedQuery('SELECT 1 AS [foo]$', $sql);
$this->assertQuotedQuery('SELECT 1 AS <foo>$', $sql);

$query = new Query($this->connection);
$sql = $query->select(['foo' => '1 + 1'])->sql();
$this->assertQuotedQuery('SELECT [1 \+ 1] AS [foo]$', $sql);
$this->assertQuotedQuery('SELECT <1 \+ 1> AS <foo>$', $sql);

$query = new Query($this->connection);
$sql = $query->select(['foo' => $query->newExpr()->add('1 + 1')])->sql();
$this->assertQuotedQuery('SELECT \(1 \+ 1\) AS [foo]$', $sql);
$this->assertQuotedQuery('SELECT \(1 \+ 1\) AS <foo>$', $sql);

$query = new Query($this->connection);
$sql = $query->select(['foo' => new IdentifierExpression('bar')])->sql();
$this->assertQuotedQuery('[bar]', $sql);
$this->assertQuotedQuery('<bar>', $sql);
}

/**
Expand All @@ -2070,15 +2070,15 @@ public function testQuotingFromAndAlias() {
$this->connection->driver()->autoQuoting(true);
$query = new Query($this->connection);
$sql = $query->select('*')->from(['something'])->sql();
$this->assertQuotedQuery('FROM [something]', $sql);
$this->assertQuotedQuery('FROM <something>', $sql);

$query = new Query($this->connection);
$sql = $query->select('*')->from(['foo' => 'something'])->sql();
$this->assertQuotedQuery('FROM [something] AS [foo]$', $sql);
$this->assertQuotedQuery('FROM <something> AS <foo>$', $sql);

$query = new Query($this->connection);
$sql = $query->select('*')->from(['foo' => $query->newExpr()->add('bar')])->sql();
$this->assertQuotedQuery('FROM \(bar\) AS [foo]$', $sql);
$this->assertQuotedQuery('FROM \(bar\) AS <foo>$', $sql);
}

/**
Expand All @@ -2090,7 +2090,7 @@ public function testQuotingDistinctOn() {
$this->connection->driver()->autoQuoting(true);
$query = new Query($this->connection);
$sql = $query->select('*')->distinct(['something'])->sql();
$this->assertQuotedQuery('[something]', $sql);
$this->assertQuotedQuery('<something>', $sql);
}

/**
Expand All @@ -2102,15 +2102,15 @@ public function testQuotingJoinsAndAlias() {
$this->connection->driver()->autoQuoting(true);
$query = new Query($this->connection);
$sql = $query->select('*')->join(['something'])->sql();
$this->assertQuotedQuery('JOIN [something]', $sql);
$this->assertQuotedQuery('JOIN <something>', $sql);

$query = new Query($this->connection);
$sql = $query->select('*')->join(['foo' => 'something'])->sql();
$this->assertQuotedQuery('JOIN [something] [foo]', $sql);
$this->assertQuotedQuery('JOIN <something> <foo>', $sql);

$query = new Query($this->connection);
$sql = $query->select('*')->join(['foo' => $query->newExpr()->add('bar')])->sql();
$this->assertQuotedQuery('JOIN \(bar\) [foo]', $sql);
$this->assertQuotedQuery('JOIN \(bar\) <foo>', $sql);
}

/**
Expand All @@ -2122,15 +2122,15 @@ public function testQuotingGroupBy() {
$this->connection->driver()->autoQuoting(true);
$query = new Query($this->connection);
$sql = $query->select('*')->group(['something'])->sql();
$this->assertQuotedQuery('GROUP BY [something]', $sql);
$this->assertQuotedQuery('GROUP BY <something>', $sql);

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

$query = new Query($this->connection);
$sql = $query->select('*')->group([new IdentifierExpression('bar')])->sql();
$this->assertQuotedQuery('GROUP BY \([bar]\)', $sql);
$this->assertQuotedQuery('GROUP BY \(<bar>\)', $sql);
}

/**
Expand All @@ -2144,7 +2144,7 @@ public function testQuotingExpressions() {
$sql = $query->select('*')
->where(['something' => 'value'])
->sql();
$this->assertQuotedQuery('WHERE [something] = :c0', $sql);
$this->assertQuotedQuery('WHERE <something> = :c0', $sql);

$query = new Query($this->connection);
$sql = $query->select('*')
Expand All @@ -2153,8 +2153,8 @@ public function testQuotingExpressions() {
'OR' => ['foo' => 'bar', 'baz' => 'cake']
])
->sql();
$this->assertQuotedQuery('[something] = :c0 AND', $sql);
$this->assertQuotedQuery('\([foo] = :c1 OR [baz] = :c2\)', $sql);
$this->assertQuotedQuery('<something> = :c0 AND', $sql);
$this->assertQuotedQuery('\(<foo> = :c1 OR <baz> = :c2\)', $sql);
}

/**
Expand All @@ -2168,13 +2168,13 @@ public function testQuotingInsert() {
$sql = $query->insert('foo', ['bar', 'baz'])
->where(['something' => 'value'])
->sql();
$this->assertQuotedQuery('INSERT INTO [foo] \([bar], [baz]\)', $sql);
$this->assertQuotedQuery('INSERT INTO <foo> \(<bar>, <baz>\)', $sql);

$query = new Query($this->connection);
$sql = $query->insert('foo', [$query->newExpr()->add('bar')])
->where(['something' => 'value'])
->sql();
$this->assertQuotedQuery('INSERT INTO [foo] \(\(bar\)\)', $sql);
$this->assertQuotedQuery('INSERT INTO <foo> \(\(bar\)\)', $sql);
}

/**
Expand All @@ -2196,7 +2196,7 @@ public function assertTable($table, $count, $rows, $conditions = []) {

/**
* Assertion for comparing a regex pattern against a query having its indentifiers
* quoted. It accepts queries quoted with the characters `[` and `]`. If the third
* quoted. It accepts queries quoted with the characters `<` and `>`. If the third
* parameter is set to true, it will alter the pattern to both accept quoted and
* unquoted queries
*
Expand All @@ -2209,8 +2209,8 @@ public function assertQuotedQuery($pattern, $query, $optional = false) {
if ($optional) {
$optional = '?';
}
$pattern = str_replace('[', '[`"\[]' . $optional, $pattern);
$pattern = str_replace(']', '[`"\]]' . $optional, $pattern);
$pattern = str_replace('<', '[`"\[]' . $optional, $pattern);
$pattern = str_replace('>', '[`"\]]' . $optional, $pattern);
$this->assertRegExp('#' . $pattern . '#', $query);
}

Expand Down

0 comments on commit cdec5b6

Please sign in to comment.