Browse Source

Fix #17435: Fixed `i18n_init` migration for MSSQL

tags/2.0.23
Alexander Kartavenko 5 years ago committed by Alexander Makarov
parent
commit
a9097dbac3
  1. 1
      framework/CHANGELOG.md
  2. 7
      framework/i18n/migrations/m150207_210500_i18n_init.php
  3. 18
      tests/framework/db/mssql/DbMessageSourceTest.php
  4. 33
      tests/framework/i18n/DbMessageSourceTest.php

1
framework/CHANGELOG.md

@ -7,6 +7,7 @@ Yii Framework 2 Change Log
- Bug #17413, #17418, #17426, #17431: Fixed MSSQL tests (alexkart)
- Bug #17420: Fixed loading of column default values for MSSQL (alexkart)
- Bug #17395: Fixed issues with actions that contain underscores in their names (alexkart)
- Bug #17435: Fixed `i18n_init` migration for MSSQL (alexkart)
- Bug #10023: Fixed MSSQL "There are no more rows in the active result set" exception when using `each()` and `batch()` (alexkart)

7
framework/i18n/migrations/m150207_210500_i18n_init.php

@ -38,7 +38,12 @@ class m150207_210500_i18n_init extends Migration
], $tableOptions);
$this->addPrimaryKey('pk_message_id_language', '{{%message}}', ['id', 'language']);
$this->addForeignKey('fk_message_source_message', '{{%message}}', 'id', '{{%source_message}}', 'id', 'CASCADE', 'RESTRICT');
$onUpdateConstraint = 'RESTRICT';
if ($this->db->driverName === 'sqlsrv') {
// 'NO ACTION' is equivalent to 'RESTRICT' in MSSQL
$onUpdateConstraint = 'NO ACTION';
}
$this->addForeignKey('fk_message_source_message', '{{%message}}', 'id', '{{%source_message}}', 'id', 'CASCADE', $onUpdateConstraint);
$this->createIndex('idx_source_message_category', '{{%source_message}}', 'category');
$this->createIndex('idx_message_language', '{{%message}}', 'language');
}

18
tests/framework/db/mssql/DbMessageSourceTest.php

@ -0,0 +1,18 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yiiunit\framework\db\mssql;
/**
* @group i18n
* @group db
* @group mssql
*/
class DbMessageSourceTest extends \yiiunit\framework\i18n\DbMessageSourceTest
{
protected static $driverName = 'sqlsrv';
}

33
tests/framework/i18n/DbMessageSourceTest.php

@ -86,23 +86,22 @@ class DbMessageSourceTest extends I18NTest
static::runConsoleAction('migrate/up', ['migrationPath' => '@yii/i18n/migrations/', 'interactive' => false]);
static::$db->createCommand()->batchInsert('source_message', ['id', 'category', 'message'], [
[1, 'test', 'Hello world!'],
[2, 'test', 'The dog runs fast.'],
[3, 'test', 'His speed is about {n} km/h.'],
[4, 'test', 'His name is {name} and his speed is about {n, number} km/h.'],
[5, 'test', 'There {n, plural, =0{no cats} =1{one cat} other{are # cats}} on lying on the sofa!'],
static::$db->createCommand()->truncateTable('source_message');
static::$db->createCommand()->batchInsert('source_message', ['category', 'message'], [
['test', 'Hello world!'], // id = 1
['test', 'The dog runs fast.'], // id = 2
['test', 'His speed is about {n} km/h.'], // id = 3
['test', 'His name is {name} and his speed is about {n, number} km/h.'], // id = 4
['test', 'There {n, plural, =0{no cats} =1{one cat} other{are # cats}} on lying on the sofa!'], // id = 5
])->execute();
static::$db->createCommand()->batchInsert('message', ['id', 'language', 'translation'], [
[1, 'de', 'Hallo Welt!'],
[2, 'de-DE', 'Der Hund rennt schnell.'],
[2, 'en-US', 'The dog runs fast (en-US).'],
[2, 'ru', 'Собака бегает быстро.'],
[3, 'de-DE', 'Seine Geschwindigkeit beträgt {n} km/h.'],
[4, 'de-DE', 'Er heißt {name} und ist {n, number} km/h schnell.'],
[5, 'ru', 'На диване {n, plural, =0{нет кошек} =1{лежит одна кошка} one{лежит # кошка} few{лежит # кошки} many{лежит # кошек} other{лежит # кошки}}!'],
])->execute();
static::$db->createCommand()->insert('message', ['id' => 1, 'language' => 'de', 'translation' => 'Hallo Welt!'])->execute();
static::$db->createCommand()->insert('message', ['id' => 2, 'language' => 'de-DE', 'translation' => 'Der Hund rennt schnell.'])->execute();
static::$db->createCommand()->insert('message', ['id' => 2, 'language' => 'en-US', 'translation' => 'The dog runs fast (en-US).'])->execute();
static::$db->createCommand()->insert('message', ['id' => 2, 'language' => 'ru', 'translation' => 'Собака бегает быстро.'])->execute();
static::$db->createCommand()->insert('message', ['id' => 3, 'language' => 'de-DE', 'translation' => 'Seine Geschwindigkeit beträgt {n} km/h.'])->execute();
static::$db->createCommand()->insert('message', ['id' => 4, 'language' => 'de-DE', 'translation' => 'Er heißt {name} und ist {n, number} km/h schnell.'])->execute();
static::$db->createCommand()->insert('message', ['id' => 5, 'language' => 'ru', 'translation' => 'На диване {n, plural, =0{нет кошек} =1{лежит одна кошка} one{лежит # кошка} few{лежит # кошки} many{лежит # кошек} other{лежит # кошки}}!'])->execute();
}
public static function tearDownAfterClass()
@ -116,10 +115,10 @@ class DbMessageSourceTest extends I18NTest
}
/**
* @throws \yii\base\InvalidParamException
* @return \yii\db\Connection
* @throws \yii\db\Exception
* @throws \yii\base\InvalidConfigException
* @return \yii\db\Connection
* @throws \yii\base\InvalidParamException
*/
public static function getConnection()
{

Loading…
Cancel
Save