From 894011dd0fb4ba0aeee428d3460665afb71cd9d9 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Sat, 9 Oct 2010 12:14:34 +0200 Subject: make the short date a valid ISO date format. --- data/config.default.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'data/config.default.php') diff --git a/data/config.default.php b/data/config.default.php index bd67c7b..3d60b91 100644 --- a/data/config.default.php +++ b/data/config.default.php @@ -327,7 +327,7 @@ $index_sidebar_blocks = array( * @var string * @link http://php.net/date */ -$shortdate = 'd-m-Y'; +$shortdate = 'Y-m-d'; /** * Format of long dates. -- cgit v1.2.3 From 361c18469af5f6782e622420797c4acd5fa70b97 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Sat, 26 Mar 2011 15:09:22 +0100 Subject: add new feature: allow unit test mode enabling via HTTP GET parameter --- data/config.default.php | 8 ++++++ src/SemanticScuttle/header.php | 16 ++++++++++- tests/TestBase.php | 63 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 85 insertions(+), 2 deletions(-) (limited to 'data/config.default.php') diff --git a/data/config.default.php b/data/config.default.php index 3d60b91..af79891 100644 --- a/data/config.default.php +++ b/data/config.default.php @@ -735,4 +735,12 @@ $authEmailSuffix = null; */ $unittestUrl = null; +/** + * Allow "unittestMode=1" in URLs. + * Should only be enabled on development systems + * + * @var boolean + */ +$allowUnittestMode = false; + ?> diff --git a/src/SemanticScuttle/header.php b/src/SemanticScuttle/header.php index 9c5f7da..75e5204 100644 --- a/src/SemanticScuttle/header.php +++ b/src/SemanticScuttle/header.php @@ -39,6 +39,20 @@ set_include_path( require_once $datadir . '/config.default.php'; require_once $datadir . '/config.php'; +if (isset($_GET['unittestMode']) && $_GET['unittestMode'] == 1 +) { + if ($allowUnittestMode !== true) { + header('HTTP/1.0 400 Bad Request'); + 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('UNIT_TEST_MODE', true); +} if (defined('UNIT_TEST_MODE')) { //make local config vars global - needed for unit tests //run with phpunit @@ -118,7 +132,7 @@ $tplVars['currentUser'] = $currentUser; $tplVars['userservice'] = $userservice; // 6 // Force UTF-8 behaviour for server (cannot be moved into top.inc.php which is not included into every file) -if (!defined('UNIT_TEST_MODE')) { +if (!defined('UNIT_TEST_MODE') || defined('HTTP_UNIT_TEST_MODE')) { //API files define that, so we need a way to support both of them if (!isset($httpContentType)) { if (DEBUG_MODE) { diff --git a/tests/TestBase.php b/tests/TestBase.php index 3e2e213..b85c189 100644 --- a/tests/TestBase.php +++ b/tests/TestBase.php @@ -22,6 +22,18 @@ */ class TestBase extends PHPUnit_Framework_TestCase { + /** + * Clean up after test + */ + public function tearDown() + { + if (file_exists($GLOBALS['datadir'] . '/config.unittest.php')) { + unlink($GLOBALS['datadir'] . '/config.unittest.php'); + } + } + + + /** * Create a new bookmark. * @@ -80,8 +92,25 @@ class TestBase extends PHPUnit_Framework_TestCase * @param string $password Password * * @return integer ID of user + * + * @uses addUserData() */ protected function addUser($username = null, $password = null) + { + return reset($this->addUserData($username, $password)); + } + + + + /** + * Creates a new user in the database and returns id, username and password. + * + * @param string $username Username + * @param string $password Password + * + * @return array ID of user, Name of user, password of user + */ + protected function addUserData($username = null, $password = null) { $us = SemanticScuttle_Service_Factory::get('User'); $rand = rand(); @@ -98,7 +127,7 @@ class TestBase extends PHPUnit_Framework_TestCase $password, 'unittest-' . $rand . '@example.org' ); - return $uid; + return array($uid, $username, $password); } @@ -129,6 +158,38 @@ class TestBase extends PHPUnit_Framework_TestCase return $uid; } + + + /** + * Writes a special unittest configuration file. + * The unittest config file is read when a GET request with unittestMode=1 + * is sent, and the user allowed unittestmode in config.php. + * + * @param array $arConfig Array with config names as key and their value as + * value + * + * @return void + */ + protected function setUnittestConfig($arConfig) + { + $str = '<' . "?php\r\n"; + foreach ($arConfig as $name => $value) { + $str .= '$' . $name . ' = ' + . var_export($value, true) . ";\n"; + } + + if (!is_dir($GLOBALS['datadir'])) { + $this->fail( + 'datadir not set or not a directory: ' . $GLOBALS['datadir'] + ); + } + + $this->assertInternalType( + 'integer', + file_put_contents($GLOBALS['datadir'] . '/config.unittest.php', $str), + 'Writing config.unittest.php failed' + ); + } } ?> \ No newline at end of file -- cgit v1.2.3