allow apps to ship test cases

This commit is contained in:
Robin Appelman 2012-03-02 15:32:20 +01:00
parent d1dcd7893c
commit 3b9ce95fc3
1 changed files with 16 additions and 8 deletions

View File

@ -26,20 +26,27 @@ require_once 'simpletest/mock_objects.php';
require_once 'simpletest/collector.php'; require_once 'simpletest/collector.php';
require_once 'simpletest/default_reporter.php'; require_once 'simpletest/default_reporter.php';
//load all test cases //load core test cases
loadTests(); loadTests(dirname(__FILE__));
//load app test cases
$apps=OC_App::getAllApps();
foreach($apps as $app){
if(is_dir(OC::$SERVERROOT.'/apps/'.$app.'/tests')){
loadTests(OC::$SERVERROOT.'/apps/'.$app.'/tests');
}
}
function loadTests($dir=''){ function loadTests($dir=''){
$basedir=dirname(__FILE__).'/'; if($dh=opendir($dir)){
if($dh=opendir($basedir.$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 '..'
$file=$dir.'/'.$name; $file=$dir.'/'.$name;
if(is_dir($basedir.$file)){ if(is_dir($file)){
loadTests($file); loadTests($file);
}elseif(substr($file,-4)=='.php' and $file!=__FILE__){ }elseif(substr($file,-4)=='.php' and $file!=__FILE__){
$testCase=new TestSuite(getTestName($file)); $testCase=new TestSuite(getTestName($file));
$testCase->addFile($basedir.$file); $testCase->addFile($file);
if($testCase->getSize()>0){ if($testCase->getSize()>0){
$testCase->run(new HtmlReporter()); $testCase->run(new HtmlReporter());
} }
@ -50,6 +57,7 @@ function loadTests($dir=''){
} }
function getTestName($file){ function getTestName($file){
//TODO: get better test names // //TODO: get better test names
return substr($file,5,-4);//strip /lib/ and .php $file=substr($file,strlen(OC::$SERVERROOT));
return substr($file,0,-4);//strip .php
} }