Commit 116270db authored by Tobias Schultze's avatar Tobias Schultze

Add tests for column collation to prove it works

parent a4015c8b
......@@ -474,7 +474,7 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
"ALTER TABLE mytable ADD PRIMARY KEY (foo)",
), $sql);
}
public function testAlterPrimaryKeyWithNewColumn()
{
$table = new Table("yolo");
......@@ -484,7 +484,7 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
$comparator = new Comparator();
$diffTable = clone $table;
$diffTable->addColumn('pkc2', 'integer');
$diffTable->dropPrimaryKey();
$diffTable->setPrimaryKey(array('pkc1', 'pkc2'));
......@@ -496,7 +496,7 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
'ALTER TABLE yolo ADD PRIMARY KEY (pkc1, pkc2)',
),
$this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable))
);
);
}
public function testInitializesDoctrineTypeMappings()
......@@ -908,4 +908,30 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
self::assertContains('bar', $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
$currentDateSql = $this->_platform->getCurrentDateSQL();
foreach (['date', 'date_immutable'] as $type) {
$field = [
'type' => Type::getType($type),
'type' => Type::getType($type),
'default' => $currentDateSql,
];
......@@ -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
{
$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 @@
namespace Doctrine\Tests\DBAL\Platforms;
use Doctrine\DBAL\Platforms\PostgreSQL91Platform;
use Doctrine\DBAL\Schema\Table;
class PostgreSql91PlatformTest extends PostgreSqlPlatformTest
{
......@@ -11,11 +12,29 @@ class PostgreSql91PlatformTest extends PostgreSqlPlatformTest
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"',
$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
{
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