enable running unit tests from cli
This commit is contained in:
parent
27f7dae932
commit
60fdc13ae6
|
@ -78,6 +78,10 @@ class OC{
|
||||||
* requested file of app
|
* requested file of app
|
||||||
*/
|
*/
|
||||||
public static $REQUESTEDFILE = '';
|
public static $REQUESTEDFILE = '';
|
||||||
|
/**
|
||||||
|
* check if owncloud runs in cli mode
|
||||||
|
*/
|
||||||
|
public static $CLI = false;
|
||||||
/**
|
/**
|
||||||
* SPL autoload
|
* SPL autoload
|
||||||
*/
|
*/
|
||||||
|
@ -320,6 +324,7 @@ class OC{
|
||||||
if (defined('DEBUG') && DEBUG){
|
if (defined('DEBUG') && DEBUG){
|
||||||
ini_set('display_errors', 1);
|
ini_set('display_errors', 1);
|
||||||
}
|
}
|
||||||
|
self::$CLI=(php_sapi_name() == 'cli');
|
||||||
|
|
||||||
date_default_timezone_set('Europe/Berlin');
|
date_default_timezone_set('Europe/Berlin');
|
||||||
ini_set('arg_separator.output','&');
|
ini_set('arg_separator.output','&');
|
||||||
|
@ -372,12 +377,14 @@ class OC{
|
||||||
// CSRF protection
|
// CSRF protection
|
||||||
if(isset($_SERVER['HTTP_REFERER'])) $referer=$_SERVER['HTTP_REFERER']; else $referer='';
|
if(isset($_SERVER['HTTP_REFERER'])) $referer=$_SERVER['HTTP_REFERER']; else $referer='';
|
||||||
if(isset($_SERVER['HTTPS']) and $_SERVER['HTTPS']<>'') $protocol='https://'; else $protocol='http://';
|
if(isset($_SERVER['HTTPS']) and $_SERVER['HTTPS']<>'') $protocol='https://'; else $protocol='http://';
|
||||||
|
if(!self::$CLI){
|
||||||
$server=$protocol.$_SERVER['SERVER_NAME'];
|
$server=$protocol.$_SERVER['SERVER_NAME'];
|
||||||
if(($_SERVER['REQUEST_METHOD']=='POST') and (substr($referer,0,strlen($server))<>$server)) {
|
if(($_SERVER['REQUEST_METHOD']=='POST') and (substr($referer,0,strlen($server))<>$server)) {
|
||||||
$url = $protocol.$_SERVER['SERVER_NAME'].OC::$WEBROOT.'/index.php';
|
$url = $protocol.$_SERVER['SERVER_NAME'].OC::$WEBROOT.'/index.php';
|
||||||
header("Location: $url");
|
header("Location: $url");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
self::initSession();
|
self::initSession();
|
||||||
self::initTemplateEngine();
|
self::initTemplateEngine();
|
||||||
|
|
|
@ -38,7 +38,13 @@ foreach($apps as $app){
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadTests($dir=''){
|
function loadTests($dir=''){
|
||||||
|
if(OC::$CLI){
|
||||||
|
$reporter='TextReporter';
|
||||||
|
$test=isset($_SERVER['argv'][1])?$_SERVER['argv'][1]:false;
|
||||||
|
}else{
|
||||||
|
$reporter='HtmlReporter';
|
||||||
$test=isset($_GET['test'])?$_GET['test']:false;
|
$test=isset($_GET['test'])?$_GET['test']:false;
|
||||||
|
}
|
||||||
if($dh=opendir($dir)){
|
if($dh=opendir($dir)){
|
||||||
while($name=readdir($dh)){
|
while($name=readdir($dh)){
|
||||||
if(substr($name,0,1)!='.'){//no hidden files, '.' or '..'
|
if(substr($name,0,1)!='.'){//no hidden files, '.' or '..'
|
||||||
|
@ -51,7 +57,7 @@ function loadTests($dir=''){
|
||||||
$testCase=new TestSuite($name);
|
$testCase=new TestSuite($name);
|
||||||
$testCase->addFile($file);
|
$testCase->addFile($file);
|
||||||
if($testCase->getSize()>0){
|
if($testCase->getSize()>0){
|
||||||
$testCase->run(new HtmlReporter());
|
$testCase->run(new $reporter());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue