From cbee288eeb74efa92b39abe7a2db71dc00ef5b66 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 27 Jan 2017 23:06:59 +0100 Subject: [PATCH 01/21] [ticket/15055] Add .appveyor.yml file PHPBB3-15055 --- .appveyor.yml | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .appveyor.yml diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 0000000000..1246c7735f --- /dev/null +++ b/.appveyor.yml @@ -0,0 +1,39 @@ +build: false +clone_folder: c:\projects\phpbb + +services: + - mssql2014 + +init: + - SET PATH=c:\php;%PATH% + - SET COMPOSER_NO_INTERACTION=1 + - SET SYMFONY_DEPRECATIONS_HELPER=strict + - SET ANSICON=121x90 (121x90) + - SET SYMFONY_PHPUNIT_SKIPPED_TESTS=phpunit.skipped + - REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Command Processor" /v DelayedExpansion /t REG_DWORD /d 1 /f + +before_test: + - sqlcmd -S "(local)\SQL2014" -Q "Use [master]; CREATE DATABASE [phpbb_test]" + - SET PATH=C:\Program Files\OpenSSL;C:\tools\php;%PATH% + - cinst -y php -version 5.6.17 --allow-empty-checksums + - cd c:\tools\php + - ps: cat php.ini-production | %{$_ -replace "memory_limit = 128M","memory_limit = 1024M"} | Out-File -Encoding "Default" php.ini + - echo date.timezone="UTC" >> php.ini + - echo extension_dir=ext >> php.ini + - echo extension=php_openssl.dll >> php.ini + - echo extension=php_mbstring.dll >> php.ini + - echo extension=php_curl.dll >> php.ini + - echo extension=php_gd2.dll >> php.ini + - echo extension=php_tidy.dll >> php.ini + - echo extension=php_fileinfo.dll >> php.ini + - php -r "readfile('https://dl.dropboxusercontent.com/u/7129062/sqlsrv_unofficial_3.0.2.2.zip');" > sqlsrv.zip + - unzip sqlsrv.zip + - copy sqlsrv_unofficial_3.0.2.2\x64\*.dll ext + - echo extension=php_sqlsrv_56_nts.dll >> php.ini + - echo extension=php_pdo_sqlsrv_56_nts.dll >> php.ini + - cd c:\projects\phpbb\phpBB + - php ..\composer.phar install + +test_script: + - cd c:\projects\phpbb + - php -e phpBB\vendor\phpunit\phpunit\phpunit From d65d776d9263954a5bea849ab4d061b383aa564a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 27 Jan 2017 23:47:24 +0100 Subject: [PATCH 02/21] [ticket/15055] Output test config to test_config.php PHPBB3-15055 --- .appveyor.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 1246c7735f..077742e799 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -33,7 +33,10 @@ before_test: - echo extension=php_pdo_sqlsrv_56_nts.dll >> php.ini - cd c:\projects\phpbb\phpBB - php ..\composer.phar install + - cd c:\projects\phpbb\tests + - touch test_config.php + - ps: $data = " Date: Sat, 28 Jan 2017 11:30:34 +0100 Subject: [PATCH 03/21] [ticket/15055] Debug issues PHPBB3-15055 --- .appveyor.yml | 2 +- tests/attachment/fixtures/resync.xml | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 077742e799..5a4b2b4951 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -39,4 +39,4 @@ before_test: test_script: - cd c:\projects\phpbb - - php -e phpBB\vendor\phpunit\phpunit\phpunit --verbose + - php -e phpBB\vendor\phpunit\phpunit\phpunit --verbose --stop-on-error diff --git a/tests/attachment/fixtures/resync.xml b/tests/attachment/fixtures/resync.xml index 6e2cc62f68..af04701b4a 100644 --- a/tests/attachment/fixtures/resync.xml +++ b/tests/attachment/fixtures/resync.xml @@ -1,6 +1,7 @@ + attach_idpost_msg_idtopic_idin_message @@ -9,6 +10,7 @@ physical_filenamethumbnail + 1 1 1 0 @@ -18,6 +20,7 @@ 0 + 2 1 1 1 @@ -27,6 +30,7 @@ 0 + 3 1 1 1 @@ -37,13 +41,16 @@
+ extension_idextensiongroup_id + 1 jpg 1 + 2 png 1 From 66143e99bee0931b77c50d9e3b1fbd0b9629e48d Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 29 Jan 2017 11:05:45 +0100 Subject: [PATCH 04/21] [ticket/15055] Further fixes to ensure PHP 7.1 & mssql compatibility PHPBB3-15055 --- .appveyor.yml | 6 ++---- phpBB/includes/acp/acp_bbcodes.php | 2 +- tests/console/user/base.php | 5 +++++ tests/test_framework/phpbb_functional_test_case.php | 1 - 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 5a4b2b4951..9ca7aee8a0 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -6,10 +6,7 @@ services: init: - SET PATH=c:\php;%PATH% - - SET COMPOSER_NO_INTERACTION=1 - - SET SYMFONY_DEPRECATIONS_HELPER=strict - SET ANSICON=121x90 (121x90) - - SET SYMFONY_PHPUNIT_SKIPPED_TESTS=phpunit.skipped - REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Command Processor" /v DelayedExpansion /t REG_DWORD /d 1 /f before_test: @@ -19,6 +16,7 @@ before_test: - cd c:\tools\php - ps: cat php.ini-production | %{$_ -replace "memory_limit = 128M","memory_limit = 1024M"} | Out-File -Encoding "Default" php.ini - echo date.timezone="UTC" >> php.ini + - echo display_errors=On >> php.ini - echo extension_dir=ext >> php.ini - echo extension=php_openssl.dll >> php.ini - echo extension=php_mbstring.dll >> php.ini @@ -39,4 +37,4 @@ before_test: test_script: - cd c:\projects\phpbb - - php -e phpBB\vendor\phpunit\phpunit\phpunit --verbose --stop-on-error + - php -e phpBB\vendor\phpunit\phpunit\phpunit --verbose diff --git a/phpBB/includes/acp/acp_bbcodes.php b/phpBB/includes/acp/acp_bbcodes.php index 18d574081a..e9d96bdecc 100644 --- a/phpBB/includes/acp/acp_bbcodes.php +++ b/phpBB/includes/acp/acp_bbcodes.php @@ -253,7 +253,7 @@ class acp_bbcodes 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... if ($bbcode_id <= NUM_CORE_BBCODES) diff --git a/tests/console/user/base.php b/tests/console/user/base.php index b84c0bb267..6e5436fb9d 100644 --- a/tests/console/user/base.php +++ b/tests/console/user/base.php @@ -34,6 +34,11 @@ abstract class phpbb_console_user_base extends phpbb_database_test_case { global $auth, $db, $cache, $config, $user, $phpbb_dispatcher, $phpbb_container, $phpbb_root_path, $phpEx; + if (strtolower(substr(PHP_OS, 0, 5)) !== 'linux') + { + $this->markTestSkipped('Unable to test console feature on OS other than Linux.'); + } + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); $phpbb_container = new phpbb_mock_container_builder(); $phpbb_container->set('cache.driver', new phpbb_mock_cache()); diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index c9943c4302..4e22e7b039 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, From 44ba0f5054151e3207ff49610728bf8cfe1ab78f Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 29 Jan 2017 11:50:22 +0100 Subject: [PATCH 05/21] [ticket/15055] Start setting up IIS PHPBB3-15055 --- .appveyor.yml | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 9ca7aee8a0..363d528523 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,8 +1,13 @@ build: false clone_folder: c:\projects\phpbb +version: '{build}' services: - mssql2014 + - iis + +hosts: + phpbb.test: 127.0.0.1 init: - SET PATH=c:\php;%PATH% @@ -33,7 +38,23 @@ before_test: - php ..\composer.phar install - cd c:\projects\phpbb\tests - touch test_config.php - - ps: $data = " Date: Sun, 29 Jan 2017 14:05:27 +0100 Subject: [PATCH 06/21] [ticket/15055] Start fixing missing keys in fixtures PHPBB3-15055 --- .appveyor.yml | 2 ++ tests/dbal/fixtures/boolean_processor.xml | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/.appveyor.yml b/.appveyor.yml index 363d528523..472ac433bb 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -51,6 +51,8 @@ before_test: - 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 diff --git a/tests/dbal/fixtures/boolean_processor.xml b/tests/dbal/fixtures/boolean_processor.xml index c5da677116..d31d679f45 100644 --- a/tests/dbal/fixtures/boolean_processor.xml +++ b/tests/dbal/fixtures/boolean_processor.xml @@ -60,25 +60,31 @@
user_idgroup_id + group_leader 1 1 + 2 2 1 + 2 3 1 + 2 4 2 + 2 5 2 + 2
From 5bb62f5560ee913efe56c1fcb8c1a855204cc658 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 29 Jan 2017 15:56:21 +0100 Subject: [PATCH 07/21] [ticket/15055] Use unicode column types where necessary PHPBB3-15055 --- phpBB/phpbb/db/tools/mssql.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/phpBB/phpbb/db/tools/mssql.php b/phpBB/phpbb/db/tools/mssql.php index 23b49aab44..6f800f730d 100644 --- a/phpBB/phpbb/db/tools/mssql.php +++ b/phpBB/phpbb/db/tools/mssql.php @@ -49,18 +49,18 @@ class mssql extends tools 'STEXT' => '[varchar] (3000)', 'TEXT' => '[varchar] (8000)', 'MTEXT' => '[text]', - 'XSTEXT_UNI'=> '[varchar] (100)', - 'STEXT_UNI' => '[varchar] (255)', - 'TEXT_UNI' => '[varchar] (4000)', - 'MTEXT_UNI' => '[text]', + 'XSTEXT_UNI'=> '[nvarchar] (100)', + 'STEXT_UNI' => '[nvarchar] (255)', + 'TEXT_UNI' => '[nvarchar] (4000)', + 'MTEXT_UNI' => '[ntext]', 'TIMESTAMP' => '[int]', 'DECIMAL' => '[float]', 'DECIMAL:' => '[float]', 'PDECIMAL' => '[float]', 'PDECIMAL:' => '[float]', - 'VCHAR_UNI' => '[varchar] (255)', - 'VCHAR_UNI:'=> '[varchar] (%d)', - 'VCHAR_CI' => '[varchar] (255)', + 'VCHAR_UNI' => '[nvarchar] (255)', + 'VCHAR_UNI:'=> '[nvarchar] (%d)', + 'VCHAR_CI' => '[nvarchar] (255)', 'VARBINARY' => '[varchar] (255)', ), @@ -80,18 +80,18 @@ class mssql extends tools 'STEXT' => '[varchar] (3000)', 'TEXT' => '[varchar] (8000)', 'MTEXT' => '[text]', - 'XSTEXT_UNI'=> '[varchar] (100)', - 'STEXT_UNI' => '[varchar] (255)', - 'TEXT_UNI' => '[varchar] (4000)', - 'MTEXT_UNI' => '[text]', + 'XSTEXT_UNI'=> '[nvarchar] (100)', + 'STEXT_UNI' => '[nvarchar] (255)', + 'TEXT_UNI' => '[nvarchar] (4000)', + 'MTEXT_UNI' => '[ntext]', 'TIMESTAMP' => '[int]', 'DECIMAL' => '[float]', 'DECIMAL:' => '[float]', 'PDECIMAL' => '[float]', 'PDECIMAL:' => '[float]', - 'VCHAR_UNI' => '[varchar] (255)', - 'VCHAR_UNI:'=> '[varchar] (%d)', - 'VCHAR_CI' => '[varchar] (255)', + 'VCHAR_UNI' => '[nvarchar] (255)', + 'VCHAR_UNI:'=> '[nvarchar] (%d)', + 'VCHAR_CI' => '[nvarchar] (255)', 'VARBINARY' => '[varchar] (255)', ), ); From 635befa00e0d9791137a2a500260b578021f60b8 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 29 Jan 2017 15:56:45 +0100 Subject: [PATCH 08/21] [ticket/15055] Drop primary keys when necessary and fix test comparisons PHPBB3-15055 --- phpBB/phpbb/db/tools/mssql.php | 35 ++++++++++++++++++++++++++++++++++ tests/dbal/db_tools_test.php | 9 ++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/phpBB/phpbb/db/tools/mssql.php b/phpBB/phpbb/db/tools/mssql.php index 6f800f730d..0dfb09b1ba 100644 --- a/phpBB/phpbb/db/tools/mssql.php +++ b/phpBB/phpbb/db/tools/mssql.php @@ -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 $result = $this->mssql_get_drop_default_constraints_queries($table_name, $column_name); $statements = array_merge($statements, $result); @@ -684,6 +688,37 @@ class mssql extends tools 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'"; + + $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 * diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index f9243e7266..f78cebdec7 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -203,8 +203,15 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case 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( - array_keys($this->table_data['COLUMNS']), + array_keys($table_columns), array_values($this->tools->sql_list_columns('prefix_table_name')) ); } From f903e5b3c025560d44622bcd4d15c7e0fa3b1633 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 24 Dec 2017 11:06:31 +0100 Subject: [PATCH 09/21] [ticket/15055] Try moving to PHP 7.1 PHPBB3-15055 --- .appveyor.yml | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 472ac433bb..ef301584b7 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -15,9 +15,13 @@ init: - 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 - sqlcmd -S "(local)\SQL2014" -Q "Use [master]; CREATE DATABASE [phpbb_test]" - SET PATH=C:\Program Files\OpenSSL;C:\tools\php;%PATH% - - cinst -y php -version 5.6.17 --allow-empty-checksums + - ps: Set-Service wuauserv -StartupType Manual + - ps: cinst -y php --version ((choco search php --exact --all-versions -r | select-string -pattern 7.1 | sort { [version]($_ -split '\|' | select -last 1) } -Descending | Select-Object -first 1) -replace '[php|]','') + - ps: Get-ChildItem -Path "c:\tools\php71" -Recurse | + Move-Item -destination "c:\tools\php" - cd c:\tools\php - ps: cat php.ini-production | %{$_ -replace "memory_limit = 128M","memory_limit = 1024M"} | Out-File -Encoding "Default" php.ini - echo date.timezone="UTC" >> php.ini @@ -29,11 +33,18 @@ before_test: - echo extension=php_gd2.dll >> php.ini - echo extension=php_tidy.dll >> php.ini - echo extension=php_fileinfo.dll >> php.ini - - php -r "readfile('https://dl.dropboxusercontent.com/u/7129062/sqlsrv_unofficial_3.0.2.2.zip');" > sqlsrv.zip - - unzip sqlsrv.zip - - copy sqlsrv_unofficial_3.0.2.2\x64\*.dll ext - - echo extension=php_sqlsrv_56_nts.dll >> php.ini - - echo extension=php_pdo_sqlsrv_56_nts.dll >> php.ini + - ps: | + cd c:\tools\php\ext + $DLLVersion = "4.1.6.1" + appveyor DownloadFile http://windows.php.net/downloads/pecl/releases/sqlsrv/$($:DLLVersion)/php_sqlsrv-$($DLLVersion)-7.1-nts-vc14-x64.zip + 7z x -y php_sqlsrv-$($DLLVersion)-7.1-nts-vc14-x64.zip > $null + appveyor-retry appveyor DownloadFile http://windows.php.net/downloads/pecl/releases/pdo_sqlsrv/$($DLLVersion)/php_pdo_sqlsrv-$($DLLVersion)-7.1-nts-vc14-x64.zip + 7z x -y php_pdo_sqlsrv-$($DLLVersion)-7.1-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" - cd c:\projects\phpbb\phpBB - php ..\composer.phar install - cd c:\projects\phpbb\tests From f4381a20d4ec6201a00cd618c24fd29b67f77965 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 24 Dec 2017 16:48:28 +0100 Subject: [PATCH 10/21] [ticket/15055] Handle default identity column on mssql in database tests PHPBB3-15055 --- .../phpbb_database_test_case.php | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) 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; } From 400fc0f73d03010d3bf28d2b1db5d789dc085334 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 25 Dec 2017 18:49:31 +0100 Subject: [PATCH 11/21] [ticket/15055] Only drop dependent PK indexes and fix more tests for mssql PHPBB3-15055 --- phpBB/phpbb/db/tools/mssql.php | 3 +- tests/dbal/db_tools_test.php | 5 +++- .../functions/fixtures/validate_username.xml | 2 ++ tests/functions_user/fixtures/delete_user.xml | 9 ++++++ ...submit_post_notification.type.bookmark.xml | 2 ++ .../submit_post_notification.type.post.xml | 3 ++ ...t_post_notification.type.post_in_queue.xml | 2 ++ .../submit_post_notification.type.quote.xml | 2 ++ .../submit_post_notification.type.topic.xml | 2 ++ tests/notification/notification_test.php | 2 +- tests/search/fixtures/posts.xml | 5 ++++ .../phpbb_database_test_case.php | 30 ++++++++++++++----- 12 files changed, 57 insertions(+), 10 deletions(-) diff --git a/phpBB/phpbb/db/tools/mssql.php b/phpBB/phpbb/db/tools/mssql.php index 0dfb09b1ba..1e4d3aee2f 100644 --- a/phpBB/phpbb/db/tools/mssql.php +++ b/phpBB/phpbb/db/tools/mssql.php @@ -706,7 +706,8 @@ class mssql extends tools 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 tc.CONSTRAINT_TYPE = 'Primary Key' + AND ccu.COLUMN_NAME = '{$column_name}'"; $result = $this->db->sql_query($sql); diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index f78cebdec7..dbe2c2909a 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -462,7 +462,10 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case // Index name has > 30 chars - that should not be possible. $too_long_index_name = str_repeat('i', 31); $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', $too_long_index_name)); - $this->setExpectedTriggerError(E_USER_ERROR); + if (strpos($this->tools->sql_layer, 'mssql') === false) + { + $this->setExpectedTriggerError(E_USER_ERROR); + } $this->tools->sql_create_index('prefix_table_name', $too_long_index_name, array('c_timestamp')); } } diff --git a/tests/functions/fixtures/validate_username.xml b/tests/functions/fixtures/validate_username.xml index 1b85a2f06d..add8f76553 100644 --- a/tests/functions/fixtures/validate_username.xml +++ b/tests/functions/fixtures/validate_username.xml @@ -1,9 +1,11 @@ + group_idgroup_namegroup_desc + 10 foobar_group test123 diff --git a/tests/functions_user/fixtures/delete_user.xml b/tests/functions_user/fixtures/delete_user.xml index 56014b35d1..8de2659722 100644 --- a/tests/functions_user/fixtures/delete_user.xml +++ b/tests/functions_user/fixtures/delete_user.xml @@ -515,35 +515,44 @@
user_id + folder_id 2 + 1 3 + 2
user_idrule_string + rule_id 2 + 1 3 + 2
user_iddraft_message + draft_id 2 + 1 3 + 2
diff --git a/tests/notification/fixtures/submit_post_notification.type.bookmark.xml b/tests/notification/fixtures/submit_post_notification.type.bookmark.xml index 7f069abc59..db1cef2ef6 100644 --- a/tests/notification/fixtures/submit_post_notification.type.bookmark.xml +++ b/tests/notification/fixtures/submit_post_notification.type.bookmark.xml @@ -29,6 +29,7 @@ + notification_idnotification_type_iduser_iditem_id @@ -36,6 +37,7 @@ notification_readnotification_data + 1 1 5 1 diff --git a/tests/notification/fixtures/submit_post_notification.type.post.xml b/tests/notification/fixtures/submit_post_notification.type.post.xml index a4bf9d3ee4..920b271525 100644 --- a/tests/notification/fixtures/submit_post_notification.type.post.xml +++ b/tests/notification/fixtures/submit_post_notification.type.post.xml @@ -21,6 +21,7 @@
+ notification_idnotification_type_iduser_iditem_id @@ -28,6 +29,7 @@ notification_readnotification_data + 1 1 5 1 @@ -36,6 +38,7 @@ + 2 1 8 1 diff --git a/tests/notification/fixtures/submit_post_notification.type.post_in_queue.xml b/tests/notification/fixtures/submit_post_notification.type.post_in_queue.xml index 0a955c48d2..12e73b0ff2 100644 --- a/tests/notification/fixtures/submit_post_notification.type.post_in_queue.xml +++ b/tests/notification/fixtures/submit_post_notification.type.post_in_queue.xml @@ -1,6 +1,7 @@
+ notification_idnotification_type_iduser_iditem_id @@ -8,6 +9,7 @@ notification_readnotification_data + 1 1 6 1 diff --git a/tests/notification/fixtures/submit_post_notification.type.quote.xml b/tests/notification/fixtures/submit_post_notification.type.quote.xml index c66830fbf5..9f4ba91475 100644 --- a/tests/notification/fixtures/submit_post_notification.type.quote.xml +++ b/tests/notification/fixtures/submit_post_notification.type.quote.xml @@ -1,6 +1,7 @@
+ notification_idnotification_type_iduser_iditem_id @@ -8,6 +9,7 @@ notification_readnotification_data + 1 1 5 1 diff --git a/tests/notification/fixtures/submit_post_notification.type.topic.xml b/tests/notification/fixtures/submit_post_notification.type.topic.xml index e0f6583f48..1f96ed2ee7 100644 --- a/tests/notification/fixtures/submit_post_notification.type.topic.xml +++ b/tests/notification/fixtures/submit_post_notification.type.topic.xml @@ -21,6 +21,7 @@
+ notification_idnotification_type_iduser_iditem_id @@ -28,6 +29,7 @@ notification_readnotification_data + 1 1 8 1 diff --git a/tests/notification/notification_test.php b/tests/notification/notification_test.php index ec42aa193c..6bbabfc602 100644 --- a/tests/notification/notification_test.php +++ b/tests/notification/notification_test.php @@ -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'); 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( 'notification_type_id' => ($id + 1), 'notification_type_name' => $type, diff --git a/tests/search/fixtures/posts.xml b/tests/search/fixtures/posts.xml index 16232b8f39..4916cd188b 100644 --- a/tests/search/fixtures/posts.xml +++ b/tests/search/fixtures/posts.xml @@ -1,25 +1,30 @@
+ post_idpost_usernamepost_subjectpost_text + 1 foo foo foo + 2 bar bar bar + 3 commonword commonword commonword + 4 baaz baaz baaz diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index 670d39ed69..bbcb8d9a48 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -151,6 +151,11 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test $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 @@ -159,8 +164,15 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test $result = $db->sql_query($sql); $identity_columns = $db->sql_fetchrowset($result); $has_default_identity = false; + $add_primary_keys = false; 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; @@ -168,18 +180,22 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test } } - if ($has_default_identity) + if ($has_default_identity || $add_primary_keys) { - /** @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()); + 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); - $dataRow['mssqlindex'] = $i + 1; + if ($has_default_identity) + { + $dataRow['mssqlindex'] = $i + 1; + } $newTable->addRow($dataRow); } $newXmlData->addTable($newTable); From 27a24d0a677a3f1fb0dcf2393859eb37fe3bc0c3 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 25 Dec 2017 19:20:02 +0100 Subject: [PATCH 12/21] [ticket/15055] Try using build matrix PHPBB3-15055 --- .appveyor.yml | 26 ++++++++++++++++--- phpBB/phpbb/tree/nestedset.php | 2 +- ...phpbb_database_test_connection_manager.php | 8 ++++++ tests/tree/nestedset_forum_base.php | 10 +++++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index ef301584b7..9e5d687372 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -3,9 +3,23 @@ clone_folder: c:\projects\phpbb version: '{build}' services: - - mssql2014 - iis +environment: + matrix: + - db: mssql + db_version: sql2012sp1 + php: 7.1 + - db: mssql + db_version: sql2014 + php: 7.1 + - db: mssql + db_version: sql2016 + php: 7.1 + - db: mssql + db_version: sql2017 + php: 7.1 + hosts: phpbb.test: 127.0.0.1 @@ -16,7 +30,13 @@ init: before_test: - ps: Set-Service wuauserv -StartupType Manual - - sqlcmd -S "(local)\SQL2014" -Q "Use [master]; CREATE DATABASE [phpbb_test]" + - ps: | + $instanceName = $env:db_version.ToUpper() + Start-Service "MSSQL`$$instanceName" + Set-Variable -Name "sqlServerPath" -Value "(local)\$($env:db_version.ToUpper())" + Write-Host "$sqlServerPath" + Write-Host "$env:db_version --> $($env:db_version.ToUpper())" + sqlcmd -S $sqlServerPath -Q "Use [master]; CREATE DATABASE [phpbb_test] COLLATE Latin1_General_CI_AS" - SET PATH=C:\Program Files\OpenSSL;C:\tools\php;%PATH% - ps: Set-Service wuauserv -StartupType Manual - ps: cinst -y php --version ((choco search php --exact --all-versions -r | select-string -pattern 7.1 | sort { [version]($_ -split '\|' | select -last 1) } -Descending | Select-Object -first 1) -replace '[php|]','') @@ -49,7 +69,7 @@ before_test: - php ..\composer.phar install - cd c:\projects\phpbb\tests - touch test_config.php - - ps: $data = "db->sql_fetchrow($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 . ' diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index 147029d699..74170f2f35 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/tree/nestedset_forum_base.php b/tests/tree/nestedset_forum_base.php index 3daa75b2e4..62f3e0bcab 100644 --- a/tests/tree/nestedset_forum_base.php +++ b/tests/tree/nestedset_forum_base.php @@ -100,6 +100,11 @@ class phpbb_tests_tree_nestedset_forum_base extends phpbb_database_test_case } else { + 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->insert_all($forums); $buffer->flush(); @@ -107,6 +112,11 @@ class phpbb_tests_tree_nestedset_forum_base extends phpbb_database_test_case $this->database_synchronisation(array( 'phpbb_forums' => array('forum_id'), )); + if (strpos($this->db->sql_layer, 'mssql') !== false) + { + $sql = 'SET IDENTITY_INSERT phpbb_forums OFF'; + $this->db->sql_query($sql); + } } } From 6f6750b6294232e6cd11eb38d0cb8492d1e1245a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 27 Dec 2017 09:04:15 +0100 Subject: [PATCH 13/21] [ticket/15055] Specify utf8 as character set in sqlsrv_connect This is needed to be able to correctly retrieve unicode data from the db. PHPBB3-15055 --- phpBB/phpbb/db/driver/mssqlnative.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpBB/phpbb/db/driver/mssqlnative.php b/phpBB/phpbb/db/driver/mssqlnative.php index 50dce35baa..28bd3ceb42 100644 --- a/phpBB/phpbb/db/driver/mssqlnative.php +++ b/phpBB/phpbb/db/driver/mssqlnative.php @@ -50,7 +50,8 @@ class mssqlnative extends \phpbb\db\driver\mssql_base $this->db_connect_id = sqlsrv_connect($this->server, array( 'Database' => $this->dbname, 'UID' => $this->user, - 'PWD' => $sqlpassword + 'PWD' => $sqlpassword, + 'CharacterSet' => 'UTF-8' )); return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error(''); From 9883aa4930a5af4df1cfefeb1d82891d81460c9a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 30 Dec 2017 12:05:05 +0100 Subject: [PATCH 14/21] [ticket/15055] Run also on PHP 7.0 PHPBB3-15055 --- .appveyor.yml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 9e5d687372..d5c5203fbe 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -7,6 +7,9 @@ services: environment: matrix: + - db: mssql + db_version: sql2017 + php: 7.0 - db: mssql db_version: sql2012sp1 php: 7.1 @@ -39,8 +42,8 @@ before_test: sqlcmd -S $sqlServerPath -Q "Use [master]; CREATE DATABASE [phpbb_test] COLLATE Latin1_General_CI_AS" - SET PATH=C:\Program Files\OpenSSL;C:\tools\php;%PATH% - ps: Set-Service wuauserv -StartupType Manual - - ps: cinst -y php --version ((choco search php --exact --all-versions -r | select-string -pattern 7.1 | sort { [version]($_ -split '\|' | select -last 1) } -Descending | Select-Object -first 1) -replace '[php|]','') - - ps: Get-ChildItem -Path "c:\tools\php71" -Recurse | + - ps: 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|]','') + - ps: Get-ChildItem -Path "c:\tools\php$($env:php -replace '[.]','')" -Recurse | Move-Item -destination "c:\tools\php" - cd c:\tools\php - ps: cat php.ini-production | %{$_ -replace "memory_limit = 128M","memory_limit = 1024M"} | Out-File -Encoding "Default" php.ini @@ -56,10 +59,10 @@ before_test: - ps: | cd c:\tools\php\ext $DLLVersion = "4.1.6.1" - appveyor DownloadFile http://windows.php.net/downloads/pecl/releases/sqlsrv/$($:DLLVersion)/php_sqlsrv-$($DLLVersion)-7.1-nts-vc14-x64.zip - 7z x -y php_sqlsrv-$($DLLVersion)-7.1-nts-vc14-x64.zip > $null - appveyor-retry appveyor DownloadFile http://windows.php.net/downloads/pecl/releases/pdo_sqlsrv/$($DLLVersion)/php_pdo_sqlsrv-$($DLLVersion)-7.1-nts-vc14-x64.zip - 7z x -y php_pdo_sqlsrv-$($DLLVersion)-7.1-nts-vc14-x64.zip > $null + 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" From ede339c1c8b19fa01a61594d231902013ef473b0 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 30 Dec 2017 12:25:05 +0100 Subject: [PATCH 15/21] [ticket/15055] Extend build matrix and trim text in extension_acp_test PHPBB3-15055 --- .appveyor.yml | 126 +++++++++++++++--------- tests/functional/extension_acp_test.php | 2 +- 2 files changed, 83 insertions(+), 45 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index d5c5203fbe..fa2fd9fc20 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -8,75 +8,113 @@ services: environment: matrix: - db: mssql - db_version: sql2017 + db_version: sql2012sp1 php: 7.0 - - db: mssql - db_version: sql2012sp1 - php: 7.1 - db: mssql db_version: sql2014 - php: 7.1 + php: 7.0 - db: mssql db_version: sql2016 - php: 7.1 + 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=c:\php;%PATH% + - 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 - ps: | - $instanceName = $env:db_version.ToUpper() - Start-Service "MSSQL`$$instanceName" - Set-Variable -Name "sqlServerPath" -Value "(local)\$($env:db_version.ToUpper())" - Write-Host "$sqlServerPath" - Write-Host "$env:db_version --> $($env:db_version.ToUpper())" - sqlcmd -S $sqlServerPath -Q "Use [master]; CREATE DATABASE [phpbb_test] COLLATE Latin1_General_CI_AS" - - SET PATH=C:\Program Files\OpenSSL;C:\tools\php;%PATH% - - ps: Set-Service wuauserv -StartupType Manual - - ps: 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|]','') - - ps: Get-ChildItem -Path "c:\tools\php$($env:php -replace '[.]','')" -Recurse | + 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 - - ps: cat php.ini-production | %{$_ -replace "memory_limit = 128M","memory_limit = 1024M"} | Out-File -Encoding "Default" php.ini - - echo date.timezone="UTC" >> php.ini - - echo display_errors=On >> php.ini - - echo extension_dir=ext >> php.ini - - echo extension=php_openssl.dll >> php.ini - - echo extension=php_mbstring.dll >> php.ini - - echo extension=php_curl.dll >> php.ini - - echo extension=php_gd2.dll >> php.ini - - echo extension=php_tidy.dll >> php.ini - - echo extension=php_fileinfo.dll >> php.ini - - ps: | - 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" + 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 = "filter('dl')->count(); $i++) { - $text = $crawler->filter('dl')->eq($i)->text(); + $text = trim($crawler->filter('dl')->eq($i)->text()); $match = false; From a999718b42742c9911a24a74cf60f80e196d5cf8 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 31 Dec 2017 11:53:15 +0100 Subject: [PATCH 16/21] [ticket/15055] Support console questions on windows PHPBB3-15055 --- tests/console/user/add_test.php | 48 +++++++++++++++++++++++++++-- tests/console/user/base.php | 5 --- tests/dbal/db_tools_test.php | 4 --- tests/tree/nestedset_forum_base.php | 10 ++++-- 4 files changed, 52 insertions(+), 15 deletions(-) diff --git a/tests/console/user/add_test.php b/tests/console/user/add_test.php index 8641bf87b6..d1a1f8542e 100644 --- a/tests/console/user/add_test.php +++ b/tests/console/user/add_test.php @@ -14,12 +14,15 @@ use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; 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'; 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->add(new add( @@ -34,7 +37,42 @@ class phpbb_console_user_add_test extends phpbb_console_user_base $command = $application->find('user:add'); $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->createMock('\Symfony\Component\Console\Helper\QuestionHelper'); + $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); } @@ -57,7 +95,11 @@ class phpbb_console_user_add_test extends phpbb_console_user_base 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')); diff --git a/tests/console/user/base.php b/tests/console/user/base.php index 6e5436fb9d..b84c0bb267 100644 --- a/tests/console/user/base.php +++ b/tests/console/user/base.php @@ -34,11 +34,6 @@ abstract class phpbb_console_user_base extends phpbb_database_test_case { global $auth, $db, $cache, $config, $user, $phpbb_dispatcher, $phpbb_container, $phpbb_root_path, $phpEx; - if (strtolower(substr(PHP_OS, 0, 5)) !== 'linux') - { - $this->markTestSkipped('Unable to test console feature on OS other than Linux.'); - } - $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); $phpbb_container = new phpbb_mock_container_builder(); $phpbb_container->set('cache.driver', new phpbb_mock_cache()); diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index dbe2c2909a..72a3718662 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -462,10 +462,6 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case // Index name has > 30 chars - that should not be possible. $too_long_index_name = str_repeat('i', 31); $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', $too_long_index_name)); - if (strpos($this->tools->sql_layer, 'mssql') === false) - { - $this->setExpectedTriggerError(E_USER_ERROR); - } $this->tools->sql_create_index('prefix_table_name', $too_long_index_name, array('c_timestamp')); } } diff --git a/tests/tree/nestedset_forum_base.php b/tests/tree/nestedset_forum_base.php index 62f3e0bcab..498c6a69a2 100644 --- a/tests/tree/nestedset_forum_base.php +++ b/tests/tree/nestedset_forum_base.php @@ -69,7 +69,7 @@ class phpbb_tests_tree_nestedset_forum_base extends phpbb_database_test_case static $forums; if (empty($forums)) - { + { $this->create_forum('Parent with two flat children'); $this->create_forum('Flat child #1', 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 // This is required, so we can see whether the methods - // correctly clear the values. + // correctly clear the values. $sql = "UPDATE phpbb_forums SET forum_parents = 'a:0:{}'"; $this->db->sql_query($sql); @@ -100,6 +100,8 @@ class phpbb_tests_tree_nestedset_forum_base extends phpbb_database_test_case } 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'; @@ -112,12 +114,14 @@ class phpbb_tests_tree_nestedset_forum_base extends phpbb_database_test_case $this->database_synchronisation(array( '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) From d99ef034463ec94739026ca5154e597db77df8a9 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 31 Dec 2017 11:57:02 +0100 Subject: [PATCH 17/21] [ticket/15055] Run phantomjs for UI tests PHPBB3-15055 --- .appveyor.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.appveyor.yml b/.appveyor.yml index fa2fd9fc20..e536a561ff 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -110,6 +110,10 @@ before_test: sqlite3 c:\projects\test.db "create table aTable(field1 int); drop table aTable;" $data = " Date: Sun, 31 Dec 2017 14:00:36 +0100 Subject: [PATCH 18/21] [ticket/15055] Properly support index length check on mssql PHPBB3-15055 --- phpBB/phpbb/db/tools/mssql.php | 20 ++++++++++++++++---- phpBB/phpbb/db/tools/tools.php | 15 +++++++++++++-- tests/dbal/db_tools_test.php | 24 +++++++++++++++++------- 3 files changed, 46 insertions(+), 13 deletions(-) diff --git a/phpBB/phpbb/db/tools/mssql.php b/phpBB/phpbb/db/tools/mssql.php index 1e4d3aee2f..b84c0db403 100644 --- a/phpBB/phpbb/db/tools/mssql.php +++ b/phpBB/phpbb/db/tools/mssql.php @@ -545,10 +545,7 @@ class mssql extends tools { $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 $column = preg_replace('#:.*$#', '', $column); @@ -558,6 +555,21 @@ class mssql extends tools 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} */ diff --git a/phpBB/phpbb/db/tools/tools.php b/phpBB/phpbb/db/tools/tools.php index 2f891e43d5..d21d34b8a9 100644 --- a/phpBB/phpbb/db/tools/tools.php +++ b/phpBB/phpbb/db/tools/tools.php @@ -1561,7 +1561,8 @@ class tools implements tools_interface */ 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 $table_prefix = substr(CONFIG_TABLE, 0, -6); // strlen(config) @@ -1582,13 +1583,23 @@ class tools implements tools_interface 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; } + /** + * 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} */ diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index 72a3718662..0365463a48 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -439,29 +439,39 @@ 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.'); } + $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_name = $table_prefix . $table_suffix; $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 have <= 30 chars in total. - $long_index_name = str_repeat('i', 30 - strlen($table_suffix)); + // Index name and table suffix and table prefix have > maximum index length chars in total. + // Index name and table suffix have <= maximum index length chars in total. + $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->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)); - // Index name and table suffix have > 30 chars in total. - $very_long_index_name = str_repeat('i', 30); + // Index name and table suffix have > maximum index length chars in total. + $very_long_index_name = str_repeat('i', $max_index_length); $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_index_exists($table_name, $very_long_index_name)); $this->tools->sql_table_drop($table_name); - // Index name has > 30 chars - that should not be possible. - $too_long_index_name = str_repeat('i', 31); + // Index name has > maximum index length chars - that should not be possible. + $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->setExpectedTriggerError(E_USER_ERROR); $this->tools->sql_create_index('prefix_table_name', $too_long_index_name, array('c_timestamp')); } } From 4afb53dd8d4fb53ce49e0164130cf34712e19324 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 1 Jan 2018 18:00:51 +0100 Subject: [PATCH 19/21] [ticket/15055] Add comments explaining overriden createXMLDataSet() PHPBB3-15055 --- tests/test_framework/phpbb_database_test_case.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index bbcb8d9a48..c2d658cfff 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -142,9 +142,17 @@ 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(); @@ -165,6 +173,11 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test $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)) @@ -182,6 +195,7 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test if ($has_default_identity || $add_primary_keys) { + // Add default identity column to columns list if ($has_default_identity) { $columns[] = 'mssqlindex'; From 7b6be23117aae157d2bff7ca9cc3610320f368a1 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 1 Jan 2018 19:25:11 +0100 Subject: [PATCH 20/21] [ticket/15055] Use getMock() for phpBB 3.2 compatibility PHPBB3-15055 --- tests/console/user/add_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/console/user/add_test.php b/tests/console/user/add_test.php index d1a1f8542e..bdfb8a8d2a 100644 --- a/tests/console/user/add_test.php +++ b/tests/console/user/add_test.php @@ -61,7 +61,7 @@ class phpbb_console_user_add_test extends phpbb_console_user_base $output->writeln(print_r($response, true)); return $response; }; - $helper = $this->createMock('\Symfony\Component\Console\Helper\QuestionHelper'); + $helper = $this->getMock('\Symfony\Component\Console\Helper\QuestionHelper', array('ask')); $helper->expects($this->any()) ->method('ask') ->will($this->returnCallback($ask)); From 98c50695003652fba171e25dd2e171ddffbd72e1 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 5 Jan 2018 21:22:24 +0100 Subject: [PATCH 21/21] [ticket/15055] Display appveyor badges in readme PHPBB3-15055 --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b6c886d687..d1854dc74d 100644 --- a/README.md +++ b/README.md @@ -29,11 +29,11 @@ Read our [Vagrant documentation](phpBB/docs/vagrant.md) to find out how to use V ## 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://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://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=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://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://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