Browse Source

Fixed QueryBuilderTest to work with PgSQL and other DBMS

tags/2.0.11
SilverFire - Dmitry Naumenko 8 years ago
parent
commit
2f8225a244
No known key found for this signature in database
GPG Key ID: 39DD917A92B270A
  1. 12
      tests/framework/db/QueryBuilderTest.php
  2. 9
      tests/framework/db/mssql/QueryBuilderTest.php
  3. 9
      tests/framework/db/pgsql/QueryBuilderTest.php

12
tests/framework/db/QueryBuilderTest.php

@ -1592,11 +1592,11 @@ abstract class QueryBuilderTest extends DatabaseTestCase
[['test@example.com', 'silverfire', 'Kyiv {{city}}, Ukraine']],
$this->replaceQuotes("INSERT INTO [[customer]] ([[email]], [[name]], [[address]]) VALUES ('test@example.com', 'silverfire', 'Kyiv {{city}}, Ukraine')")
],
[
'escape-danger-chars' => [
'customer',
['address'],
[["SQL-danger chars are escaped: '); --"]],
$this->replaceQuotes("INSERT INTO [[customer]] ([[address]]) VALUES ('SQL-danger chars are escaped: \'); --')")
'expected' => $this->replaceQuotes("INSERT INTO [[customer]] ([[address]]) VALUES ('SQL-danger chars are escaped: \'); --')")
],
[
'customer',
@ -1610,11 +1610,11 @@ abstract class QueryBuilderTest extends DatabaseTestCase
[["no columns passed"]],
$this->replaceQuotes("INSERT INTO [[customer]] () VALUES ('no columns passed')")
],
[
'bool-false, bool2-null' => [
'type',
['bool_col', 'bool_col2'],
[[false, null]],
$this->replaceQuotes("INSERT INTO [[type]] ([[bool_col]], [[bool_col2]]) VALUES (0, NULL)")
'expected' => $this->replaceQuotes("INSERT INTO [[type]] ([[bool_col]], [[bool_col2]]) VALUES (0, NULL)")
],
[
'{{%type}}',
@ -1622,11 +1622,11 @@ abstract class QueryBuilderTest extends DatabaseTestCase
[[null, new Expression('now()')]],
"INSERT INTO {{%type}} ({{%type}}.[[float_col]], [[time]]) VALUES (NULL, now())"
],
[
'bool-false, time-now()' => [
'{{%type}}',
['{{%type}}.[[bool_col]]', '[[time]]'],
[[false, new Expression('now()')]],
"INSERT INTO {{%type}} ({{%type}}.[[bool_col]], [[time]]) VALUES (0, now())"
'expected' => "INSERT INTO {{%type}} ({{%type}}.[[bool_col]], [[time]]) VALUES (0, now())"
],
];
}

9
tests/framework/db/mssql/QueryBuilderTest.php

@ -89,4 +89,13 @@ class QueryBuilderTest extends \yiiunit\framework\db\QueryBuilderTest
{
return array_merge(parent::columnTypes(), []);
}
public function batchInsertProvider()
{
$data = parent::batchInsertProvider();
$data['escape-danger-chars']['expected'] = 'INSERT INTO [customer] ([address]) VALUES ("SQL-danger chars are escaped: \'); --")';
$data['bool-false, bool2-null']['expected'] = 'INSERT INTO [type] ([bool_col], [bool_col2]) VALUES (FALSE, NULL)';
$data['bool-false, time-now()']['expected'] = "INSERT INTO {{%type}} ({{%type}}.[[bool_col]], [[time]]) VALUES (FALSE, now())";
}
}

9
tests/framework/db/pgsql/QueryBuilderTest.php

@ -120,4 +120,13 @@ class QueryBuilderTest extends \yiiunit\framework\db\QueryBuilderTest
$sql = $qb->dropCommentFromTable('comment');
$this->assertEquals($this->replaceQuotes($expected), $sql);
}
public function batchInsertProvider()
{
$data = parent::batchInsertProvider();
$data['escape-danger-chars']['expected'] = "INSERT INTO \"customer\" (\"address\") VALUES ('SQL-danger chars are escaped: ''); --')";
$data['bool-false, bool2-null']['expected'] = 'INSERT INTO "type" ("bool_col", "bool_col2") VALUES (FALSE, NULL)';
$data['bool-false, time-now()']['expected'] = "INSERT INTO {{%type}} ({{%type}}.[[bool_col]], [[time]]) VALUES (FALSE, now())";
}
}

Loading…
Cancel
Save