aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_framework
diff options
context:
space:
mode:
authorDerky <derky@phpbb.com>2018-01-05 22:44:34 +0100
committerDerky <derky@phpbb.com>2018-01-05 22:44:34 +0100
commit182a96f2738316adcb292816a9ac8af0e0cb5866 (patch)
tree0b6a0fb40a2ea201fdf4cfc5e4cc5ebfb4cb46db /tests/test_framework
parent2fcb8ab87fb30c57b106695859c2661fc3cc2837 (diff)
parent98c50695003652fba171e25dd2e171ddffbd72e1 (diff)
downloadforums-182a96f2738316adcb292816a9ac8af0e0cb5866.tar
forums-182a96f2738316adcb292816a9ac8af0e0cb5866.tar.gz
forums-182a96f2738316adcb292816a9ac8af0e0cb5866.tar.bz2
forums-182a96f2738316adcb292816a9ac8af0e0cb5866.tar.xz
forums-182a96f2738316adcb292816a9ac8af0e0cb5866.zip
Merge pull request #4680 from marc1706/ticket/15055
[ticket/15055] Add appveyor file to allow running tests on appveyor as well
Diffstat (limited to 'tests/test_framework')
-rw-r--r--tests/test_framework/phpbb_database_test_case.php77
-rw-r--r--tests/test_framework/phpbb_database_test_connection_manager.php8
-rw-r--r--tests/test_framework/phpbb_functional_test_case.php1
3 files changed, 85 insertions, 1 deletions
diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php
index df7c669865..606c40a623 100644
--- a/tests/test_framework/phpbb_database_test_case.php
+++ b/tests/test_framework/phpbb_database_test_case.php
@@ -142,9 +142,86 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
$manager->database_synchronisation($table_column_map);
}
+ /**
+ * Create xml data set for insertion into database
+ *
+ * @param string $path Path to fixture XML
+ * @return PHPUnit_Extensions_Database_DataSet_DefaultDataSet|PHPUnit_Extensions_Database_DataSet_XmlDataSet
+ */
public function createXMLDataSet($path)
{
$this->fixture_xml_data = parent::createXMLDataSet($path);
+
+ // Extend XML data set on MSSQL
+ 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)
+ {
+ /** @var \PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData $tableMetaData */
+ $tableMetaData = $value->getTableMetaData();
+ $columns = $tableMetaData->getColumns();
+ $primaryKeys = $tableMetaData->getPrimaryKeys();
+
+ $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;
+ $add_primary_keys = false;
+
+ // Iterate over identity columns to check for missing primary
+ // keys in data set and special identity column 'mssqlindex'
+ // that might have been added when no default identity column
+ // exists in the current table.
+ foreach ($identity_columns as $column)
+ {
+ if (in_array($column['identity_column'], $columns) && !in_array($column['identity_column'], $primaryKeys))
+ {
+ $primaryKeys[] = $column['identity_column'];
+ $add_primary_keys = true;
+ }
+
+ if ($column['identity_column'] === 'mssqlindex')
+ {
+ $has_default_identity = true;
+ break;
+ }
+ }
+
+ if ($has_default_identity || $add_primary_keys)
+ {
+ // Add default identity column to columns list
+ if ($has_default_identity)
+ {
+ $columns[] = 'mssqlindex';
+ }
+
+ $newMetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($key, $columns, $primaryKeys);
+ $newTable = new PHPUnit_Extensions_Database_DataSet_DefaultTable($newMetaData);
+ for ($i = 0; $i < $value->getRowCount(); $i++)
+ {
+ $dataRow = $value->getRow($i);
+ if ($has_default_identity)
+ {
+ $dataRow['mssqlindex'] = $i + 1;
+ }
+ $newTable->addRow($dataRow);
+ }
+ $newXmlData->addTable($newTable);
+ }
+ else
+ {
+ $newXmlData->addTable($value);
+ }
+ }
+
+ $this->fixture_xml_data = $newXmlData;
+ }
return $this->fixture_xml_data;
}
diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php
index b58e9c752b..f3adbefc1b 100644
--- a/tests/test_framework/phpbb_database_test_connection_manager.php
+++ b/tests/test_framework/phpbb_database_test_connection_manager.php
@@ -222,6 +222,14 @@ class phpbb_database_test_connection_manager
$this->purge_extras();
break;
+ case 'phpbb\db\driver\mssql':
+ case 'phpbb\db\driver\mssqlnative':
+ $this->connect();
+ // Drop all tables
+ $this->pdo->exec("EXEC sp_MSforeachtable 'DROP TABLE ?'");
+ $this->purge_extras();
+ break;
+
default:
$this->connect(false);
diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php
index 2d8224f7dc..2be16c7198 100644
--- a/tests/test_framework/phpbb_functional_test_case.php
+++ b/tests/test_framework/phpbb_functional_test_case.php
@@ -509,7 +509,6 @@ class phpbb_functional_test_case extends phpbb_test_case
else
{
$db->sql_multi_insert(STYLES_TABLE, array(array(
- 'style_id' => $style_id,
'style_name' => $style_path,
'style_copyright' => '',
'style_active' => 1,