diff options
author | Marc Alexander <admin@m-a-styles.de> | 2017-12-24 16:48:28 +0100 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2018-01-01 18:55:06 +0100 |
commit | f4381a20d4ec6201a00cd618c24fd29b67f77965 (patch) | |
tree | deeceff0661633612d3c19a4fc0d2da91deee4fa | |
parent | f903e5b3c025560d44622bcd4d15c7e0fa3b1633 (diff) | |
download | forums-f4381a20d4ec6201a00cd618c24fd29b67f77965.tar forums-f4381a20d4ec6201a00cd618c24fd29b67f77965.tar.gz forums-f4381a20d4ec6201a00cd618c24fd29b67f77965.tar.bz2 forums-f4381a20d4ec6201a00cd618c24fd29b67f77965.tar.xz forums-f4381a20d4ec6201a00cd618c24fd29b67f77965.zip |
[ticket/15055] Handle default identity column on mssql in database tests
PHPBB3-15055
-rw-r--r-- | tests/test_framework/phpbb_database_test_case.php | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index b7386e9a3e..670d39ed69 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -145,6 +145,53 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test public function createXMLDataSet($path) { $this->fixture_xml_data = parent::createXMLDataSet($path); + if (strpos($this->get_database_config()['dbms'], 'mssql') !== false) + { + $newXmlData = new PHPUnit_Extensions_Database_DataSet_DefaultDataSet(); + $db = $this->new_dbal(); + foreach ($this->fixture_xml_data as $key => $value) + { + $sql = "SELECT COLUMN_NAME AS identity_column + FROM INFORMATION_SCHEMA.COLUMNS + WHERE COLUMNPROPERTY(object_id(TABLE_SCHEMA + '.' + TABLE_NAME), COLUMN_NAME, 'IsIdentity') = 1 + AND TABLE_NAME = '$key' + ORDER BY TABLE_NAME"; + $result = $db->sql_query($sql); + $identity_columns = $db->sql_fetchrowset($result); + $has_default_identity = false; + foreach ($identity_columns as $column) + { + if ($column['identity_column'] === 'mssqlindex') + { + $has_default_identity = true; + break; + } + } + + if ($has_default_identity) + { + /** @var \PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData $tableMetaData */ + $tableMetaData = $value->getTableMetaData(); + $columns = $tableMetaData->getColumns(); + $columns[] = 'mssqlindex'; + $newMetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($key, $columns, $tableMetaData->getPrimaryKeys()); + $newTable = new PHPUnit_Extensions_Database_DataSet_DefaultTable($newMetaData); + for ($i = 0; $i < $value->getRowCount(); $i++) + { + $dataRow = $value->getRow($i); + $dataRow['mssqlindex'] = $i + 1; + $newTable->addRow($dataRow); + } + $newXmlData->addTable($newTable); + } + else + { + $newXmlData->addTable($value); + } + } + + $this->fixture_xml_data = $newXmlData; + } return $this->fixture_xml_data; } |