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

Add tests for column collation to prove it works

parent a4015c8b
...@@ -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'
);
}
} }
...@@ -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