begin supporting a different database for unit tests
This commit is contained in:
parent
e118a7d97b
commit
ef23f01eba
4 changed files with 19 additions and 11 deletions
|
@ -14,7 +14,7 @@
|
||||||
* @link http://sourceforge.net/projects/semanticscuttle
|
* @link http://sourceforge.net/projects/semanticscuttle
|
||||||
*/
|
*/
|
||||||
$_SERVER['HTTP_HOST'] = 'http://localhost/';
|
$_SERVER['HTTP_HOST'] = 'http://localhost/';
|
||||||
define('UNIT_TEST_MODE', true);
|
//define('UNIT_TEST_MODE', true);
|
||||||
|
|
||||||
require_once dirname(__FILE__) . '/header.php';
|
require_once dirname(__FILE__) . '/header.php';
|
||||||
?>
|
?>
|
|
@ -46,14 +46,21 @@ if (isset($_GET['unittestMode']) && $_GET['unittestMode'] == 1
|
||||||
die("Unittestmode is not allowed\n");
|
die("Unittestmode is not allowed\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
$unittestConfigFile = $datadir . '/config.unittest.php';
|
|
||||||
if (file_exists($unittestConfigFile)) {
|
|
||||||
require_once $unittestConfigFile;
|
|
||||||
}
|
|
||||||
define('HTTP_UNIT_TEST_MODE', true);
|
define('HTTP_UNIT_TEST_MODE', true);
|
||||||
define('UNIT_TEST_MODE', true);
|
define('UNIT_TEST_MODE', true);
|
||||||
}
|
}
|
||||||
if (defined('UNIT_TEST_MODE')) {
|
if (defined('UNIT_TEST_MODE')) {
|
||||||
|
//load configuration for unit tests
|
||||||
|
$testingConfigFile = $datadir . '/config.testing.php';
|
||||||
|
if (file_exists($testingConfigFile)) {
|
||||||
|
require_once $testingConfigFile;
|
||||||
|
}
|
||||||
|
//test-specific configuration file
|
||||||
|
$unittestConfigFile = $datadir . '/config.testing-tmp.php';
|
||||||
|
if (file_exists($unittestConfigFile)) {
|
||||||
|
require_once $unittestConfigFile;
|
||||||
|
}
|
||||||
|
|
||||||
//make local config vars global - needed for unit tests
|
//make local config vars global - needed for unit tests
|
||||||
//run with phpunit
|
//run with phpunit
|
||||||
foreach (get_defined_vars() as $var => $value) {
|
foreach (get_defined_vars() as $var => $value) {
|
||||||
|
@ -107,7 +114,7 @@ T_bind_textdomain_codeset($domain, 'UTF-8');
|
||||||
T_textdomain($domain);
|
T_textdomain($domain);
|
||||||
|
|
||||||
// 4 // Session
|
// 4 // Session
|
||||||
if (!defined('UNIT_TEST_MODE') || defined('HTTP_UNIT_TEST_MODE')) {
|
if (isset($_SERVER['REMOTE_ADDR'])) {
|
||||||
session_start();
|
session_start();
|
||||||
if ($GLOBALS['enableVoting']) {
|
if ($GLOBALS['enableVoting']) {
|
||||||
if (isset($_SESSION['lastUrl'])) {
|
if (isset($_SESSION['lastUrl'])) {
|
||||||
|
|
|
@ -50,8 +50,9 @@ class TestBaseApi extends TestBase
|
||||||
$this->url = $GLOBALS['unittestUrl'] . $this->urlPart;
|
$this->url = $GLOBALS['unittestUrl'] . $this->urlPart;
|
||||||
|
|
||||||
//clean up before test
|
//clean up before test
|
||||||
if (file_exists($GLOBALS['datadir'] . '/config.unittest.php')) {
|
$configFile = $GLOBALS['datadir'] . '/config.testing-tmp.php';
|
||||||
unlink($GLOBALS['datadir'] . '/config.unittest.php');
|
if (file_exists($configFile)) {
|
||||||
|
unlink($configFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->us = SemanticScuttle_Service_Factory::get('User');
|
$this->us = SemanticScuttle_Service_Factory::get('User');
|
||||||
|
@ -230,7 +231,7 @@ class TestBaseApi extends TestBase
|
||||||
|
|
||||||
$this->assertInternalType(
|
$this->assertInternalType(
|
||||||
'integer',
|
'integer',
|
||||||
file_put_contents($GLOBALS['datadir'] . '/config.unittest.php', $str),
|
file_put_contents($GLOBALS['datadir'] . '/config.testing-tmp.php', $str),
|
||||||
'Writing config.unittest.php failed'
|
'Writing config.unittest.php failed'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ $_SERVER['HTTP_HOST'] = 'http://localhost/';
|
||||||
define('UNIT_TEST_MODE', true);
|
define('UNIT_TEST_MODE', true);
|
||||||
|
|
||||||
if ('@data_dir@' == '@' . 'data_dir@') {
|
if ('@data_dir@' == '@' . 'data_dir@') {
|
||||||
//non pear-install
|
//non pear-installation (i.e. git checkout)
|
||||||
require_once dirname(__FILE__) . '/../src/SemanticScuttle/header.php';
|
require_once dirname(__FILE__) . '/../src/SemanticScuttle/header.php';
|
||||||
} else {
|
} else {
|
||||||
//pear installation; files are in include path
|
//pear installation; files are in include path
|
||||||
|
@ -35,7 +35,7 @@ if ($GLOBALS['debugMode'] == true
|
||||||
&& $GLOBALS['dbtype'] == 'mysql4'
|
&& $GLOBALS['dbtype'] == 'mysql4'
|
||||||
) {
|
) {
|
||||||
echo "\n"
|
echo "\n"
|
||||||
. '!!! The combination of debugMode and dbtype==mysql4'
|
. '!! The combination of debugMode and dbtype==mysql4'
|
||||||
. ' will wreck some tests' . "\n\n";
|
. ' will wreck some tests' . "\n\n";
|
||||||
}
|
}
|
||||||
?>
|
?>
|
Loading…
Reference in a new issue