mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
Merge branch 'develop-olympus' into develop
* develop-olympus: (26 commits) [git-tools] add note about PHP_BIN using env [git-tools] do not display stderr [git-tools] Prepend the branch to the commit message for all branches. [git-tools] Use env to find the correct paths to binaries. [git-tools] Display what parse errors were found. [git-tools] This script requires bash to run, so point directly to bash. [feature/dbal-tests] Remove hardcoded 'mysql' from PDO DSN in DBAL test. [feature/dbal-tests] Fix mysql (not mysqli) dbal test. [feature/dbal-tests] Only output the missing config error message once. [feature/dbal-tests] Make the PDO prefix depend on the dbms. [feature/dbal-tests] Fix whitespace and line endings. [bug/9108] Fix table binding issues with PostgreSQL in board-wide feed. (Old Bug #58425) [bug/59425] Correctly check for double inclusion in captcha garbage collection [bug/58465] The redirect hidden field is now XHTML conform [feature/dbal-tests] Make some tests for build_array_data on SELECT [feature/dbal-tests] Make some tests for return_on_error on SELECT-queries [feature/dbal-tests] Tests for $db->sql_query_limit() [feature/dbal-tests] Load phpbb-schema after creating the connection to the database [feature/dbal-tests] Added tests for dbal fetchrow and fetchfield. [feature/dbal-tests] Added database test & refactored test framework ...
This commit is contained in:
commit
382354925d
16 changed files with 767 additions and 34 deletions
72
git-tools/hooks/pre-commit
Executable file
72
git-tools/hooks/pre-commit
Executable file
|
@ -0,0 +1,72 @@
|
||||||
|
#!/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
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# NOTE: this is run through /usr/bin/env
|
||||||
|
PHP_BIN=php
|
||||||
|
|
||||||
|
# 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
|
||||||
|
errors=""
|
||||||
|
|
||||||
|
IFS=$'\n'
|
||||||
|
# get a list of staged files
|
||||||
|
for line in $(git diff-index --cached --full-index $against)
|
||||||
|
do
|
||||||
|
# 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)
|
||||||
|
result=$(git cat-file -p $sha | /usr/bin/env $PHP_BIN -l 2>/dev/null)
|
||||||
|
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
|
|
@ -10,15 +10,25 @@
|
||||||
#
|
#
|
||||||
# ln -s ../../git-tools/hooks/prepare-commit-msg \\
|
# ln -s ../../git-tools/hooks/prepare-commit-msg \\
|
||||||
# .git/hooks/prepare-commit-msg
|
# .git/hooks/prepare-commit-msg
|
||||||
#
|
|
||||||
# Make sure it is executable.
|
|
||||||
|
|
||||||
# strip off ref: refs/heads/
|
# get branch name
|
||||||
branch="$(cat $GIT_DIR/HEAD | sed 's/ref: refs\/heads\///g')"
|
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;
|
# * only run when normal commit is made (without -m or -F;
|
||||||
# not a merge, etc.)
|
# not a merge, etc.)
|
||||||
# * also make sure the branch name begins with bug/ or feature/
|
# * also make sure the branch name begins with bug/ or feature/
|
||||||
if [ "$2" = "" ] && [ $(echo "$branch" | grep -e '^\(bug\|feature\)/') ]; then
|
if [ "$2" = "" ]
|
||||||
echo "[$branch] $(cat $1)" > "$1"
|
then
|
||||||
|
echo "[$branch] $(cat "$1")" > "$1"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -101,10 +101,14 @@
|
||||||
<li>[Fix] Minor language fixes. (Bug #54855)</li>
|
<li>[Fix] Minor language fixes. (Bug #54855)</li>
|
||||||
<li>[Fix] Parsing urls in signatures properly uses config settings. (Bug #57105)</li>
|
<li>[Fix] Parsing urls in signatures properly uses config settings. (Bug #57105)</li>
|
||||||
<li>[Fix] Allow multibyte keys in request_var(). (Bug #51555)</li>
|
<li>[Fix] Allow multibyte keys in request_var(). (Bug #51555)</li>
|
||||||
|
<li>[Fix] Fix inclusion check for captcha garbage collection (Bug #59425)</li>
|
||||||
<li>[Fix] Prevent wrong tar archive type detection. (Bug #12531)</li>
|
<li>[Fix] Prevent wrong tar archive type detection. (Bug #12531)</li>
|
||||||
<li>[Fix] Correct redirection after login to forum not in web root (Bug #58755)</li>
|
<li>[Fix] Correct redirection after login to forum not in web root (Bug #58755)</li>
|
||||||
<li>[Fix] Allow setting parent forums regardless of permission settings. (Bug #57415)</li>
|
<li>[Fix] Allow setting parent forums regardless of permission settings. (Bug #57415)</li>
|
||||||
<li>[Fix] Redirect search engines that access pages with SIDs in the URL. (Bug #58025)</li>
|
<li>[Fix] Redirect search engines that access pages with SIDs in the URL. (Bug #58025)</li>
|
||||||
|
<li>[Fix] Fix incorrect ampersand encoding in redirect parameter. (Bug #58465)</li>
|
||||||
|
<li>[Fix] Fix open_basedir issues when accessing styles- and language-management. (Bug #59135)</li>
|
||||||
|
<li>[Fix] Fix table binding issues with PostgreSQL in board-wide feed. (Bug #58425)</li>
|
||||||
<li>[Feature] Support for Microsoft's Native SQL Server Driver for PHP (Bug #57055 - Patch by Chris Pucci at Microsoft)</li>
|
<li>[Feature] Support for Microsoft's Native SQL Server Driver for PHP (Bug #57055 - Patch by Chris Pucci at Microsoft)</li>
|
||||||
<li>[Feature] The memcache acm plugin now supports multiple memcache servers.</li>
|
<li>[Feature] The memcache acm plugin now supports multiple memcache servers.</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -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, ' .
|
'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',
|
'u.username, u.user_id',
|
||||||
'FROM' => array(
|
'FROM' => array(
|
||||||
POSTS_TABLE => 'p',
|
|
||||||
USERS_TABLE => 'u',
|
USERS_TABLE => 'u',
|
||||||
|
POSTS_TABLE => 'p',
|
||||||
),
|
),
|
||||||
'LEFT_JOIN' => array(
|
'LEFT_JOIN' => array(
|
||||||
array(
|
array(
|
||||||
|
|
|
@ -1120,12 +1120,12 @@ class acp_language
|
||||||
{
|
{
|
||||||
while (($file = readdir($dp)) !== false)
|
while (($file = readdir($dp)) !== false)
|
||||||
{
|
{
|
||||||
if (!is_dir($phpbb_root_path . 'language/' . $file))
|
if ($file[0] == '.' || !is_dir($phpbb_root_path . 'language/' . $file))
|
||||||
{
|
{
|
||||||
continue;
|
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))
|
if (!in_array($file, $installed))
|
||||||
{
|
{
|
||||||
|
|
|
@ -643,13 +643,13 @@ parse_css_file = {PARSE_CSS_FILE}
|
||||||
{
|
{
|
||||||
while (($file = readdir($dp)) !== false)
|
while (($file = readdir($dp)) !== false)
|
||||||
{
|
{
|
||||||
if (!is_dir($phpbb_root_path . 'styles/' . $file))
|
if ($file[0] == '.' || !is_dir($phpbb_root_path . 'styles/' . $file))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$subpath = ($mode != 'style') ? "$mode/" : '';
|
$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"))
|
if ($cfg = file("{$phpbb_root_path}styles/$file/$subpath$mode.cfg"))
|
||||||
{
|
{
|
||||||
|
|
|
@ -4257,7 +4257,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0
|
||||||
'S_TOPIC_ID' => $topic_id,
|
'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_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' => ($config['feed_enable']) ? true : false,
|
||||||
'S_ENABLE_FEEDS_OVERALL' => ($config['feed_overall']) ? true : false,
|
'S_ENABLE_FEEDS_OVERALL' => ($config['feed_overall']) ? true : false,
|
||||||
|
|
|
@ -983,7 +983,7 @@ class session
|
||||||
}
|
}
|
||||||
|
|
||||||
// only called from CRON; should be a safe workaround until the infrastructure gets going
|
// 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);
|
include($phpbb_root_path . "includes/captcha/captcha_factory." . $phpEx);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ require_once 'security/all_tests.php';
|
||||||
require_once 'template/all_tests.php';
|
require_once 'template/all_tests.php';
|
||||||
#require_once 'bbcode/all_tests.php';
|
#require_once 'bbcode/all_tests.php';
|
||||||
require_once 'text_processing/all_tests.php';
|
require_once 'text_processing/all_tests.php';
|
||||||
|
require_once 'dbal/all_tests.php';
|
||||||
|
|
||||||
// exclude the test directory from code coverage reports
|
// exclude the test directory from code coverage reports
|
||||||
PHPUnit_Util_Filter::addDirectoryToFilter('./');
|
PHPUnit_Util_Filter::addDirectoryToFilter('./');
|
||||||
|
@ -42,6 +43,7 @@ class phpbb_all_tests
|
||||||
$suite->addTest(phpbb_template_all_tests::suite());
|
$suite->addTest(phpbb_template_all_tests::suite());
|
||||||
# $suite->addTest(phpbb_bbcode_all_tests::suite());
|
# $suite->addTest(phpbb_bbcode_all_tests::suite());
|
||||||
$suite->addTest(phpbb_text_processing_all_tests::suite());
|
$suite->addTest(phpbb_text_processing_all_tests::suite());
|
||||||
|
$suite->addTest(phpbb_dbal_all_tests::suite());
|
||||||
|
|
||||||
return $suite;
|
return $suite;
|
||||||
}
|
}
|
||||||
|
|
40
tests/dbal/all_tests.php
Normal file
40
tests/dbal/all_tests.php
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package testing
|
||||||
|
* @copyright (c) 2008 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!defined('PHPUnit_MAIN_METHOD'))
|
||||||
|
{
|
||||||
|
define('PHPUnit_MAIN_METHOD', 'phpbb_dbal_all_tests::main');
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once 'test_framework/framework.php';
|
||||||
|
require_once 'PHPUnit/TextUI/TestRunner.php';
|
||||||
|
|
||||||
|
require_once 'dbal/dbal.php';
|
||||||
|
|
||||||
|
class phpbb_dbal_all_tests
|
||||||
|
{
|
||||||
|
public static function main()
|
||||||
|
{
|
||||||
|
PHPUnit_TextUI_TestRunner::run(self::suite());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function suite()
|
||||||
|
{
|
||||||
|
$suite = new PHPUnit_Framework_TestSuite('phpBB Database Abstraction Layer');
|
||||||
|
|
||||||
|
$suite->addTestSuite('phpbb_dbal_test');
|
||||||
|
|
||||||
|
return $suite;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PHPUnit_MAIN_METHOD == 'phpbb_dbal_all_tests::main')
|
||||||
|
{
|
||||||
|
phpbb_dbal_all_tests::main();
|
||||||
|
}
|
328
tests/dbal/dbal.php
Normal file
328
tests/dbal/dbal.php
Normal file
|
@ -0,0 +1,328 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package testing
|
||||||
|
* @copyright (c) 2008 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once 'test_framework/framework.php';
|
||||||
|
require_once '../phpBB/includes/functions.php';
|
||||||
|
|
||||||
|
class phpbb_dbal_test extends phpbb_database_test_case
|
||||||
|
{
|
||||||
|
public function getDataSet()
|
||||||
|
{
|
||||||
|
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/three_users.xml');
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function return_on_error_select_data()
|
||||||
|
{
|
||||||
|
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),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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) ? ' WHERE ' . $where : '') . '
|
||||||
|
ORDER BY user_id ASC');
|
||||||
|
|
||||||
|
$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()
|
||||||
|
{
|
||||||
|
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 ASC', $total, $offset);
|
||||||
|
|
||||||
|
$ary = array();
|
||||||
|
while ($row = $db->sql_fetchrow($result))
|
||||||
|
{
|
||||||
|
$ary[] = $row;
|
||||||
|
}
|
||||||
|
$db->sql_freeresult($result);
|
||||||
|
|
||||||
|
$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, true, array()),
|
||||||
|
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),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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(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));
|
||||||
|
|
||||||
|
$db->sql_freeresult($result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
19
tests/dbal/fixtures/three_users.xml
Normal file
19
tests/dbal/fixtures/three_users.xml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<dataset>
|
||||||
|
<table name="phpbb_users">
|
||||||
|
<column>user_id</column>
|
||||||
|
<column>username_clean</column>
|
||||||
|
<row>
|
||||||
|
<value>1</value>
|
||||||
|
<value>barfoo</value>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<value>2</value>
|
||||||
|
<value>foobar</value>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<value>3</value>
|
||||||
|
<value>bertie</value>
|
||||||
|
</row>
|
||||||
|
</table>
|
||||||
|
</dataset>
|
|
@ -33,4 +33,7 @@ if (version_compare(PHPUnit_Runner_Version::id(), '3.3.0', '<'))
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once 'PHPUnit/Framework.php';
|
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_test_case.php';
|
||||||
|
require_once 'test_framework/phpbb_database_test_case.php';
|
||||||
|
|
168
tests/test_framework/phpbb_database_test_case.php
Normal file
168
tests/test_framework/phpbb_database_test_case.php
Normal file
|
@ -0,0 +1,168 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package testing
|
||||||
|
* @copyright (c) 2008 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_TestCase
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_dbms_data($dbms)
|
||||||
|
{
|
||||||
|
$available_dbms = array(
|
||||||
|
'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',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
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);
|
||||||
|
$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();
|
||||||
|
|
||||||
|
$dbms_data = $this->get_dbms_data($database_config['dbms']);
|
||||||
|
|
||||||
|
if ($already_connected)
|
||||||
|
{
|
||||||
|
$pdo = new PDO($dbms_data['PDO'] . ':host=' . $database_config['dbhost'] . ';dbname=' . $database_config['dbname'], $database_config['dbuser'], $database_config['dbpasswd']);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$pdo = new PDO($dbms_data['PDO'] . ':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($dbms_data['PDO'] . ':host=' . $database_config['dbhost'] . ';dbname=' . $database_config['dbname'], $database_config['dbuser'], $database_config['dbpasswd']);
|
||||||
|
|
||||||
|
if ($database_config['dbms'] == 'mysql')
|
||||||
|
{
|
||||||
|
$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';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$dbms_data['SCHEMA'] .= '_40';
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($row, $sth);
|
||||||
|
}
|
||||||
|
|
||||||
|
$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)
|
||||||
|
{
|
||||||
|
$pdo->exec($sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
$already_connected = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,29 +9,19 @@
|
||||||
|
|
||||||
class phpbb_test_case extends PHPUnit_Framework_TestCase
|
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 = '')
|
public function setExpectedTriggerError($errno, $message = '')
|
||||||
{
|
{
|
||||||
$exceptionName = '';
|
$this->init_test_case_helpers();
|
||||||
switch ($errno)
|
$this->test_case_helpers->setExpectedTriggerError($errno, $message);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
97
tests/test_framework/phpbb_test_case_helpers.php
Normal file
97
tests/test_framework/phpbb_test_case_helpers.php
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package testing
|
||||||
|
* @copyright (c) 2008 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class phpbb_test_case_helpers
|
||||||
|
{
|
||||||
|
protected $expectedTriggerError = false;
|
||||||
|
|
||||||
|
protected $test_case;
|
||||||
|
|
||||||
|
public function __construct($test_case)
|
||||||
|
{
|
||||||
|
$this->test_case = $test_case;
|
||||||
|
}
|
||||||
|
|
||||||
|
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:
|
||||||
|
\"<?php
|
||||||
|
\$dbms = 'mysqli';
|
||||||
|
\$dbhost = 'localhost';
|
||||||
|
\$dbport = '';
|
||||||
|
\$dbname = 'database';
|
||||||
|
\$dbuser = 'user';
|
||||||
|
\$dbpasswd = 'password';
|
||||||
|
\"
|
||||||
|
|
||||||
|
NOTE: The database is dropped and recreated with the phpbb-db-schema! Do NOT specify a database with important data.", E_USER_ERROR);
|
||||||
|
}
|
||||||
|
include('test_config.php');
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'dbms' => $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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue