From db8c557e4c6fee0a66c78863d4082dc17ff22d57 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 10 Mar 2010 20:07:10 +0100 Subject: [PATCH 01/26] [git-tools] pre-commit hook for syntax checking This pre-commit hook utilises PHP's command-line -l (lint) option, which checks for syntax errors. In case of an error the commit is rejected and the error displayed. Testing is welcome. --- git-tools/hooks/pre-commit | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 git-tools/hooks/pre-commit diff --git a/git-tools/hooks/pre-commit b/git-tools/hooks/pre-commit new file mode 100755 index 0000000000..4a070d130c --- /dev/null +++ b/git-tools/hooks/pre-commit @@ -0,0 +1,44 @@ +#!/bin/sh +# +# A hook to disallow php syntax errors to be committed +# by running php -l (lint) on them. It requires php-cli +# to be installed. +# +# This is a pre-commit hook. +# +# To install this you can either copy or symlink it to +# $GIT_DIR/hooks, example: +# +# ln -s ../../git-tools/hooks/pre-commit \\ +# .git/hooks/pre-commit + +# necessary check for initial commit +if git rev-parse --verify HEAD >/dev/null 2>&1 +then + against=HEAD +else + # Initial commit: diff against an empty tree object + against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 +fi + +error=0 + +# get a list of staged .php files, omitting file removals +IFS=" " +for file in $(git diff --cached --name-status $against | grep -v -E '^D' | cut -f2 | grep -E '\.php$') +do + # store lint result in a temp file + tempfile="/tmp/$(basename $0).$$.tmp" + if ! php -l "$file" >/dev/null 2>"$tempfile" + then + error=1 + cat "$tempfile" + fi + rm -f "$tempfile" +done +unset IFS + +if [ $error -eq 1 ] +then + exit 1 +fi From 6df10358aa7f9c544b188b51d6d1e8b3e66c8a28 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 10 Mar 2010 21:37:55 +0100 Subject: [PATCH 02/26] [git-tools] use mktemp in pre-commit (thanks nn-) --- git-tools/hooks/pre-commit | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/git-tools/hooks/pre-commit b/git-tools/hooks/pre-commit index 4a070d130c..937d2d2dc0 100755 --- a/git-tools/hooks/pre-commit +++ b/git-tools/hooks/pre-commit @@ -28,13 +28,12 @@ IFS=" " for file in $(git diff --cached --name-status $against | grep -v -E '^D' | cut -f2 | grep -E '\.php$') do # store lint result in a temp file - tempfile="/tmp/$(basename $0).$$.tmp" + tempfile=$(mktemp -t "$(basename $0).XXXXXX") if ! php -l "$file" >/dev/null 2>"$tempfile" then error=1 cat "$tempfile" fi - rm -f "$tempfile" done unset IFS From f9192bed79c2d5a0c1e8388bcdc35be3d21aa9a8 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Thu, 11 Mar 2010 19:44:21 +0100 Subject: [PATCH 03/26] [git-tools] Some pre-commit enhancements, abolish tempfile --- git-tools/hooks/pre-commit | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/git-tools/hooks/pre-commit b/git-tools/hooks/pre-commit index 937d2d2dc0..6129470196 100755 --- a/git-tools/hooks/pre-commit +++ b/git-tools/hooks/pre-commit @@ -12,6 +12,8 @@ # ln -s ../../git-tools/hooks/pre-commit \\ # .git/hooks/pre-commit +PHP_BIN=php + # necessary check for initial commit if git rev-parse --verify HEAD >/dev/null 2>&1 then @@ -27,12 +29,10 @@ error=0 IFS=" " for file in $(git diff --cached --name-status $against | grep -v -E '^D' | cut -f2 | grep -E '\.php$') do - # store lint result in a temp file - tempfile=$(mktemp -t "$(basename $0).XXXXXX") - if ! php -l "$file" >/dev/null 2>"$tempfile" + # hide output, but show errors + if ! $PHP_BIN -l "$file" >/dev/null then error=1 - cat "$tempfile" fi done unset IFS From 4349bec316e93ed6feac3ad7e56e54b6320aa960 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 13 Mar 2010 11:37:06 +0100 Subject: [PATCH 04/26] [bug/59135] Fix open_basedir issues when accessing styles- and language-management. (Bug #59135) introduced in r10496 and r10360/r10361 --- phpBB/docs/CHANGELOG.html | 1 + phpBB/includes/acp/acp_language.php | 4 ++-- phpBB/includes/acp/acp_styles.php | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/phpBB/docs/CHANGELOG.html b/phpBB/docs/CHANGELOG.html index 7b8d8f63f2..e6cefc15c4 100644 --- a/phpBB/docs/CHANGELOG.html +++ b/phpBB/docs/CHANGELOG.html @@ -103,6 +103,7 @@
  • [Fix] Allow multibyte keys in request_var(). (Bug #51555)
  • [Fix] Prevent wrong tar archive type detection. (Bug #12531)
  • [Fix] Correct redirection after login to forum not in web root (Bug #58755)
  • +
  • [Fix] Fix open_basedir issues when accessing styles- and language-management. (Bug #59135)
  • [Feature] Support for Microsoft's Native SQL Server Driver for PHP (Bug #57055 - Patch by Chris Pucci at Microsoft)
  • diff --git a/phpBB/includes/acp/acp_language.php b/phpBB/includes/acp/acp_language.php index fedae6fe67..c2cb2f9c11 100644 --- a/phpBB/includes/acp/acp_language.php +++ b/phpBB/includes/acp/acp_language.php @@ -1120,12 +1120,12 @@ class acp_language { while (($file = readdir($dp)) !== false) { - if (!is_dir($phpbb_root_path . 'language/' . $file)) + if ($file[0] == '.' || !is_dir($phpbb_root_path . 'language/' . $file)) { continue; } - if ($file[0] != '.' && file_exists("{$phpbb_root_path}language/$file/iso.txt")) + if (file_exists("{$phpbb_root_path}language/$file/iso.txt")) { if (!in_array($file, $installed)) { diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index d2a0f9210f..3310560c73 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -643,13 +643,13 @@ parse_css_file = {PARSE_CSS_FILE} { while (($file = readdir($dp)) !== false) { - if (!is_dir($phpbb_root_path . 'styles/' . $file)) + if ($file[0] == '.' || !is_dir($phpbb_root_path . 'styles/' . $file)) { continue; } $subpath = ($mode != 'style') ? "$mode/" : ''; - if ($file[0] != '.' && file_exists("{$phpbb_root_path}styles/$file/$subpath$mode.cfg")) + if (file_exists("{$phpbb_root_path}styles/$file/$subpath$mode.cfg")) { if ($cfg = file("{$phpbb_root_path}styles/$file/$subpath$mode.cfg")) { From 6a9304021f41cd8319ccb009bb24792ffc5438bc Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 13 Mar 2010 13:04:44 +0100 Subject: [PATCH 05/26] [git-tools] Improvements on prepare-commt-msg hook prepare-commit-hook now uses `git symbolic-ref HEAD` instead of reading $GIT_DIR/HEAD directly. This seems to be a more portable solution. Thanks to Chris (cs278/ToonArmy) for the suggestion. --- git-tools/hooks/prepare-commit-msg | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/git-tools/hooks/prepare-commit-msg b/git-tools/hooks/prepare-commit-msg index e1e05d67b8..354b539cc1 100755 --- a/git-tools/hooks/prepare-commit-msg +++ b/git-tools/hooks/prepare-commit-msg @@ -10,15 +10,25 @@ # # ln -s ../../git-tools/hooks/prepare-commit-msg \\ # .git/hooks/prepare-commit-msg -# -# Make sure it is executable. -# strip off ref: refs/heads/ -branch="$(cat $GIT_DIR/HEAD | sed 's/ref: refs\/heads\///g')" +# get branch name +branch="$(git symbolic-ref HEAD)" +# exit if no branch name is present +# (eg. detached HEAD) +if [ $? -ne 0 ] +then + exit +fi + +# strip off refs/heads/ +branch="$(echo "$branch" | sed "s/refs\/heads\///g")" + +# add [branchname] to commit message # * only run when normal commit is made (without -m or -F; # not a merge, etc.) # * also make sure the branch name begins with bug/ or feature/ -if [ "$2" = "" ] && [ $(echo "$branch" | grep -e '^\(bug\|feature\)/') ]; then - echo "[$branch] $(cat $1)" > "$1" +if [ "$2" = "" ] && [ $(echo "$branch" | grep -e "^\(bug\|feature\)/") ] +then + echo "[$branch] $(cat "$1")" > "$1" fi From ae48c8ee9ecf7866e4fe1ca4d3390d69a1adc2b4 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 17 Mar 2010 21:04:54 +0100 Subject: [PATCH 06/26] [git-tools] Improvements for the pre-commit hook One major issue with the pre-hook so far was partially staged files, because it used filenames for php lint. These changes will make the hook read the file contents from the index instead. Great thanks to David Soria Parra. --- git-tools/hooks/pre-commit | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/git-tools/hooks/pre-commit b/git-tools/hooks/pre-commit index 6129470196..1c67a0f3e3 100755 --- a/git-tools/hooks/pre-commit +++ b/git-tools/hooks/pre-commit @@ -25,12 +25,35 @@ fi error=0 -# get a list of staged .php files, omitting file removals -IFS=" " -for file in $(git diff --cached --name-status $against | grep -v -E '^D' | cut -f2 | grep -E '\.php$') +IFS=$'\n' +# get a list of staged files +for line in $(git diff-index --cached --full-index $against) do - # hide output, but show errors - if ! $PHP_BIN -l "$file" >/dev/null + # split needed values + sha=$(echo $line | cut -d' ' -f4) + temp=$(echo $line | cut -d' ' -f5) + status=$(echo $temp | cut -d' ' -f1) + filename=$(echo $temp | cut -d' ' -f2) + + # file extension + ext=$(echo $filename | sed 's/^.*\.//') + + # only check files with php extension + if [ $ext != "php" ] + then + continue + fi + + # do not check deleted files + if [ $status = "D" ] + then + continue + fi + + # check the staged file content for syntax errors + # using php -l (lint) + git cat-file -p $sha | $PHP_BIN -l >/dev/null + if [ $? -ne 0 ] then error=1 fi From 94bc65e2038407b8b6d2b23c195b232e07208d22 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 26 Mar 2010 16:39:37 +0100 Subject: [PATCH 07/26] [feature/dbal-tests] Added database test & refactored test framework There is now a phpbb_database_test_case which can be used as a base class for tests that require database access. You have to set up a test_config.php file in your tests/ directory containing host, user, pass etc. Extra test functionality has been moved to phpbb_test_case_helpers to provide the same functionality in database tests and regular tests without duplicating the code. This is achieved through delegation of method calls. --- tests/test_framework/framework.php | 3 + .../phpbb_database_test_case.php | 42 ++++++++++ tests/test_framework/phpbb_test_case.php | 32 +++----- .../phpbb_test_case_helpers.php | 82 +++++++++++++++++++ 4 files changed, 138 insertions(+), 21 deletions(-) create mode 100644 tests/test_framework/phpbb_database_test_case.php create mode 100644 tests/test_framework/phpbb_test_case_helpers.php diff --git a/tests/test_framework/framework.php b/tests/test_framework/framework.php index 5913d20ca0..abdcd1ad79 100644 --- a/tests/test_framework/framework.php +++ b/tests/test_framework/framework.php @@ -33,4 +33,7 @@ if (version_compare(PHPUnit_Runner_Version::id(), '3.3.0', '<')) } require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Extensions/Database/TestCase.php'; +require_once 'test_framework/phpbb_test_case_helpers.php'; require_once 'test_framework/phpbb_test_case.php'; +require_once 'test_framework/phpbb_database_test_case.php'; diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php new file mode 100644 index 0000000000..f0aa54ec8d --- /dev/null +++ b/tests/test_framework/phpbb_database_test_case.php @@ -0,0 +1,42 @@ +test_case_helpers) + { + $this->test_case_helpers = new phpbb_test_case_helpers($this); + } + } + + public function getConnection() + { + $this->init_test_case_helpers(); + $database_config = $this->test_case_helpers->get_database_config(); + + $pdo = new PDO('mysql:host=' . $database_config['dbhost'] . ';dbname=' . $database_config['dbname'], $database_config['dbuser'], $database_config['dbpasswd']); + return $this->createDefaultDBConnection($pdo, 'testdb'); + } + + public function new_dbal() + { + $this->init_test_case_helpers(); + return $this->test_case_helpers->new_dbal(); + } + + public function setExpectedTriggerError($errno, $message = '') + { + $this->init_test_case_helpers(); + $this->test_case_helpers->setExpectedTriggerError($errno, $message); + } +} diff --git a/tests/test_framework/phpbb_test_case.php b/tests/test_framework/phpbb_test_case.php index 3cf2a9d442..af867b29ff 100644 --- a/tests/test_framework/phpbb_test_case.php +++ b/tests/test_framework/phpbb_test_case.php @@ -9,29 +9,19 @@ class phpbb_test_case extends PHPUnit_Framework_TestCase { - protected $expectedTriggerError = false; + protected $test_case_helpers; + + public function init_test_case_helpers() + { + if (!$this->test_case_helpers) + { + $this->test_case_helpers = new phpbb_test_case_helpers($this); + } + } public function setExpectedTriggerError($errno, $message = '') { - $exceptionName = ''; - switch ($errno) - { - case E_NOTICE: - case E_STRICT: - PHPUnit_Framework_Error_Notice::$enabled = true; - $exceptionName = 'PHPUnit_Framework_Error_Notice'; - break; - - case E_WARNING: - PHPUnit_Framework_Error_Warning::$enabled = true; - $exceptionName = 'PHPUnit_Framework_Error_Warning'; - break; - - default: - $exceptionName = 'PHPUnit_Framework_Error'; - break; - } - $this->expectedTriggerError = true; - $this->setExpectedException($exceptionName, (string) $message, $errno); + $this->init_test_case_helpers(); + $this->test_case_helpers->setExpectedTriggerError($errno, $message); } } diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php new file mode 100644 index 0000000000..27a730e2dd --- /dev/null +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -0,0 +1,82 @@ +test_case = $test_case; + } + + public function get_database_config() + { + if (!file_exists('test_config.php')) + { + trigger_error("You have to create a test_config.php like this: + $dbms, + 'dbhost' => $dbhost, + 'dbport' => $dbport, + 'dbname' => $dbname, + 'dbuser' => $dbuser, + 'dbpasswd' => $dbpasswd, + ); + } + + public function new_dbal() + { + global $phpbb_root_path, $phpEx; + $config = $this->get_database_config(); + + require_once '../phpBB/includes/db/' . $config['dbms'] . '.php'; + $dbal = 'dbal_' . $config['dbms']; + $db = new $dbal(); + $db->sql_connect($config['dbhost'], $config['dbuser'], $config['dbpasswd'], $config['dbname'], $config['dbport']); + + return $db; + } + + public function setExpectedTriggerError($errno, $message = '') + { + $exceptionName = ''; + switch ($errno) + { + case E_NOTICE: + case E_STRICT: + PHPUnit_Framework_Error_Notice::$enabled = true; + $exceptionName = 'PHPUnit_Framework_Error_Notice'; + break; + + case E_WARNING: + PHPUnit_Framework_Error_Warning::$enabled = true; + $exceptionName = 'PHPUnit_Framework_Error_Warning'; + break; + + default: + $exceptionName = 'PHPUnit_Framework_Error'; + break; + } + $this->expectedTriggerError = true; + $this->test_case->setExpectedException($exceptionName, (string) $message, $errno); + } +} From af654814f63e05be5236075f06943062be007072 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 26 Mar 2010 16:41:19 +0100 Subject: [PATCH 08/26] [feature/dbal-tests] Added tests for dbal fetchrow and fetchfield. --- tests/all_tests.php | 2 ++ tests/dbal/all_tests.php | 40 ++++++++++++++++++++++++++++ tests/dbal/dbal.php | 43 +++++++++++++++++++++++++++++++ tests/dbal/fixtures/two_users.xml | 15 +++++++++++ 4 files changed, 100 insertions(+) create mode 100644 tests/dbal/all_tests.php create mode 100644 tests/dbal/dbal.php create mode 100644 tests/dbal/fixtures/two_users.xml diff --git a/tests/all_tests.php b/tests/all_tests.php index 1ed6126e80..e693427809 100644 --- a/tests/all_tests.php +++ b/tests/all_tests.php @@ -22,6 +22,7 @@ require_once 'request/all_tests.php'; require_once 'security/all_tests.php'; require_once 'template/all_tests.php'; require_once 'text_processing/all_tests.php'; +require_once 'dbal/all_tests.php'; // exclude the test directory from code coverage reports PHPUnit_Util_Filter::addDirectoryToFilter('./'); @@ -42,6 +43,7 @@ class phpbb_all_tests $suite->addTest(phpbb_security_all_tests::suite()); $suite->addTest(phpbb_template_all_tests::suite()); $suite->addTest(phpbb_text_processing_all_tests::suite()); + $suite->addTest(phpbb_dbal_all_tests::suite()); return $suite; } diff --git a/tests/dbal/all_tests.php b/tests/dbal/all_tests.php new file mode 100644 index 0000000000..7aee0f6b16 --- /dev/null +++ b/tests/dbal/all_tests.php @@ -0,0 +1,40 @@ +addTestSuite('phpbb_dbal_test'); + + return $suite; + } +} + +if (PHPUnit_MAIN_METHOD == 'phpbb_dbal_all_tests::main') +{ + phpbb_dbal_all_tests::main(); +} diff --git a/tests/dbal/dbal.php b/tests/dbal/dbal.php new file mode 100644 index 0000000000..a77279105f --- /dev/null +++ b/tests/dbal/dbal.php @@ -0,0 +1,43 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/two_users.xml'); + } + + public function test_select_row() + { + $db = $this->new_dbal(); + + $result = $db->sql_query('SELECT username_clean + FROM phpbb_users + WHERE user_id = 2'); + $row = $db->sql_fetchrow($result); + + $this->assertEquals(array('username_clean' => 'foobar'), $row); + } + + public function test_select_field() + { + $db = $this->new_dbal(); + + $result = $db->sql_query('SELECT username_clean + FROM phpbb_users + WHERE user_id = 2'); + + $this->assertEquals('foobar', $db->sql_fetchfield('username_clean')); + } +} + diff --git a/tests/dbal/fixtures/two_users.xml b/tests/dbal/fixtures/two_users.xml new file mode 100644 index 0000000000..255f061bd4 --- /dev/null +++ b/tests/dbal/fixtures/two_users.xml @@ -0,0 +1,15 @@ + + + + user_id + username_clean + + 1 + barfoo + + + 2 + foobar + +
    +
    From a7581085e002035ab5c516fe91fe4ece57087267 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 26 Mar 2010 17:37:01 +0100 Subject: [PATCH 09/26] [feature/dbal-tests] Load phpbb-schema after creating the connection to the database --- .../phpbb_database_test_case.php | 49 ++++++++++++++++++- .../phpbb_test_case_helpers.php | 7 ++- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index f0aa54ec8d..4f017f08d0 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -19,12 +19,59 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test } } + function split_sql_file($sql, $delimiter) + { + $sql = str_replace("\r" , '', $sql); + $data = preg_split('/' . preg_quote($delimiter, '/') . '$/m', $sql); + + $data = array_map('trim', $data); + + // The empty case + $end_data = end($data); + + if (empty($end_data)) + { + unset($data[key($data)]); + } + + return $data; + } + public function getConnection() { + static $already_connected; + $this->init_test_case_helpers(); $database_config = $this->test_case_helpers->get_database_config(); - $pdo = new PDO('mysql:host=' . $database_config['dbhost'] . ';dbname=' . $database_config['dbname'], $database_config['dbuser'], $database_config['dbpasswd']); + if ($already_connected) + { + $pdo = new PDO('mysql:host=' . $database_config['dbhost'] . ';dbname=' . $database_config['dbname'], $database_config['dbuser'], $database_config['dbpasswd']); + } + else + { + $pdo = new PDO('mysql:host=' . $database_config['dbhost'] . ';', $database_config['dbuser'], $database_config['dbpasswd']); + + try + { + $pdo->exec('DROP DATABASE ' . $database_config['dbname']); + } + catch (PDOException $e){} // ignore non existent db + + $pdo->exec('CREATE DATABASE ' . $database_config['dbname']); + + $pdo = new PDO('mysql:host=' . $database_config['dbhost'] . ';dbname=' . $database_config['dbname'], $database_config['dbuser'], $database_config['dbpasswd']); + + $sql_query = $this->split_sql_file(file_get_contents('../phpBB/install/schemas/mysql_41_schema.sql'), ';'); + + foreach ($sql_query as $sql) + { + $pdo->exec($sql); + } + + $already_connected = true; + } + return $this->createDefaultDBConnection($pdo, 'testdb'); } diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 27a730e2dd..f9ab750218 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -23,13 +23,16 @@ class phpbb_test_case_helpers if (!file_exists('test_config.php')) { trigger_error("You have to create a test_config.php like this: - Date: Fri, 26 Mar 2010 21:02:56 +0100 Subject: [PATCH 10/26] [feature/dbal-tests] Tests for $db->sql_query_limit() --- tests/dbal/dbal.php | 44 ++++++++++++++++++- .../{two_users.xml => three_users.xml} | 4 ++ 2 files changed, 47 insertions(+), 1 deletion(-) rename tests/dbal/fixtures/{two_users.xml => three_users.xml} (77%) diff --git a/tests/dbal/dbal.php b/tests/dbal/dbal.php index a77279105f..72e399adbe 100644 --- a/tests/dbal/dbal.php +++ b/tests/dbal/dbal.php @@ -14,7 +14,7 @@ class phpbb_dbal_test extends phpbb_database_test_case { public function getDataSet() { - return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/two_users.xml'); + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/three_users.xml'); } public function test_select_row() @@ -39,5 +39,47 @@ class phpbb_dbal_test extends phpbb_database_test_case $this->assertEquals('foobar', $db->sql_fetchfield('username_clean')); } + + public static function query_limit_data() + { + return array( + array(0, 0, array(array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar'), + array('username_clean' => 'bertie'))), + array(0, 1, array(array('username_clean' => 'foobar'), + array('username_clean' => 'bertie'))), + array(1, 0, array(array('username_clean' => 'barfoo'))), + array(1, 1, array(array('username_clean' => 'foobar'))), + array(1, 2, array(array('username_clean' => 'bertie'))), + array(2, 0, array(array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar'))), + array(2, 2, array(array('username_clean' => 'bertie'))), + array(2, 5, array()), + array(10, 1, array(array('username_clean' => 'foobar'), + array('username_clean' => 'bertie'))), + array(10, 5, array()), + ); + } + + /** + * @dataProvider query_limit_data + */ + public function test_query_limit($total, $offset, $expected) + { + $db = $this->new_dbal(); + + $result = $db->sql_query_limit('SELECT username_clean + FROM phpbb_users + ORDER BY user_id', $total, $offset); + + $ary = array(); + while ($row = $db->sql_fetchrow($result)) + { + $ary[] = $row; + } + $db->sql_freeresult($result); + + $this->assertEquals($expected, $ary); + } } diff --git a/tests/dbal/fixtures/two_users.xml b/tests/dbal/fixtures/three_users.xml similarity index 77% rename from tests/dbal/fixtures/two_users.xml rename to tests/dbal/fixtures/three_users.xml index 255f061bd4..fff26d2b3f 100644 --- a/tests/dbal/fixtures/two_users.xml +++ b/tests/dbal/fixtures/three_users.xml @@ -11,5 +11,9 @@ 2 foobar + + 3 + bertie + From 147d6fd590b0ff0bbed153fd33dcead494f822d0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 26 Mar 2010 22:33:54 +0100 Subject: [PATCH 11/26] [feature/dbal-tests] Make some tests for return_on_error on SELECT-queries --- tests/dbal/dbal.php | 226 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 213 insertions(+), 13 deletions(-) diff --git a/tests/dbal/dbal.php b/tests/dbal/dbal.php index 72e399adbe..0239f91a2d 100644 --- a/tests/dbal/dbal.php +++ b/tests/dbal/dbal.php @@ -17,27 +17,116 @@ class phpbb_dbal_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/three_users.xml'); } - public function test_select_row() + public static function return_on_error_select_data() { - $db = $this->new_dbal(); - - $result = $db->sql_query('SELECT username_clean - FROM phpbb_users - WHERE user_id = 2'); - $row = $db->sql_fetchrow($result); - - $this->assertEquals(array('username_clean' => 'foobar'), $row); + return array( + array('phpbb_users', "username_clean = 'bertie'", array(array('username_clean' => 'bertie'))), + array('phpbb_users', "username_clean = 'phpBB'", array()), + array('phpbb_users', 'username_clean syntax_error', false), + array('phpbb_users', 'column_not_exists = 2', false), + array('table_not_exists', 'column_not_exists = 2', false), + ); } - public function test_select_field() + /** + * @dataProvider return_on_error_select_data + */ + public function test_return_on_error_select($table, $where, $expected) + { + $db = $this->new_dbal(); + + $db->sql_return_on_error(true); + + $result = $db->sql_query('SELECT username_clean + FROM ' . $table . ' + WHERE ' . $where . ' + ORDER BY user_id ASC'); + + $db->sql_return_on_error(false); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public static function fetchrow_data() + { + return array( + array('', array(array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar'), + array('username_clean' => 'bertie'))), + array('user_id = 2', array(array('username_clean' => 'foobar'))), + array("username_clean = 'bertie'", array(array('username_clean' => 'bertie'))), + array("username_clean = 'phpBB'", array()), + ); + } + + /** + * @dataProvider fetchrow_data + */ + public function test_fetchrow($where, $expected) { $db = $this->new_dbal(); $result = $db->sql_query('SELECT username_clean FROM phpbb_users - WHERE user_id = 2'); + ' . (($where) ? ' WHERE ' . $where : '') . ' + ORDER BY user_id ASC'); - $this->assertEquals('foobar', $db->sql_fetchfield('username_clean')); + $ary = array(); + while ($row = $db->sql_fetchrow($result)) + { + $ary[] = $row; + } + $db->sql_freeresult($result); + + $this->assertEquals($expected, $ary); + } + + /** + * @dataProvider fetchrow_data + */ + public function test_fetchrowset($where, $expected) + { + $db = $this->new_dbal(); + + $result = $db->sql_query('SELECT username_clean + FROM phpbb_users + ' . (($where) ? ' WHERE ' . $where : '') . ' + ORDER BY user_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + + $db->sql_freeresult($result); + } + + public static function fetchfield_data() + { + return array( + array('', array('barfoo', 'foobar', 'bertie')), + array('user_id = 2', array('foobar')), + array("username_clean = 'bertie'", array('bertie')), + ); + } + + /** + * @dataProvider fetchfield_data + */ + public function test_fetchfield($where, $expected) + { + $db = $this->new_dbal(); + + $result = $db->sql_query('SELECT username_clean + FROM phpbb_users + ' . (($where) ? ' WHERE ' . $where : '') . ' + ORDER BY user_id ASC'); + + $ary = array(); + while ($row = $db->sql_fetchfield('username_clean')) + { + $ary[] = $row; + } + $db->sql_freeresult($result); + + $this->assertEquals($expected, $ary); } public static function query_limit_data() @@ -70,7 +159,7 @@ class phpbb_dbal_test extends phpbb_database_test_case $result = $db->sql_query_limit('SELECT username_clean FROM phpbb_users - ORDER BY user_id', $total, $offset); + ORDER BY user_id ASC', $total, $offset); $ary = array(); while ($row = $db->sql_fetchrow($result)) @@ -81,5 +170,116 @@ class phpbb_dbal_test extends phpbb_database_test_case $this->assertEquals($expected, $ary); } + + public static function like_expression_data() + { + // * = any_char; # = one_char + return array( + array('barfoo', array(array('username_clean' => 'barfoo'))), + array('bar', array()), + array('bar*', array(array('username_clean' => 'barfoo'))), + array('*bar*', array(array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar'))), + array('*b*', array(array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar'), + array('username_clean' => 'bertie'))), + array('b*r', array()), + array('b*e', array(array('username_clean' => 'bertie'))), + array('#b*e', array()), + array('b####e', array(array('username_clean' => 'bertie'))), + ); + } + + /** + * @dataProvider like_expression_data + */ + public function test_like_expression($like_expression, $expected) + { + $db = $this->new_dbal(); + + $like_expression = str_replace('*', $db->any_char, $like_expression); + $like_expression = str_replace('#', $db->one_char, $like_expression); + $where = ($like_expression) ? 'username_clean ' . $db->sql_like_expression($like_expression) : ''; + + $result = $db->sql_query('SELECT username_clean + FROM phpbb_users + ' . (($where) ? ' WHERE ' . $where : '') . ' + ORDER BY user_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + + $db->sql_freeresult($result); + } + + public static function in_set_data() + { + return array( + array('user_id', 3, false, false, array(array('username_clean' => 'bertie'))), + array('user_id', 3, false, true, array(array('username_clean' => 'bertie'))), + array('user_id', 3, true, false, array(array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar'))), + array('user_id', 3, true, true, array(array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar'))), + array('user_id', '3', false, false, array(array('username_clean' => 'bertie'))), + array('user_id', '3', false, true, array(array('username_clean' => 'bertie'))), + array('user_id', '3', true, false, array(array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar'))), + array('user_id', '3', true, true, array(array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar'))), + array('user_id', array(3), false, false, array(array('username_clean' => 'bertie'))), + array('user_id', array(3), false, true, array(array('username_clean' => 'bertie'))), + array('user_id', array(3), true, false, array(array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar'))), + array('user_id', array(3), true, true, array(array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar'))), + array('user_id', array(1, 3), false, false, array(array('username_clean' => 'barfoo'), + array('username_clean' => 'bertie'))), + array('user_id', array(1, 3), false, true, array(array('username_clean' => 'barfoo'), + array('username_clean' => 'bertie'))), + array('user_id', array(1, 3), true, false, array(array('username_clean' => 'foobar'))), + array('user_id', array(1, 3), true, true, array(array('username_clean' => 'foobar'))), + array('user_id', '', false, false, array()), + array('user_id', '', false, true, array()), + array('user_id', '', true, false, array(array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar'), + array('username_clean' => 'bertie'))), + array('user_id', '', true, true, array(array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar'), + array('username_clean' => 'bertie'))), + array('user_id', array(), false, false, false, true), + array('user_id', array(), false, true, array()), + array('user_id', array(), true, false, false, true), + array('user_id', array(), true, true, array(array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar'), + array('username_clean' => 'bertie'))), + ); + } + + /** + * @dataProvider in_set_data + */ + public function test_in_set($field, $array, $negate, $allow_empty_set, $expected, $catch_error = false) + { + $db = $this->new_dbal(); + + if ($catch_error) + { + $db->sql_return_on_error(true); + } + + $result = $db->sql_query('SELECT username_clean + FROM phpbb_users + WHERE ' . $db->sql_in_set($field, $array, $negate, $allow_empty_set) . ' + ORDER BY user_id ASC'); + + if ($catch_error) + { + $db->sql_return_on_error(falsee); + } + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + + $db->sql_freeresult($result); + } } From 53d316dc9ea34b1228591aa9cee766b2ec8abdc7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 27 Mar 2010 10:21:16 +0100 Subject: [PATCH 12/26] [feature/dbal-tests] Make some tests for build_array_data on SELECT --- tests/dbal/dbal.php | 49 ++++++++++++- .../phpbb_database_test_case.php | 69 ++++++++++++++++++- 2 files changed, 114 insertions(+), 4 deletions(-) diff --git a/tests/dbal/dbal.php b/tests/dbal/dbal.php index 0239f91a2d..f90b5efeb5 100644 --- a/tests/dbal/dbal.php +++ b/tests/dbal/dbal.php @@ -246,12 +246,14 @@ class phpbb_dbal_test extends phpbb_database_test_case array('user_id', '', true, true, array(array('username_clean' => 'barfoo'), array('username_clean' => 'foobar'), array('username_clean' => 'bertie'))), - array('user_id', array(), false, false, false, true), array('user_id', array(), false, true, array()), - array('user_id', array(), true, false, false, true), array('user_id', array(), true, true, array(array('username_clean' => 'barfoo'), array('username_clean' => 'foobar'), array('username_clean' => 'bertie'))), + + // These here would throw errors and therefor $result should be false. + array('user_id', array(), false, false, false, true), + array('user_id', array(), true, false, false, true), ); } @@ -274,7 +276,48 @@ class phpbb_dbal_test extends phpbb_database_test_case if ($catch_error) { - $db->sql_return_on_error(falsee); + $db->sql_return_on_error(false); + } + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + + $db->sql_freeresult($result); + } + + public static function build_array_data() + { + return array( + array(array('username_clean' => 'barfoo'), array(array('username_clean' => 'barfoo'))), + array(array('username_clean' => 'barfoo', 'user_id' => 1), array(array('username_clean' => 'barfoo'))), + array(array('username_clean' => 'barfoo', 'user_id' => 2), array()), + + // These here would throw errors and therefor $result should be false. + array(array(), false, true), + array('no_array', false, true), + array(0, false, true), + ); + } + + /** + * @dataProvider build_array_data + */ + public function test_build_array($assoc_ary, $expected, $catch_error = false) + { + $db = $this->new_dbal(); + + if ($catch_error) + { + $db->sql_return_on_error(true); + } + + $result = $db->sql_query('SELECT username_clean + FROM phpbb_users + WHERE ' . $db->sql_build_array('SELECT', $assoc_ary) . ' + ORDER BY user_id ASC'); + + if ($catch_error) + { + $db->sql_return_on_error(false); } $this->assertEquals($expected, $db->sql_fetchrowset($result)); diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index 4f017f08d0..547ee6404e 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -19,6 +19,57 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test } } + function get_dbms_data($dbms) + { + $available_dbms = array( + 'firebird' => array( + 'SCHEMA' => 'firebird', + 'DELIM' => ';;', + ), + 'mysqli' => array( + 'SCHEMA' => 'mysql_41', + 'DELIM' => ';', + ), + 'mysql' => array( + 'SCHEMA' => 'mysql', + 'DELIM' => ';', + ), + 'mssql' => array( + 'SCHEMA' => 'mssql', + 'DELIM' => 'GO', + ), + 'mssql_odbc'=> array( + 'SCHEMA' => 'mssql', + 'DELIM' => 'GO', + ), + 'mssqlnative' => array( + 'SCHEMA' => 'mssql', + 'DELIM' => 'GO', + ), + 'oracle' => array( + 'SCHEMA' => 'oracle', + 'DELIM' => '/', + ), + 'postgres' => array( + 'SCHEMA' => 'postgres', + 'DELIM' => ';', + ), + 'sqlite' => array( + 'SCHEMA' => 'sqlite', + 'DELIM' => ';', + ), + ); + + if (isset($available_dbms[$dbms])) + { + return $available_dbms[$dbms]; + } + else + { + trigger_error('Database unsupported', E_USER_ERROR); + } + } + function split_sql_file($sql, $delimiter) { $sql = str_replace("\r" , '', $sql); @@ -62,7 +113,23 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test $pdo = new PDO('mysql:host=' . $database_config['dbhost'] . ';dbname=' . $database_config['dbname'], $database_config['dbuser'], $database_config['dbpasswd']); - $sql_query = $this->split_sql_file(file_get_contents('../phpBB/install/schemas/mysql_41_schema.sql'), ';'); + $dbms_data = $this->get_dbms_data($database_config['dbms']); + if ($database_config['dbms'] == 'mysql') + { + $pdo->exec('SELECT VERSION() AS version'); + $row = $sth->fetch(PDO::FETCH_ASSOC); + if (version_compare($row['version'], '4.1.3', '>=')) + { + $dbms_data['SCHEMA'] .= '_41'; + } + else + { + $dbms_data['SCHEMA'] .= '_40'; + } + unset($row); + } + + $sql_query = $this->split_sql_file(file_get_contents("../phpBB/install/schemas/{$dbms_data['SCHEMA']}_schema.sql"), $dbms_data['DELIM']); foreach ($sql_query as $sql) { From 6cfb4c82dd4f81cade9b75fb730ebe8c2343b709 Mon Sep 17 00:00:00 2001 From: "U-H-PC\\H" Date: Sun, 28 Mar 2010 14:17:42 +0200 Subject: [PATCH 13/26] [bug/58465] The redirect hidden field is now XHTML conform The result of build_url was falsely un-entitized. --- phpBB/docs/CHANGELOG.html | 1 + phpBB/includes/functions.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/phpBB/docs/CHANGELOG.html b/phpBB/docs/CHANGELOG.html index 08f8be32fd..fabf2dad4f 100644 --- a/phpBB/docs/CHANGELOG.html +++ b/phpBB/docs/CHANGELOG.html @@ -105,6 +105,7 @@
  • [Fix] Correct redirection after login to forum not in web root (Bug #58755)
  • [Fix] Allow setting parent forums regardless of permission settings. (Bug #57415)
  • [Fix] Redirect search engines that access pages with SIDs in the URL. (Bug #58025)
  • +
  • [Fix] Fix incorrect ampersand encoding in redirect parameter. (Bug #58465)
  • [Feature] Support for Microsoft's Native SQL Server Driver for PHP (Bug #57055 - Patch by Chris Pucci at Microsoft)
  • [Feature] The memcache acm plugin now supports multiple memcache servers.
  • diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 5878c1977d..4f52c7c2ce 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4257,7 +4257,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'S_TOPIC_ID' => $topic_id, 'S_LOGIN_ACTION' => ((!defined('ADMIN_START')) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login') : append_sid("index.$phpEx", false, true, $user->session_id)), - 'S_LOGIN_REDIRECT' => build_hidden_fields(array('redirect' => str_replace('&', '&', build_url()))), + 'S_LOGIN_REDIRECT' => build_hidden_fields(array('redirect' => build_url())), 'S_ENABLE_FEEDS' => ($config['feed_enable']) ? true : false, 'S_ENABLE_FEEDS_OVERALL' => ($config['feed_overall']) ? true : false, From 9be61f9e53fef972e8f3b37186050814a9488790 Mon Sep 17 00:00:00 2001 From: "U-H-PC\\H" Date: Sun, 28 Mar 2010 14:37:31 +0200 Subject: [PATCH 14/26] [bug/59425] Correctly check for double inclusion in captcha garbage collection The check to avoid the double inclusion of the captcha factory class in the garbage collection code was faulty, checking for "captcha_factory" instead of "phpbb_captcha_factory". TerryE pointed the problem out, thanks! --- phpBB/docs/CHANGELOG.html | 1 + phpBB/includes/session.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/phpBB/docs/CHANGELOG.html b/phpBB/docs/CHANGELOG.html index 08f8be32fd..1cdbe310e8 100644 --- a/phpBB/docs/CHANGELOG.html +++ b/phpBB/docs/CHANGELOG.html @@ -101,6 +101,7 @@
  • [Fix] Minor language fixes. (Bug #54855)
  • [Fix] Parsing urls in signatures properly uses config settings. (Bug #57105)
  • [Fix] Allow multibyte keys in request_var(). (Bug #51555)
  • +
  • [Fix] Fix inclusion check for captcha garbage collection (Bug #59425)
  • [Fix] Prevent wrong tar archive type detection. (Bug #12531)
  • [Fix] Correct redirection after login to forum not in web root (Bug #58755)
  • [Fix] Allow setting parent forums regardless of permission settings. (Bug #57415)
  • diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php index 8beb0161f9..0a01b4e73b 100644 --- a/phpBB/includes/session.php +++ b/phpBB/includes/session.php @@ -983,7 +983,7 @@ class session } // only called from CRON; should be a safe workaround until the infrastructure gets going - if (!class_exists('captcha_factory')) + if (!class_exists('phpbb_captcha_factory')) { include($phpbb_root_path . "includes/captcha/captcha_factory." . $phpEx); } From 2b696cc632b917c4d49330966ddb1dee639a22fe Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 1 Apr 2010 13:11:18 +0200 Subject: [PATCH 15/26] [bug/9108] Fix table binding issues with PostgreSQL in board-wide feed. (Old Bug #58425) The order in the FROM clause is important. The posts table has to be the last one in the chain, so it can be correctly bound with the forums table in the LEFT JOIN. This only affects the overall feed (board-wide feed). All the other feeds are unaffected. --- phpBB/docs/CHANGELOG.html | 1 + phpBB/feed.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/phpBB/docs/CHANGELOG.html b/phpBB/docs/CHANGELOG.html index 5e6a0dbd86..e9b0f3804f 100644 --- a/phpBB/docs/CHANGELOG.html +++ b/phpBB/docs/CHANGELOG.html @@ -107,6 +107,7 @@
  • [Fix] Allow setting parent forums regardless of permission settings. (Bug #57415)
  • [Fix] Redirect search engines that access pages with SIDs in the URL. (Bug #58025)
  • [Fix] Fix incorrect ampersand encoding in redirect parameter. (Bug #58465)
  • +
  • [Fix] Fix table binding issues with PostgreSQL in board-wide feed. (Bug #58425)
  • [Feature] Support for Microsoft's Native SQL Server Driver for PHP (Bug #57055 - Patch by Chris Pucci at Microsoft)
  • [Feature] The memcache acm plugin now supports multiple memcache servers.
  • diff --git a/phpBB/feed.php b/phpBB/feed.php index a42aa42a7f..4ce983a967 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -783,8 +783,8 @@ class phpbb_feed_overall extends phpbb_feed_post_base 'p.post_id, p.topic_id, p.post_time, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' . 'u.username, u.user_id', 'FROM' => array( - POSTS_TABLE => 'p', USERS_TABLE => 'u', + POSTS_TABLE => 'p', ), 'LEFT_JOIN' => array( array( From 23beaceadd38f694ca2eea3110a20db48328e6ce Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 1 Apr 2010 18:59:26 +0200 Subject: [PATCH 16/26] [feature/dbal-tests] Fix whitespace and line endings. --- tests/dbal/fixtures/three_users.xml | 38 +++++++++---------- .../phpbb_database_test_case.php | 4 +- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/dbal/fixtures/three_users.xml b/tests/dbal/fixtures/three_users.xml index fff26d2b3f..a6789f4a01 100644 --- a/tests/dbal/fixtures/three_users.xml +++ b/tests/dbal/fixtures/three_users.xml @@ -1,19 +1,19 @@ - - - - user_id - username_clean - - 1 - barfoo - - - 2 - foobar - - - 3 - bertie - -
    -
    + + + + user_id + username_clean + + 1 + barfoo + + + 2 + foobar + + + 3 + bertie + +
    +
    diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index 547ee6404e..84635fc24d 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -45,7 +45,7 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test 'mssqlnative' => array( 'SCHEMA' => 'mssql', 'DELIM' => 'GO', - ), + ), 'oracle' => array( 'SCHEMA' => 'oracle', 'DELIM' => '/', @@ -108,7 +108,7 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test $pdo->exec('DROP DATABASE ' . $database_config['dbname']); } catch (PDOException $e){} // ignore non existent db - + $pdo->exec('CREATE DATABASE ' . $database_config['dbname']); $pdo = new PDO('mysql:host=' . $database_config['dbhost'] . ';dbname=' . $database_config['dbname'], $database_config['dbuser'], $database_config['dbpasswd']); From 53ab8886b1a3a98291627e2baab94ec86c7df685 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 1 Apr 2010 19:08:11 +0200 Subject: [PATCH 17/26] [feature/dbal-tests] Make the PDO prefix depend on the dbms. The database base test will need a few more changes to run on all the databases we support. But those really need to be made on a system where they run and can be tested. Patches welcome! --- .../test_framework/phpbb_database_test_case.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index 84635fc24d..a80f03b749 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -25,38 +25,47 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test 'firebird' => array( 'SCHEMA' => 'firebird', 'DELIM' => ';;', + 'PDO' => 'firebird', ), 'mysqli' => array( 'SCHEMA' => 'mysql_41', 'DELIM' => ';', + 'PDO' => 'mysql', ), 'mysql' => array( 'SCHEMA' => 'mysql', 'DELIM' => ';', + 'PDO' => 'mysql', ), 'mssql' => array( 'SCHEMA' => 'mssql', 'DELIM' => 'GO', + 'PDO' => 'odbc', ), 'mssql_odbc'=> array( 'SCHEMA' => 'mssql', 'DELIM' => 'GO', + 'PDO' => 'odbc', ), 'mssqlnative' => array( 'SCHEMA' => 'mssql', 'DELIM' => 'GO', + 'PDO' => 'odbc', ), 'oracle' => array( 'SCHEMA' => 'oracle', 'DELIM' => '/', + 'PDO' => 'oci', ), 'postgres' => array( 'SCHEMA' => 'postgres', 'DELIM' => ';', + 'PDO' => 'pgsql', ), 'sqlite' => array( 'SCHEMA' => 'sqlite', 'DELIM' => ';', + 'PDO' => 'sqlite', ), ); @@ -95,13 +104,15 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test $this->init_test_case_helpers(); $database_config = $this->test_case_helpers->get_database_config(); + $dbms_data = $this->get_dbms_data($database_config['dbms']); + if ($already_connected) { - $pdo = new PDO('mysql:host=' . $database_config['dbhost'] . ';dbname=' . $database_config['dbname'], $database_config['dbuser'], $database_config['dbpasswd']); + $pdo = new PDO($dbms_data['PDO'] . ':host=' . $database_config['dbhost'] . ';dbname=' . $database_config['dbname'], $database_config['dbuser'], $database_config['dbpasswd']); } else { - $pdo = new PDO('mysql:host=' . $database_config['dbhost'] . ';', $database_config['dbuser'], $database_config['dbpasswd']); + $pdo = new PDO($dbms_data['PDO'] . ':host=' . $database_config['dbhost'] . ';', $database_config['dbuser'], $database_config['dbpasswd']); try { @@ -113,7 +124,6 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test $pdo = new PDO('mysql:host=' . $database_config['dbhost'] . ';dbname=' . $database_config['dbname'], $database_config['dbuser'], $database_config['dbpasswd']); - $dbms_data = $this->get_dbms_data($database_config['dbms']); if ($database_config['dbms'] == 'mysql') { $pdo->exec('SELECT VERSION() AS version'); From 2bbfa9c29f4ce33d25e58c550540e236a4ee3c1a Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 1 Apr 2010 19:15:34 +0200 Subject: [PATCH 18/26] [feature/dbal-tests] Only output the missing config error message once. The error message was also not properly escaping the variables, thus producing an incorrect example configuration file. --- .../phpbb_test_case_helpers.php | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index f9ab750218..0c5932e1ad 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -20,16 +20,28 @@ class phpbb_test_case_helpers public function get_database_config() { + static $show_error = true; + if (!file_exists('test_config.php')) { + if ($show_error) + { + $show_error = false; + } + else + { + $this->test_case->markTestSkipped('Missing test_config.php: See first error.'); + return; + } + trigger_error("You have to create a test_config.php like this: \" Date: Fri, 2 Apr 2010 00:35:48 +0200 Subject: [PATCH 19/26] [feature/dbal-tests] Fix mysql (not mysqli) dbal test. Correctly determine MySQL version from the database. --- tests/test_framework/phpbb_database_test_case.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index a80f03b749..d2ebe4c30e 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -126,8 +126,9 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test if ($database_config['dbms'] == 'mysql') { - $pdo->exec('SELECT VERSION() AS version'); + $sth = $pdo->query('SELECT VERSION() AS version'); $row = $sth->fetch(PDO::FETCH_ASSOC); + if (version_compare($row['version'], '4.1.3', '>=')) { $dbms_data['SCHEMA'] .= '_41'; @@ -136,7 +137,8 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test { $dbms_data['SCHEMA'] .= '_40'; } - unset($row); + + unset($row, $sth); } $sql_query = $this->split_sql_file(file_get_contents("../phpBB/install/schemas/{$dbms_data['SCHEMA']}_schema.sql"), $dbms_data['DELIM']); From 4a2a84d7a2d024c8ada93a7b23a8ef01141656b8 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 2 Apr 2010 00:40:49 +0200 Subject: [PATCH 20/26] [feature/dbal-tests] Remove hardcoded 'mysql' from PDO DSN in DBAL test. --- tests/test_framework/phpbb_database_test_case.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index d2ebe4c30e..d558874c6f 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -122,7 +122,7 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test $pdo->exec('CREATE DATABASE ' . $database_config['dbname']); - $pdo = new PDO('mysql:host=' . $database_config['dbhost'] . ';dbname=' . $database_config['dbname'], $database_config['dbuser'], $database_config['dbpasswd']); + $pdo = new PDO($dbms_data['PDO'] . ':host=' . $database_config['dbhost'] . ';dbname=' . $database_config['dbname'], $database_config['dbuser'], $database_config['dbpasswd']); if ($database_config['dbms'] == 'mysql') { From a06ec8c7fd3313acb9a69de6ac51f4486b5f79a3 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Sat, 3 Apr 2010 01:51:37 +0100 Subject: [PATCH 21/26] [git-tools] This script requires bash to run, so point directly to bash. --- git-tools/hooks/pre-commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-tools/hooks/pre-commit b/git-tools/hooks/pre-commit index 1c67a0f3e3..929789e312 100755 --- a/git-tools/hooks/pre-commit +++ b/git-tools/hooks/pre-commit @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # A hook to disallow php syntax errors to be committed # by running php -l (lint) on them. It requires php-cli From 5568b2134bfc8aa477d92e573d8a7d3d13264b44 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Sat, 3 Apr 2010 01:53:12 +0100 Subject: [PATCH 22/26] [git-tools] Display what parse errors were found. --- git-tools/hooks/pre-commit | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/git-tools/hooks/pre-commit b/git-tools/hooks/pre-commit index 929789e312..a7deea43c5 100755 --- a/git-tools/hooks/pre-commit +++ b/git-tools/hooks/pre-commit @@ -24,6 +24,7 @@ else fi error=0 +errors="" IFS=$'\n' # get a list of staged files @@ -52,15 +53,19 @@ do # check the staged file content for syntax errors # using php -l (lint) - git cat-file -p $sha | $PHP_BIN -l >/dev/null + result=$(git cat-file -p $sha | $PHP_BIN -l) if [ $? -ne 0 ] then error=1 + # Swap back in correct filenames + errors+=${result//in - on/"$filename"} fi done unset IFS if [ $error -eq 1 ] then + echo -e "PHP Syntax check failed:"; + echo -e "$errors" | grep "^Parse error:" exit 1 fi From b6920b7ca8a6859bf9f76247b882dbd9331a9c78 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Sat, 3 Apr 2010 02:12:21 +0100 Subject: [PATCH 23/26] [git-tools] Use env to find the correct paths to binaries. --- git-tools/hooks/pre-commit | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-tools/hooks/pre-commit b/git-tools/hooks/pre-commit index a7deea43c5..151c604c30 100755 --- a/git-tools/hooks/pre-commit +++ b/git-tools/hooks/pre-commit @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # A hook to disallow php syntax errors to be committed # by running php -l (lint) on them. It requires php-cli @@ -53,7 +53,7 @@ do # check the staged file content for syntax errors # using php -l (lint) - result=$(git cat-file -p $sha | $PHP_BIN -l) + result=$(git cat-file -p $sha | /usr/bin/env $PHP_BIN -l) if [ $? -ne 0 ] then error=1 From 3e5236dcd62f1d0b18cd3c92661a2287b5bbf2d6 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Sat, 3 Apr 2010 02:13:48 +0100 Subject: [PATCH 24/26] [git-tools] Prepend the branch to the commit message for all branches. --- git-tools/hooks/prepare-commit-msg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-tools/hooks/prepare-commit-msg b/git-tools/hooks/prepare-commit-msg index 354b539cc1..033cb187c7 100755 --- a/git-tools/hooks/prepare-commit-msg +++ b/git-tools/hooks/prepare-commit-msg @@ -28,7 +28,7 @@ branch="$(echo "$branch" | sed "s/refs\/heads\///g")" # * only run when normal commit is made (without -m or -F; # not a merge, etc.) # * also make sure the branch name begins with bug/ or feature/ -if [ "$2" = "" ] && [ $(echo "$branch" | grep -e "^\(bug\|feature\)/") ] +if [ "$2" = "" ] then echo "[$branch] $(cat "$1")" > "$1" fi From 8091e3166630c70310908668c4d35d1d8d948e0f Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 3 Apr 2010 21:53:09 +0200 Subject: [PATCH 25/26] [git-tools] do not display stderr --- git-tools/hooks/pre-commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-tools/hooks/pre-commit b/git-tools/hooks/pre-commit index 151c604c30..c8d78ed490 100755 --- a/git-tools/hooks/pre-commit +++ b/git-tools/hooks/pre-commit @@ -53,7 +53,7 @@ do # check the staged file content for syntax errors # using php -l (lint) - result=$(git cat-file -p $sha | /usr/bin/env $PHP_BIN -l) + result=$(git cat-file -p $sha | /usr/bin/env $PHP_BIN -l 2>/dev/null) if [ $? -ne 0 ] then error=1 From 11de6a46b10c5bdb77b2ee7f9e970b849e0f4d74 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 3 Apr 2010 22:06:25 +0200 Subject: [PATCH 26/26] [git-tools] add note about PHP_BIN using env --- git-tools/hooks/pre-commit | 1 + 1 file changed, 1 insertion(+) diff --git a/git-tools/hooks/pre-commit b/git-tools/hooks/pre-commit index c8d78ed490..23ab8d6cdb 100755 --- a/git-tools/hooks/pre-commit +++ b/git-tools/hooks/pre-commit @@ -12,6 +12,7 @@ # ln -s ../../git-tools/hooks/pre-commit \\ # .git/hooks/pre-commit +# NOTE: this is run through /usr/bin/env PHP_BIN=php # necessary check for initial commit