2010-03-26 16:39:37 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @package testing
|
|
|
|
* @copyright (c) 2008 phpBB Group
|
2011-12-31 16:05:02 +00:00
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
2010-03-26 16:39:37 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
class phpbb_test_case_helpers
|
|
|
|
{
|
|
|
|
protected $expectedTriggerError = false;
|
|
|
|
|
|
|
|
protected $test_case;
|
|
|
|
|
|
|
|
public function __construct($test_case)
|
|
|
|
{
|
|
|
|
$this->test_case = $test_case;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2012-04-20 23:50:49 -05:00
|
|
|
|
|
|
|
static public function get_test_config()
|
|
|
|
{
|
|
|
|
$config = array();
|
|
|
|
|
|
|
|
if (extension_loaded('sqlite') && version_compare(PHPUnit_Runner_Version::id(), '3.4.15', '>='))
|
|
|
|
{
|
|
|
|
$config = array_merge($config, array(
|
|
|
|
'dbms' => 'sqlite',
|
|
|
|
'dbhost' => dirname(__FILE__) . '/../phpbb_unit_tests.sqlite2', // filename
|
|
|
|
'dbport' => '',
|
|
|
|
'dbname' => '',
|
|
|
|
'dbuser' => '',
|
|
|
|
'dbpasswd' => '',
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2012-05-11 22:24:01 -04:00
|
|
|
if (isset($_SERVER['PHPBB_TEST_CONFIG']))
|
2012-04-20 23:50:49 -05:00
|
|
|
{
|
2012-05-11 22:24:01 -04:00
|
|
|
// Could be an absolute path
|
|
|
|
$test_config = $_SERVER['PHPBB_TEST_CONFIG'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$test_config = dirname(__FILE__) . '/../test_config.php';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (file_exists($test_config))
|
|
|
|
{
|
|
|
|
include($test_config);
|
2012-04-20 23:50:49 -05:00
|
|
|
|
|
|
|
$config = array_merge($config, array(
|
|
|
|
'dbms' => $dbms,
|
|
|
|
'dbhost' => $dbhost,
|
|
|
|
'dbport' => $dbport,
|
|
|
|
'dbname' => $dbname,
|
|
|
|
'dbuser' => $dbuser,
|
|
|
|
'dbpasswd' => $dbpasswd,
|
2012-05-08 04:34:19 -05:00
|
|
|
'custom_dsn' => isset($custom_dsn) ? $custom_dsn : '',
|
2012-04-20 23:50:49 -05:00
|
|
|
));
|
2012-04-21 04:37:57 -05:00
|
|
|
|
|
|
|
if (isset($phpbb_functional_url))
|
|
|
|
{
|
|
|
|
$config['phpbb_functional_url'] = $phpbb_functional_url;
|
|
|
|
}
|
2012-04-20 23:50:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($_SERVER['PHPBB_TEST_DBMS']))
|
|
|
|
{
|
|
|
|
$config = array_merge($config, array(
|
|
|
|
'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? $_SERVER['PHPBB_TEST_DBMS'] : '',
|
|
|
|
'dbhost' => isset($_SERVER['PHPBB_TEST_DBHOST']) ? $_SERVER['PHPBB_TEST_DBHOST'] : '',
|
|
|
|
'dbport' => isset($_SERVER['PHPBB_TEST_DBPORT']) ? $_SERVER['PHPBB_TEST_DBPORT'] : '',
|
|
|
|
'dbname' => isset($_SERVER['PHPBB_TEST_DBNAME']) ? $_SERVER['PHPBB_TEST_DBNAME'] : '',
|
|
|
|
'dbuser' => isset($_SERVER['PHPBB_TEST_DBUSER']) ? $_SERVER['PHPBB_TEST_DBUSER'] : '',
|
2012-05-08 04:34:19 -05:00
|
|
|
'dbpasswd' => isset($_SERVER['PHPBB_TEST_DBPASSWD']) ? $_SERVER['PHPBB_TEST_DBPASSWD'] : '',
|
|
|
|
'custom_dsn' => isset($_SERVER['PHPBB_TEST_CUSTOM_DSN']) ? $_SERVER['PHPBB_TEST_CUSTOM_DSN'] : '',
|
2012-04-20 23:50:49 -05:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2012-04-21 04:37:57 -05:00
|
|
|
if (isset($_SERVER['PHPBB_FUNCTIONAL_URL']))
|
|
|
|
{
|
|
|
|
$config = array_merge($config, array(
|
|
|
|
'phpbb_functional_url' => isset($_SERVER['PHPBB_FUNCTIONAL_URL']) ? $_SERVER['PHPBB_FUNCTIONAL_URL'] : '',
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2012-04-20 23:50:49 -05:00
|
|
|
return $config;
|
|
|
|
}
|
2010-03-26 16:39:37 +01:00
|
|
|
}
|