Unverified Commit 46069b6b authored by Marco Pivetta's avatar Marco Pivetta Committed by GitHub

Merge pull request #2919 from Tobion/test-column-collation

Add tests for column collation to prove it works
parents a4015c8b 116270db
...@@ -474,7 +474,7 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase ...@@ -474,7 +474,7 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
"ALTER TABLE mytable ADD PRIMARY KEY (foo)", "ALTER TABLE mytable ADD PRIMARY KEY (foo)",
), $sql); ), $sql);
} }
public function testAlterPrimaryKeyWithNewColumn() public function testAlterPrimaryKeyWithNewColumn()
{ {
$table = new Table("yolo"); $table = new Table("yolo");
...@@ -484,7 +484,7 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase ...@@ -484,7 +484,7 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
$comparator = new Comparator(); $comparator = new Comparator();
$diffTable = clone $table; $diffTable = clone $table;
$diffTable->addColumn('pkc2', 'integer'); $diffTable->addColumn('pkc2', 'integer');
$diffTable->dropPrimaryKey(); $diffTable->dropPrimaryKey();
$diffTable->setPrimaryKey(array('pkc1', 'pkc2')); $diffTable->setPrimaryKey(array('pkc1', 'pkc2'));
...@@ -496,7 +496,7 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase ...@@ -496,7 +496,7 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
'ALTER TABLE yolo ADD PRIMARY KEY (pkc1, pkc2)', 'ALTER TABLE yolo ADD PRIMARY KEY (pkc1, pkc2)',
), ),
$this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) $this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable))
); );
} }
public function testInitializesDoctrineTypeMappings() public function testInitializesDoctrineTypeMappings()
...@@ -908,4 +908,30 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase ...@@ -908,4 +908,30 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
self::assertContains('bar', $sql); self::assertContains('bar', $sql);
self::assertNotContains('DATABASE()', $sql); self::assertNotContains('DATABASE()', $sql);
} }
public function testSupportsColumnCollation() : void
{
self::assertTrue($this->_platform->supportsColumnCollation());
}
public function testColumnCollationDeclarationSQL() : void
{
self::assertSame(
'COLLATE ascii_general_ci',
$this->_platform->getColumnCollationDeclarationSQL('ascii_general_ci')
);
}
public function testGetCreateTableSQLWithColumnCollation() : void
{
$table = new Table('foo');
$table->addColumn('no_collation', 'string');
$table->addColumn('column_collation', 'string')->setPlatformOption('collation', 'ascii_general_ci');
self::assertSame(
['CREATE TABLE foo (no_collation VARCHAR(255) NOT NULL, column_collation VARCHAR(255) NOT NULL COLLATE ascii_general_ci) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'],
$this->_platform->getCreateTableSQL($table),
'Column "no_collation" will use the default collation from the table/database and "column_collation" overwrites the collation on this column'
);
}
} }
...@@ -1487,7 +1487,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas ...@@ -1487,7 +1487,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
$currentDateSql = $this->_platform->getCurrentDateSQL(); $currentDateSql = $this->_platform->getCurrentDateSQL();
foreach (['date', 'date_immutable'] as $type) { foreach (['date', 'date_immutable'] as $type) {
$field = [ $field = [
'type' => Type::getType($type), 'type' => Type::getType($type),
'default' => $currentDateSql, 'default' => $currentDateSql,
]; ];
...@@ -1498,6 +1498,32 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas ...@@ -1498,6 +1498,32 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
} }
} }
public function testSupportsColumnCollation() : void
{
self::assertTrue($this->_platform->supportsColumnCollation());
}
public function testColumnCollationDeclarationSQL() : void
{
self::assertSame(
'COLLATE Latin1_General_CS_AS_KS_WS',
$this->_platform->getColumnCollationDeclarationSQL('Latin1_General_CS_AS_KS_WS')
);
}
public function testGetCreateTableSQLWithColumnCollation() : void
{
$table = new Table('foo');
$table->addColumn('no_collation', 'string');
$table->addColumn('column_collation', 'string')->setPlatformOption('collation', 'Latin1_General_CS_AS_KS_WS');
self::assertSame(
['CREATE TABLE foo (no_collation NVARCHAR(255) NOT NULL, column_collation NVARCHAR(255) COLLATE Latin1_General_CS_AS_KS_WS NOT NULL)'],
$this->_platform->getCreateTableSQL($table),
'Column "no_collation" will use the default collation from the table/database and "column_collation" overwrites the collation on this column'
);
}
private function expectCteWithMaxRowNum(string $expectedSql, int $expectedMax, string $sql) : void private function expectCteWithMaxRowNum(string $expectedSql, int $expectedMax, string $sql) : void
{ {
$pattern = 'WITH dctrn_cte AS (%s) SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS doctrine_rownum FROM dctrn_cte) AS doctrine_tbl WHERE doctrine_rownum <= %d ORDER BY doctrine_rownum ASC'; $pattern = 'WITH dctrn_cte AS (%s) SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS doctrine_rownum FROM dctrn_cte) AS doctrine_tbl WHERE doctrine_rownum <= %d ORDER BY doctrine_rownum ASC';
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Doctrine\Tests\DBAL\Platforms; namespace Doctrine\Tests\DBAL\Platforms;
use Doctrine\DBAL\Platforms\PostgreSQL91Platform; use Doctrine\DBAL\Platforms\PostgreSQL91Platform;
use Doctrine\DBAL\Schema\Table;
class PostgreSql91PlatformTest extends PostgreSqlPlatformTest class PostgreSql91PlatformTest extends PostgreSqlPlatformTest
{ {
...@@ -11,11 +12,29 @@ class PostgreSql91PlatformTest extends PostgreSqlPlatformTest ...@@ -11,11 +12,29 @@ class PostgreSql91PlatformTest extends PostgreSqlPlatformTest
return new PostgreSQL91Platform(); return new PostgreSQL91Platform();
} }
public function testColumnCollationDeclarationSQL() public function testSupportsColumnCollation() : void
{ {
self::assertEquals( self::assertTrue($this->_platform->supportsColumnCollation());
}
public function testColumnCollationDeclarationSQL() : void
{
self::assertSame(
'COLLATE "en_US.UTF-8"', 'COLLATE "en_US.UTF-8"',
$this->_platform->getColumnCollationDeclarationSQL('en_US.UTF-8') $this->_platform->getColumnCollationDeclarationSQL('en_US.UTF-8')
); );
} }
public function testGetCreateTableSQLWithColumnCollation() : void
{
$table = new Table('foo');
$table->addColumn('no_collation', 'string');
$table->addColumn('column_collation', 'string')->setPlatformOption('collation', 'en_US.UTF-8');
self::assertSame(
['CREATE TABLE foo (no_collation VARCHAR(255) NOT NULL, column_collation VARCHAR(255) NOT NULL COLLATE "en_US.UTF-8")'],
$this->_platform->getCreateTableSQL($table),
'Column "no_collation" will use the default collation from the table/database and "column_collation" overwrites the collation on this column'
);
}
} }
...@@ -759,4 +759,30 @@ class SqlitePlatformTest extends AbstractPlatformTestCase ...@@ -759,4 +759,30 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
{ {
self::assertSame("DATE(rentalBeginsOn,'+' || duration || ' DAY')", $this->_platform->getDateAddDaysExpression('rentalBeginsOn', 'duration')); self::assertSame("DATE(rentalBeginsOn,'+' || duration || ' DAY')", $this->_platform->getDateAddDaysExpression('rentalBeginsOn', 'duration'));
} }
public function testSupportsColumnCollation() : void
{
self::assertTrue($this->_platform->supportsColumnCollation());
}
public function testColumnCollationDeclarationSQL() : void
{
self::assertSame(
'COLLATE NOCASE',
$this->_platform->getColumnCollationDeclarationSQL('NOCASE')
);
}
public function testGetCreateTableSQLWithColumnCollation() : void
{
$table = new Table('foo');
$table->addColumn('no_collation', 'string');
$table->addColumn('column_collation', 'string')->setPlatformOption('collation', 'NOCASE');
self::assertSame(
['CREATE TABLE foo (no_collation VARCHAR(255) NOT NULL, column_collation VARCHAR(255) NOT NULL COLLATE NOCASE)'],
$this->_platform->getCreateTableSQL($table),
'Column "no_collation" will use the default collation (BINARY) and "column_collation" overwrites the collation on this column'
);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment