summaryrefslogtreecommitdiffstats
path: root/tests/index.php
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2012-02-12 18:06:32 +0100
committerRobin Appelman <icewind@owncloud.com>2012-02-12 18:07:58 +0100
commit357944693017572319334aa8943e888cde0e99c0 (patch)
treed5c7e79c674c3db637865e8f14356ef2235a81aa /tests/index.php
parent0917bdecddd74a48ee2b21f18e184c579d156b62 (diff)
downloadnextcloud-server-357944693017572319334aa8943e888cde0e99c0.tar.gz
nextcloud-server-357944693017572319334aa8943e888cde0e99c0.zip
use SimpleTest for unit testing
includes some tests for storage providers, more to come
Diffstat (limited to 'tests/index.php')
-rw-r--r--tests/index.php77
1 files changed, 27 insertions, 50 deletions
diff --git a/tests/index.php b/tests/index.php
index 34e1d4166ce..d29579a4bba 100644
--- a/tests/index.php
+++ b/tests/index.php
@@ -3,7 +3,7 @@
* ownCloud
*
* @author Robin Appelman
-* @copyright 2010 Robin Appelman icewind1991@gmailc.om
+* @copyright 2012 Robin Appelman icewind@owncloud.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@@ -20,59 +20,36 @@
*
*/
+require_once '../lib/base.php';
+require_once 'simpletest/unit_tester.php';
+require_once 'simpletest/mock_objects.php';
+require_once 'simpletest/collector.php';
+require_once 'simpletest/default_reporter.php';
-/**
- * run all test cases
- */
- $RUNTIME_NOSETUPFS=true;
-require_once('../lib/base.php');
-OC_Util::checkAdminUser();
+//load all test cases
+loadTests();
-$testCases=loadFiles(__DIR__,array('index.php','templates'));
-@ob_end_clean();
-$testResults=array();
-foreach($testCases as $testCaseClass){
- $testCase=new $testCaseClass();
- $results=array();
- foreach($testCase->getTests() as $test){
- $testCase->setup();
- try{
- $testCase->$test();
- $results[$test]='Ok';
- }catch(Exception $e){
- $results[$test]=$e->getMessage();
+function loadTests($dir=''){
+ $basedir=dirname(__FILE__).'/';
+ if($dh=opendir($basedir.$dir)){
+ while($name=readdir($dh)){
+ if(substr($name,0,1)!='.'){//no hidden files, '.' or '..'
+ $file=$dir.'/'.$name;
+ if(is_dir($basedir.$file)){
+ loadTests($file);
+ }elseif(substr($file,-4)=='.php' and $file!=__FILE__){
+ $testCase=new TestSuite(getTestName($file));
+ $testCase->addFile($basedir.$file);
+ if($testCase->getSize()>0){
+ $testCase->run(new DefaultReporter());
+ }
+ }
+ }
}
- $testCase->tearDown();
}
- $testResults[$testCaseClass]=$results;
}
-$tmpl = new OC_Template( 'tests', 'index');
-$tmpl->assign('tests',$testResults);
-$tmpl->printPage();
-
-/**
- * recursively load all files in a folder
- * @param string $path
- * @param array $exclude list of files to exclude
- */
-function loadFiles($path,$exclude=false){
- $results=array();
- if(!$exclude){
- $exclude=array();
- }
- $dh=opendir($path);
- while($file=readdir($dh)){
- if($file!='.' && $file!='..' && array_search($file,$exclude)===false){
- if(is_file($path.'/'.$file) and substr($file,-3)=='php'){
- $result=require_once($path.'/'.$file);
- $results[]=$result;
- }elseif(is_dir($path.'/'.$file)){
- $subResults=loadFiles($path.'/'.$file);
- $results=array_merge($results,$subResults);
- }
- }
- }
- return $results;
+function getTestName($file){
+ //TODO: get better test names
+ return substr($file,5,-4);//strip /lib/ and .php
}
-?>