1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-03-14 12:40:13 +01:00

Merge pull request #4680 from marc1706/ticket/15055

[ticket/15055] Add appveyor file to allow running tests on appveyor as well
This commit is contained in:
Derky 2018-01-05 22:44:34 +01:00
commit 182a96f273
25 changed files with 439 additions and 44 deletions

139
.appveyor.yml Normal file
View File

@ -0,0 +1,139 @@
build: false
clone_folder: c:\projects\phpbb
version: '{build}'
services:
- iis
environment:
matrix:
- db: mssql
db_version: sql2012sp1
php: 7.0
- db: mssql
db_version: sql2014
php: 7.0
- db: mssql
db_version: sql2016
php: 7.0
- db: mssql
db_version: sql2017
php: 7.1
# - db: mariadb
# php: 7.1
# - db: mysqli
# php: 7.1
# - db: sqlite
# php: 7.1
# - db: postgresql
# php: 7.1
hosts:
phpbb.test: 127.0.0.1
init:
- SET PATH=%systemroot%\system32\inetsrv\;C:\Program Files\OpenSSL;C:\tools\php;c:\php;%PATH%
- SET ANSICON=121x90 (121x90)
- REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Command Processor" /v DelayedExpansion /t REG_DWORD /d 1 /f
before_test:
- ps: |
Set-Service wuauserv -StartupType Manual
cinst -y php --version ((choco search php --exact --all-versions -r | select-string -pattern $env:php | sort { [version]($_ -split '\|' | select -last 1) } -Descending | Select-Object -first 1) -replace '[php|]','')
Get-ChildItem -Path "c:\tools\php$($env:php -replace '[.]','')" -Recurse |
Move-Item -destination "c:\tools\php"
cd c:\tools\php
cat php.ini-production | %{$_ -replace "memory_limit = 128M","memory_limit = 1024M"} | Out-File -Encoding "Default" php.ini
Add-Content php.ini "`n date.timezone=UTC"
Add-Content php.ini "`n display_errors=On"
Add-Content php.ini "`n extension_dir=ext"
Add-Content php.ini "`n extension=php_openssl.dll"
Add-Content php.ini "`n extension=php_mbstring.dll"
Add-Content php.ini "`n extension=php_curl.dll"
Add-Content php.ini "`n extension=php_gd2.dll"
Add-Content php.ini "`n extension=php_tidy.dll"
Add-Content php.ini "`n extension=php_fileinfo.dll"
Add-Content php.ini "`n extension=php_pdo_sqlite.dll"
Add-Content php.ini "`n extension=php_sqlite3.dll"
Add-Content php.ini "`n extension=php_pdo_mysql.dll"
Add-Content php.ini "`n extension=php_mysqli.dll"
Add-Content php.ini "`n extension=php_pdo_pgsql.dll"
Add-Content php.ini "`n extension=php_pgsql.dll"
# Get MSSQL driver
if ($env:db -eq "mssql") {
cd c:\tools\php\ext
$DLLVersion = "4.1.6.1"
appveyor DownloadFile http://windows.php.net/downloads/pecl/releases/sqlsrv/$($:DLLVersion)/php_sqlsrv-$($DLLVersion)-$($env:php)-nts-vc14-x64.zip
7z x -y php_sqlsrv-$($DLLVersion)-$($env:php)-nts-vc14-x64.zip > $null
appveyor-retry appveyor DownloadFile http://windows.php.net/downloads/pecl/releases/pdo_sqlsrv/$($DLLVersion)/php_pdo_sqlsrv-$($DLLVersion)-$($env:php)-nts-vc14-x64.zip
7z x -y php_pdo_sqlsrv-$($DLLVersion)-$($env:php)-nts-vc14-x64.zip > $null
Remove-Item c:\tools\php\* -include .zip
cd c:\tools\php
Add-Content php.ini "`nextension=php_sqlsrv.dll"
Add-Content php.ini "`nextension=php_pdo_sqlsrv.dll"
Add-Content php.ini "`n"
$instanceName = $env:db_version.ToUpper()
Start-Service "MSSQL`$$instanceName"
Set-Variable -Name "sqlServerPath" -Value "(local)\$($env:db_version.ToUpper())"
# Create database write test config
sqlcmd -S $sqlServerPath -Q "Use [master]; CREATE DATABASE [phpbb_test] COLLATE Latin1_General_CI_AS"
$data = "<?php`n`n`$dbms = 'phpbb\\db\\driver\\mssqlnative';`n`$dbhost = '.\\$env:db_version';`n`$dbport = '';`n`$dbname = 'phpbb_test';`n`$dbuser = 'sa';`n`$dbpasswd = 'Password12!';`n`$phpbb_functional_url = 'http://phpbb.test/';"; $data | Out-File -Encoding "Default" "c:\\projects\\phpbb\\tests\\test_config.php"
}
elseif ($env:db -eq "mysqli") {
Start-Service MySQL57
$env:MYSQL_PWD="Password12!"
$cmd = '"C:\Program Files\MySQL\MySQL Server 5.7\bin\mysql" -e "create database phpbb_test;" --user=root'
iex "& $cmd"
$data = "<?php`n`n`$dbms = 'phpbb\\db\\driver\\mysqli';`n`$dbhost = 'localhost';`n`$dbport = '';`n`$dbname = 'phpbb_test';`n`$dbuser = 'root';`n`$dbpasswd = 'Password12!';`n`$phpbb_functional_url = 'http://phpbb.test/';"; $data | Out-File -Encoding "Default" "c:\\projects\\phpbb\\tests\\test_config.php"
}
elseif ($env:db -eq "postgresql") {
Start-Service postgresql-x64-9.5
$env:PGUSER="postgres"
$env:PGPASSWORD="Password12!"
$Env:Path="C:\Program Files\PostgreSQL\9.6\bin\;$($Env:Path)"
createdb phpbb_test
$data = "<?php`n`n`$dbms = 'phpbb\\db\\driver\\postgres';`n`$dbhost = 'localhost';`n`$dbport = '';`n`$dbname = 'phpbb_test';`n`$dbuser = 'postgres';`n`$dbpasswd = 'Password12!';`n`$phpbb_functional_url = 'http://phpbb.test/';"; $data | Out-File -Encoding "Default" "c:\\projects\\phpbb\\tests\\test_config.php"
}
elseif ($env:db -eq "mariadb") {
appveyor-retry cinst -y --force mariadb
$env:MYSQL_PWD=""
$cmd = '"C:\Program Files\MariaDB 10.2\bin\mysql" -e "create database phpbb_test;" --user=root'
iex "& $cmd"
$data = "<?php`n`n`$dbms = 'phpbb\\db\\driver\\mysqli';`n`$dbhost = 'localhost';`n`$dbport = '';`n`$dbname = 'phpbb_test';`n`$dbuser = 'root';`n`$dbpasswd = '';`n`$phpbb_functional_url = 'http://phpbb.test/';"; $data | Out-File -Encoding "Default" "c:\\projects\\phpbb\\tests\\test_config.php"
}
elseif ($env:db -eq "sqlite") {
# install sqlite
appveyor-retry cinst -y sqlite
sqlite3 c:\projects\test.db "create table aTable(field1 int); drop table aTable;"
$data = "<?php`n`n`$dbms = 'phpbb\\db\\driver\\sqlite3';`n`$dbhost = 'c:\\projects\\test.db';`n`$dbport = '';`n`$dbname = '';`n`$dbuser = '';`n`$dbpasswd = '';`n`$phpbb_functional_url = 'http://phpbb.test/';"; $data | Out-File -Encoding "Default" "c:\\projects\\phpbb\\tests\\test_config.php"
}
# Install PhantomJS
cinst -y phantomjs
Start-Process "phantomjs" "--webdriver=8910" | Out-Null
- cd c:\projects\phpbb\phpBB
- php ..\composer.phar install
- choco install -y urlrewrite
- ps: New-WebSite -Name 'phpBBTest' -PhysicalPath 'c:\projects\phpbb\phpBB' -Force
- ps: Import-Module WebAdministration; Set-ItemProperty 'IIS:\Sites\phpBBTest' -name Bindings -value @{protocol='http';bindingInformation='*:80:phpbb.test'}
- echo Change default anonymous user AUTH to ApplicationPool
- appcmd set config -section:anonymousAuthentication /username:"" --password
- echo Setup FAST-CGI configuration
- appcmd set config /section:system.webServer/fastCGI /+[fullPath='C:\tools\php\php-cgi.exe']
- echo Setup FACT-CGI handler
- appcmd set config /section:system.webServer/handlers /+[name='PHP-FastCGI',path='*.php',verb='*',modules='FastCgiModule',scriptProcessor='C:\tools\php\php-cgi.exe',resourceType='Either']
- iisreset
- NET START W3SVC
- mkdir "C:\projects\phpbb\phpBB\cache\test"
- mkdir "C:\projects\phpbb\phpBB\cache\installer"
- icacls "C:\projects\phpbb\phpBB\cache" /grant Users:F /T
- icacls "C:\projects\phpbb\phpBB\files" /grant Users:F /T
- icacls "C:\projects\phpbb\phpBB\store" /grant Users:F /T
- icacls "C:\projects\phpbb\phpBB\images\avatars\upload" /grant Users:F /T
test_script:
- cd c:\projects\phpbb
- php -e phpBB\vendor\phpunit\phpunit\phpunit --verbose

View File

@ -29,11 +29,11 @@ Read our [Vagrant documentation](phpBB/docs/vagrant.md) to find out how to use V
## AUTOMATED TESTING ## AUTOMATED TESTING
We have unit and functional tests in order to prevent regressions. You can view the bamboo continuous integration [here](http://bamboo.phpbb.com) or check our travis builds below: We have unit and functional tests in order to prevent regressions. You can view the bamboo continuous integration [here](https://bamboo.phpbb.com) or check our travis builds below:
* [![Build Status](https://secure.travis-ci.org/phpbb/phpbb.png?branch=master)](http://travis-ci.org/phpbb/phpbb) **master** - Latest development version * [![Build Status](https://travis-ci.org/phpbb/phpbb.svg?branch=master)](http://travis-ci.org/phpbb/phpbb)[![Build status](https://ci.appveyor.com/api/projects/status/8g98ybngd2f3axy1/branch/master?svg=true)](https://ci.appveyor.com/project/phpBB/phpbb/branch/master) **master** - Latest development version
* [![Build Status](https://secure.travis-ci.org/phpbb/phpbb.png?branch=3.2.x)](http://travis-ci.org/phpbb/phpbb) **3.2.x** - Development of version 3.2.x * [![Build Status](https://travis-ci.org/phpbb/phpbb.svg?branch=3.2.x)](http://travis-ci.org/phpbb/phpbb)[![Build status](https://ci.appveyor.com/api/projects/status/8g98ybngd2f3axy1/branch/3.2.x?svg=true)](https://ci.appveyor.com/project/phpBB/phpbb/branch/3.2.x) **3.2.x** - Development of version 3.2.x
* [![Build Status](https://secure.travis-ci.org/phpbb/phpbb.png?branch=3.1.x)](http://travis-ci.org/phpbb/phpbb) **3.1.x** - Development of version 3.1.x * [![Build Status](https://travis-ci.org/phpbb/phpbb.svg?branch=3.1.x)](http://travis-ci.org/phpbb/phpbb) **3.1.x** - Development of version 3.1.x
## LICENSE ## LICENSE

View File

@ -253,7 +253,7 @@ class acp_bbcodes
if ($row) if ($row)
{ {
$bbcode_id = $row['max_bbcode_id'] + 1; $bbcode_id = (int) $row['max_bbcode_id'] + 1;
// Make sure it is greater than the core bbcode ids... // Make sure it is greater than the core bbcode ids...
if ($bbcode_id <= NUM_CORE_BBCODES) if ($bbcode_id <= NUM_CORE_BBCODES)

View File

@ -50,7 +50,8 @@ class mssqlnative extends \phpbb\db\driver\mssql_base
$this->db_connect_id = sqlsrv_connect($this->server, array( $this->db_connect_id = sqlsrv_connect($this->server, array(
'Database' => $this->dbname, 'Database' => $this->dbname,
'UID' => $this->user, 'UID' => $this->user,
'PWD' => $sqlpassword 'PWD' => $sqlpassword,
'CharacterSet' => 'UTF-8'
)); ));
return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error(''); return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error('');

View File

@ -49,18 +49,18 @@ class mssql extends tools
'STEXT' => '[varchar] (3000)', 'STEXT' => '[varchar] (3000)',
'TEXT' => '[varchar] (8000)', 'TEXT' => '[varchar] (8000)',
'MTEXT' => '[text]', 'MTEXT' => '[text]',
'XSTEXT_UNI'=> '[varchar] (100)', 'XSTEXT_UNI'=> '[nvarchar] (100)',
'STEXT_UNI' => '[varchar] (255)', 'STEXT_UNI' => '[nvarchar] (255)',
'TEXT_UNI' => '[varchar] (4000)', 'TEXT_UNI' => '[nvarchar] (4000)',
'MTEXT_UNI' => '[text]', 'MTEXT_UNI' => '[ntext]',
'TIMESTAMP' => '[int]', 'TIMESTAMP' => '[int]',
'DECIMAL' => '[float]', 'DECIMAL' => '[float]',
'DECIMAL:' => '[float]', 'DECIMAL:' => '[float]',
'PDECIMAL' => '[float]', 'PDECIMAL' => '[float]',
'PDECIMAL:' => '[float]', 'PDECIMAL:' => '[float]',
'VCHAR_UNI' => '[varchar] (255)', 'VCHAR_UNI' => '[nvarchar] (255)',
'VCHAR_UNI:'=> '[varchar] (%d)', 'VCHAR_UNI:'=> '[nvarchar] (%d)',
'VCHAR_CI' => '[varchar] (255)', 'VCHAR_CI' => '[nvarchar] (255)',
'VARBINARY' => '[varchar] (255)', 'VARBINARY' => '[varchar] (255)',
), ),
@ -80,18 +80,18 @@ class mssql extends tools
'STEXT' => '[varchar] (3000)', 'STEXT' => '[varchar] (3000)',
'TEXT' => '[varchar] (8000)', 'TEXT' => '[varchar] (8000)',
'MTEXT' => '[text]', 'MTEXT' => '[text]',
'XSTEXT_UNI'=> '[varchar] (100)', 'XSTEXT_UNI'=> '[nvarchar] (100)',
'STEXT_UNI' => '[varchar] (255)', 'STEXT_UNI' => '[nvarchar] (255)',
'TEXT_UNI' => '[varchar] (4000)', 'TEXT_UNI' => '[nvarchar] (4000)',
'MTEXT_UNI' => '[text]', 'MTEXT_UNI' => '[ntext]',
'TIMESTAMP' => '[int]', 'TIMESTAMP' => '[int]',
'DECIMAL' => '[float]', 'DECIMAL' => '[float]',
'DECIMAL:' => '[float]', 'DECIMAL:' => '[float]',
'PDECIMAL' => '[float]', 'PDECIMAL' => '[float]',
'PDECIMAL:' => '[float]', 'PDECIMAL:' => '[float]',
'VCHAR_UNI' => '[varchar] (255)', 'VCHAR_UNI' => '[nvarchar] (255)',
'VCHAR_UNI:'=> '[varchar] (%d)', 'VCHAR_UNI:'=> '[nvarchar] (%d)',
'VCHAR_CI' => '[varchar] (255)', 'VCHAR_CI' => '[nvarchar] (255)',
'VARBINARY' => '[varchar] (255)', 'VARBINARY' => '[varchar] (255)',
), ),
); );
@ -448,6 +448,10 @@ class mssql extends tools
} }
} }
// Drop primary keys depending on this column
$result = $this->mssql_get_drop_default_primary_key_queries($table_name, $column_name);
$statements = array_merge($statements, $result);
// Drop default value constraint // Drop default value constraint
$result = $this->mssql_get_drop_default_constraints_queries($table_name, $column_name); $result = $this->mssql_get_drop_default_constraints_queries($table_name, $column_name);
$statements = array_merge($statements, $result); $statements = array_merge($statements, $result);
@ -541,10 +545,7 @@ class mssql extends tools
{ {
$statements = array(); $statements = array();
if ($this->mssql_is_sql_server_2000()) $this->check_index_name_length($table_name, $index_name);
{
$this->check_index_name_length($table_name, $index_name);
}
// remove index length // remove index length
$column = preg_replace('#:.*$#', '', $column); $column = preg_replace('#:.*$#', '', $column);
@ -554,6 +555,21 @@ class mssql extends tools
return $this->_sql_run_sql($statements); return $this->_sql_run_sql($statements);
} }
/**
* {@inheritdoc}
*/
protected function get_max_index_name_length()
{
if ($this->mssql_is_sql_server_2000())
{
return parent::get_max_index_name_length();
}
else
{
return 128;
}
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -684,6 +700,38 @@ class mssql extends tools
return $statements; return $statements;
} }
/**
* Get queries to drop the primary keys depending on the specified column
*
* We need to drop primary keys depending on this column before being able
* to delete them.
*
* @param string $table_name
* @param string $column_name
* @return array Array with SQL statements
*/
protected function mssql_get_drop_default_primary_key_queries($table_name, $column_name)
{
$statements = array();
$sql = "SELECT ccu.CONSTRAINT_NAME, ccu.COLUMN_NAME
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc
JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu ON tc.CONSTRAINT_NAME = ccu.Constraint_name
WHERE tc.TABLE_NAME = '{$table_name}'
AND tc.CONSTRAINT_TYPE = 'Primary Key'
AND ccu.COLUMN_NAME = '{$column_name}'";
$result = $this->db->sql_query($sql);
while ($primary_key = $this->db->sql_fetchrow($result))
{
$statements[] = 'ALTER TABLE [' . $table_name . '] DROP CONSTRAINT [' . $primary_key['CONSTRAINT_NAME'] . ']';
}
$this->db->sql_freeresult($result);
return $statements;
}
/** /**
* Checks to see if column is an identity column * Checks to see if column is an identity column
* *

View File

@ -1561,7 +1561,8 @@ class tools implements tools_interface
*/ */
protected function check_index_name_length($table_name, $index_name, $throw_error = true) protected function check_index_name_length($table_name, $index_name, $throw_error = true)
{ {
if (strlen($index_name) > 30) $max_index_name_length = $this->get_max_index_name_length();
if (strlen($index_name) > $max_index_name_length)
{ {
// Try removing the table prefix if it's at the beginning // Try removing the table prefix if it's at the beginning
$table_prefix = substr(CONFIG_TABLE, 0, -6); // strlen(config) $table_prefix = substr(CONFIG_TABLE, 0, -6); // strlen(config)
@ -1582,13 +1583,23 @@ class tools implements tools_interface
if ($throw_error) if ($throw_error)
{ {
trigger_error("Index name '$index_name' on table '$table_name' is too long. The maximum is 30 characters.", E_USER_ERROR); trigger_error("Index name '$index_name' on table '$table_name' is too long. The maximum is $max_index_name_length characters.", E_USER_ERROR);
} }
} }
return $index_name; return $index_name;
} }
/**
* Get maximum index name length. Might vary depending on db type
*
* @return int Maximum index name length
*/
protected function get_max_index_name_length()
{
return 30;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */

View File

@ -533,7 +533,7 @@ abstract class nestedset implements \phpbb\tree\tree_interface
$row = $this->db->sql_fetchrow($result); $row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result); $this->db->sql_freeresult($result);
$diff = ' + ' . ($row[$this->column_right_id] - (int) $item[$this->column_left_id] + 1); $diff = ' + ' . ((int) $row[$this->column_right_id] - (int) $item[$this->column_left_id] + 1);
} }
$sql = 'UPDATE ' . $this->table_name . ' $sql = 'UPDATE ' . $this->table_name . '

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<dataset> <dataset>
<table name="phpbb_attachments"> <table name="phpbb_attachments">
<column>attach_id</column>
<column>post_msg_id</column> <column>post_msg_id</column>
<column>topic_id</column> <column>topic_id</column>
<column>in_message</column> <column>in_message</column>
@ -9,6 +10,7 @@
<column>physical_filename</column> <column>physical_filename</column>
<column>thumbnail</column> <column>thumbnail</column>
<row> <row>
<value>1</value>
<value>1</value> <value>1</value>
<value>1</value> <value>1</value>
<value>0</value> <value>0</value>
@ -18,6 +20,7 @@
<value>0</value> <value>0</value>
</row> </row>
<row> <row>
<value>2</value>
<value>1</value> <value>1</value>
<value>1</value> <value>1</value>
<value>1</value> <value>1</value>
@ -27,6 +30,7 @@
<value>0</value> <value>0</value>
</row> </row>
<row> <row>
<value>3</value>
<value>1</value> <value>1</value>
<value>1</value> <value>1</value>
<value>1</value> <value>1</value>
@ -37,13 +41,16 @@
</row> </row>
</table> </table>
<table name="phpbb_extensions"> <table name="phpbb_extensions">
<column>extension_id</column>
<column>extension</column> <column>extension</column>
<column>group_id</column> <column>group_id</column>
<row> <row>
<value>1</value>
<value>jpg</value> <value>jpg</value>
<value>1</value> <value>1</value>
</row> </row>
<row> <row>
<value>2</value>
<value>png</value> <value>png</value>
<value>1</value> <value>1</value>
</row> </row>

View File

@ -14,12 +14,15 @@
use Symfony\Component\Console\Application; use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
use phpbb\console\command\user\add; use phpbb\console\command\user\add;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
require_once dirname(__FILE__) . '/base.php'; require_once dirname(__FILE__) . '/base.php';
class phpbb_console_user_add_test extends phpbb_console_user_base class phpbb_console_user_add_test extends phpbb_console_user_base
{ {
public function get_command_tester() public function get_command_tester($question_answers = [])
{ {
$application = new Application(); $application = new Application();
$application->add(new add( $application->add(new add(
@ -34,7 +37,42 @@ class phpbb_console_user_add_test extends phpbb_console_user_base
$command = $application->find('user:add'); $command = $application->find('user:add');
$this->command_name = $command->getName(); $this->command_name = $command->getName();
$this->question = $command->getHelper('question');
if (!empty($question_answers))
{
$ask = function(InputInterface $input, OutputInterface $output, Question $question) use ($question_answers)
{
$text = $question->getQuestion();
// handle a question
foreach ($question_answers as $expected_question => $answer)
{
if (strpos($text, $expected_question) !== false)
{
$response = $answer;
}
}
if (!isset($response))
{
throw new \RuntimeException('Was asked for input on an unhandled question: ' . $text);
}
$output->writeln(print_r($response, true));
return $response;
};
$helper = $this->getMock('\Symfony\Component\Console\Helper\QuestionHelper', array('ask'));
$helper->expects($this->any())
->method('ask')
->will($this->returnCallback($ask));
$this->question = $helper;
$command->getHelperSet()->set($helper, 'question');
}
else
{
$this->question = $command->getHelper('question');
}
return new CommandTester($command); return new CommandTester($command);
} }
@ -57,7 +95,11 @@ class phpbb_console_user_add_test extends phpbb_console_user_base
public function test_add_dialog() public function test_add_dialog()
{ {
$command_tester = $this->get_command_tester(); $command_tester = $this->get_command_tester([
'USERNAME' => 'bar',
'PASSWORD' => 'password',
'EMAIL_ADDRESS' => 'bar@test.com',
]);
$this->assertEquals(2, $this->get_user_id('Admin')); $this->assertEquals(2, $this->get_user_id('Admin'));

View File

@ -203,8 +203,15 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
public function test_list_columns() public function test_list_columns()
{ {
$config = $this->get_database_config();
$table_columns = $this->table_data['COLUMNS'];
if (strpos($config['dbms'], 'mssql') !== false)
{
ksort($table_columns);
}
$this->assertEquals( $this->assertEquals(
array_keys($this->table_data['COLUMNS']), array_keys($table_columns),
array_values($this->tools->sql_list_columns('prefix_table_name')) array_values($this->tools->sql_list_columns('prefix_table_name'))
); );
} }
@ -432,28 +439,37 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
$this->markTestIncomplete('The table prefix length is too long for proper testing of index shortening function.'); $this->markTestIncomplete('The table prefix length is too long for proper testing of index shortening function.');
} }
$max_index_length = 30;
if ($this->tools instanceof \phpbb\db\tools\mssql)
{
$max_length_method = new ReflectionMethod('\phpbb\db\tools\mssql', 'get_max_index_name_length');
$max_length_method->setAccessible(true);
$max_index_length = $max_length_method->invoke($this->tools);
}
$table_suffix = str_repeat('a', 25 - strlen($table_prefix)); $table_suffix = str_repeat('a', 25 - strlen($table_prefix));
$table_name = $table_prefix . $table_suffix; $table_name = $table_prefix . $table_suffix;
$this->tools->sql_create_table($table_name, $this->table_data); $this->tools->sql_create_table($table_name, $this->table_data);
// Index name and table suffix and table prefix have > 30 chars in total. // Index name and table suffix and table prefix have > maximum index length chars in total.
// Index name and table suffix have <= 30 chars in total. // Index name and table suffix have <= maximum index length chars in total.
$long_index_name = str_repeat('i', 30 - strlen($table_suffix)); $long_index_name = str_repeat('i', $max_index_length - strlen($table_suffix));
$this->assertFalse($this->tools->sql_index_exists($table_name, $long_index_name)); $this->assertFalse($this->tools->sql_index_exists($table_name, $long_index_name));
$this->assertTrue($this->tools->sql_create_index($table_name, $long_index_name, array('c_timestamp'))); $this->assertTrue($this->tools->sql_create_index($table_name, $long_index_name, array('c_timestamp')));
$this->assertTrue($this->tools->sql_index_exists($table_name, $long_index_name)); $this->assertTrue($this->tools->sql_index_exists($table_name, $long_index_name));
// Index name and table suffix have > 30 chars in total. // Index name and table suffix have > maximum index length chars in total.
$very_long_index_name = str_repeat('i', 30); $very_long_index_name = str_repeat('i', $max_index_length);
$this->assertFalse($this->tools->sql_index_exists($table_name, $very_long_index_name)); $this->assertFalse($this->tools->sql_index_exists($table_name, $very_long_index_name));
$this->assertTrue($this->tools->sql_create_index($table_name, $very_long_index_name, array('c_timestamp'))); $this->assertTrue($this->tools->sql_create_index($table_name, $very_long_index_name, array('c_timestamp')));
$this->assertTrue($this->tools->sql_index_exists($table_name, $very_long_index_name)); $this->assertTrue($this->tools->sql_index_exists($table_name, $very_long_index_name));
$this->tools->sql_table_drop($table_name); $this->tools->sql_table_drop($table_name);
// Index name has > 30 chars - that should not be possible. // Index name has > maximum index length chars - that should not be possible.
$too_long_index_name = str_repeat('i', 31); $too_long_index_name = str_repeat('i', $max_index_length + 1);
$this->assertFalse($this->tools->sql_index_exists('prefix_table_name', $too_long_index_name)); $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', $too_long_index_name));
$this->setExpectedTriggerError(E_USER_ERROR); $this->setExpectedTriggerError(E_USER_ERROR);
$this->tools->sql_create_index('prefix_table_name', $too_long_index_name, array('c_timestamp')); $this->tools->sql_create_index('prefix_table_name', $too_long_index_name, array('c_timestamp'));

View File

@ -60,25 +60,31 @@
<table name="phpbb_user_group"> <table name="phpbb_user_group">
<column>user_id</column> <column>user_id</column>
<column>group_id</column> <column>group_id</column>
<column>group_leader</column>
<row> <row>
<value>1</value> <value>1</value>
<value>1</value> <value>1</value>
<value>2</value>
</row> </row>
<row> <row>
<value>2</value> <value>2</value>
<value>1</value> <value>1</value>
<value>2</value>
</row> </row>
<row> <row>
<value>3</value> <value>3</value>
<value>1</value> <value>1</value>
<value>2</value>
</row> </row>
<row> <row>
<value>4</value> <value>4</value>
<value>2</value> <value>2</value>
<value>2</value>
</row> </row>
<row> <row>
<value>5</value> <value>5</value>
<value>2</value> <value>2</value>
<value>2</value>
</row> </row>
</table> </table>
</dataset> </dataset>

View File

@ -133,7 +133,7 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case
for ($i = 0; $i < $crawler->filter('dl')->count(); $i++) for ($i = 0; $i < $crawler->filter('dl')->count(); $i++)
{ {
$text = $crawler->filter('dl')->eq($i)->text(); $text = trim($crawler->filter('dl')->eq($i)->text());
$match = false; $match = false;

View File

@ -1,9 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<dataset> <dataset>
<table name="phpbb_groups"> <table name="phpbb_groups">
<column>group_id</column>
<column>group_name</column> <column>group_name</column>
<column>group_desc</column> <column>group_desc</column>
<row> <row>
<value>10</value>
<value>foobar_group</value> <value>foobar_group</value>
<value>test123</value> <value>test123</value>
</row> </row>

View File

@ -515,35 +515,44 @@
</table> </table>
<table name="phpbb_privmsgs_folder"> <table name="phpbb_privmsgs_folder">
<column>user_id</column> <column>user_id</column>
<column>folder_id</column>
<row> <row>
<value>2</value> <value>2</value>
<value>1</value>
</row> </row>
<row> <row>
<value>3</value> <value>3</value>
<value>2</value>
</row> </row>
</table> </table>
<table name="phpbb_privmsgs_rules"> <table name="phpbb_privmsgs_rules">
<column>user_id</column> <column>user_id</column>
<column>rule_string</column> <column>rule_string</column>
<column>rule_id</column>
<row> <row>
<value>2</value> <value>2</value>
<value></value> <value></value>
<value>1</value>
</row> </row>
<row> <row>
<value>3</value> <value>3</value>
<value></value> <value></value>
<value>2</value>
</row> </row>
</table> </table>
<table name="phpbb_drafts"> <table name="phpbb_drafts">
<column>user_id</column> <column>user_id</column>
<column>draft_message</column> <column>draft_message</column>
<column>draft_id</column>
<row> <row>
<value>2</value> <value>2</value>
<value></value> <value></value>
<value>1</value>
</row> </row>
<row> <row>
<value>3</value> <value>3</value>
<value></value> <value></value>
<value>2</value>
</row> </row>
</table> </table>
</dataset> </dataset>

View File

@ -29,6 +29,7 @@
</row> </row>
</table> </table>
<table name="phpbb_notifications"> <table name="phpbb_notifications">
<column>notification_id</column>
<column>notification_type_id</column> <column>notification_type_id</column>
<column>user_id</column> <column>user_id</column>
<column>item_id</column> <column>item_id</column>
@ -36,6 +37,7 @@
<column>notification_read</column> <column>notification_read</column>
<column>notification_data</column> <column>notification_data</column>
<row> <row>
<value>1</value>
<value>1</value> <value>1</value>
<value>5</value> <value>5</value>
<value>1</value> <value>1</value>

View File

@ -21,6 +21,7 @@
</row> </row>
</table> </table>
<table name="phpbb_notifications"> <table name="phpbb_notifications">
<column>notification_id</column>
<column>notification_type_id</column> <column>notification_type_id</column>
<column>user_id</column> <column>user_id</column>
<column>item_id</column> <column>item_id</column>
@ -28,6 +29,7 @@
<column>notification_read</column> <column>notification_read</column>
<column>notification_data</column> <column>notification_data</column>
<row> <row>
<value>1</value>
<value>1</value> <value>1</value>
<value>5</value> <value>5</value>
<value>1</value> <value>1</value>
@ -36,6 +38,7 @@
<value></value> <value></value>
</row> </row>
<row> <row>
<value>2</value>
<value>1</value> <value>1</value>
<value>8</value> <value>8</value>
<value>1</value> <value>1</value>

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<dataset> <dataset>
<table name="phpbb_notifications"> <table name="phpbb_notifications">
<column>notification_id</column>
<column>notification_type_id</column> <column>notification_type_id</column>
<column>user_id</column> <column>user_id</column>
<column>item_id</column> <column>item_id</column>
@ -8,6 +9,7 @@
<column>notification_read</column> <column>notification_read</column>
<column>notification_data</column> <column>notification_data</column>
<row> <row>
<value>1</value>
<value>1</value> <value>1</value>
<value>6</value> <value>6</value>
<value>1</value> <value>1</value>

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<dataset> <dataset>
<table name="phpbb_notifications"> <table name="phpbb_notifications">
<column>notification_id</column>
<column>notification_type_id</column> <column>notification_type_id</column>
<column>user_id</column> <column>user_id</column>
<column>item_id</column> <column>item_id</column>
@ -8,6 +9,7 @@
<column>notification_read</column> <column>notification_read</column>
<column>notification_data</column> <column>notification_data</column>
<row> <row>
<value>1</value>
<value>1</value> <value>1</value>
<value>5</value> <value>5</value>
<value>1</value> <value>1</value>

View File

@ -21,6 +21,7 @@
</row> </row>
</table> </table>
<table name="phpbb_notifications"> <table name="phpbb_notifications">
<column>notification_id</column>
<column>notification_type_id</column> <column>notification_type_id</column>
<column>user_id</column> <column>user_id</column>
<column>item_id</column> <column>item_id</column>
@ -28,6 +29,7 @@
<column>notification_read</column> <column>notification_read</column>
<column>notification_data</column> <column>notification_data</column>
<row> <row>
<value>1</value>
<value>1</value> <value>1</value>
<value>8</value> <value>8</value>
<value>1</value> <value>1</value>

View File

@ -108,7 +108,7 @@ class phpbb_notification_test extends phpbb_tests_notification_base
$types = array('notification.type.quote', 'notification.type.bookmark', 'notification.type.post', 'test'); $types = array('notification.type.quote', 'notification.type.bookmark', 'notification.type.post', 'test');
foreach ($types as $id => $type) foreach ($types as $id => $type)
{ {
$this->db->sql_query('INSERT INTO phpbb_notification_types ' . $this->getConnection()->createQueryTable('insertNotification', 'INSERT INTO phpbb_notification_types ' .
$this->db->sql_build_array('INSERT', array( $this->db->sql_build_array('INSERT', array(
'notification_type_id' => ($id + 1), 'notification_type_id' => ($id + 1),
'notification_type_name' => $type, 'notification_type_name' => $type,

View File

@ -1,25 +1,30 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<dataset> <dataset>
<table name="phpbb_posts"> <table name="phpbb_posts">
<column>post_id</column>
<column>post_username</column> <column>post_username</column>
<column>post_subject</column> <column>post_subject</column>
<column>post_text</column> <column>post_text</column>
<row> <row>
<value>1</value>
<value>foo</value> <value>foo</value>
<value>foo</value> <value>foo</value>
<value>foo</value> <value>foo</value>
</row> </row>
<row> <row>
<value>2</value>
<value>bar</value> <value>bar</value>
<value>bar</value> <value>bar</value>
<value>bar</value> <value>bar</value>
</row> </row>
<row> <row>
<value>3</value>
<value>commonword</value> <value>commonword</value>
<value>commonword</value> <value>commonword</value>
<value>commonword</value> <value>commonword</value>
</row> </row>
<row> <row>
<value>4</value>
<value>baaz</value> <value>baaz</value>
<value>baaz</value> <value>baaz</value>
<value>baaz</value> <value>baaz</value>

View File

@ -142,9 +142,86 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
$manager->database_synchronisation($table_column_map); $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) public function createXMLDataSet($path)
{ {
$this->fixture_xml_data = parent::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; return $this->fixture_xml_data;
} }

View File

@ -222,6 +222,14 @@ class phpbb_database_test_connection_manager
$this->purge_extras(); $this->purge_extras();
break; 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: default:
$this->connect(false); $this->connect(false);

View File

@ -509,7 +509,6 @@ class phpbb_functional_test_case extends phpbb_test_case
else else
{ {
$db->sql_multi_insert(STYLES_TABLE, array(array( $db->sql_multi_insert(STYLES_TABLE, array(array(
'style_id' => $style_id,
'style_name' => $style_path, 'style_name' => $style_path,
'style_copyright' => '', 'style_copyright' => '',
'style_active' => 1, 'style_active' => 1,

View File

@ -69,7 +69,7 @@ class phpbb_tests_tree_nestedset_forum_base extends phpbb_database_test_case
static $forums; static $forums;
if (empty($forums)) if (empty($forums))
{ {
$this->create_forum('Parent with two flat children'); $this->create_forum('Parent with two flat children');
$this->create_forum('Flat child #1', 1); $this->create_forum('Flat child #1', 1);
$this->create_forum('Flat child #2', 1); $this->create_forum('Flat child #2', 1);
@ -86,7 +86,7 @@ class phpbb_tests_tree_nestedset_forum_base extends phpbb_database_test_case
// Updating forum_parents column here so it's not empty // Updating forum_parents column here so it's not empty
// This is required, so we can see whether the methods // This is required, so we can see whether the methods
// correctly clear the values. // correctly clear the values.
$sql = "UPDATE phpbb_forums $sql = "UPDATE phpbb_forums
SET forum_parents = 'a:0:{}'"; SET forum_parents = 'a:0:{}'";
$this->db->sql_query($sql); $this->db->sql_query($sql);
@ -100,6 +100,13 @@ class phpbb_tests_tree_nestedset_forum_base extends phpbb_database_test_case
} }
else else
{ {
// Turn on identity insert on mssql to be able to insert into
// identity columns (e.g. forum_id)
if (strpos($this->db->sql_layer, 'mssql') !== false)
{
$sql = 'SET IDENTITY_INSERT phpbb_forums ON';
$this->db->sql_query($sql);
}
$buffer = new \phpbb\db\sql_insert_buffer($this->db, 'phpbb_forums'); $buffer = new \phpbb\db\sql_insert_buffer($this->db, 'phpbb_forums');
$buffer->insert_all($forums); $buffer->insert_all($forums);
$buffer->flush(); $buffer->flush();
@ -107,7 +114,14 @@ class phpbb_tests_tree_nestedset_forum_base extends phpbb_database_test_case
$this->database_synchronisation(array( $this->database_synchronisation(array(
'phpbb_forums' => array('forum_id'), 'phpbb_forums' => array('forum_id'),
)); ));
}
// Disable identity insert on mssql again
if (strpos($this->db->sql_layer, 'mssql') !== false)
{
$sql = 'SET IDENTITY_INSERT phpbb_forums OFF';
$this->db->sql_query($sql);
}
}
} }
protected function create_forum($name, $parent_id = 0) protected function create_forum($name, $parent_id = 0)