index.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Robin Appelman
  6. * @copyright 2012 Robin Appelman icewind@owncloud.com
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. require_once '../lib/base.php';
  23. require_once 'simpletest/unit_tester.php';
  24. require_once 'simpletest/mock_objects.php';
  25. require_once 'simpletest/collector.php';
  26. require_once 'simpletest/default_reporter.php';
  27. //load core test cases
  28. loadTests(dirname(__FILE__));
  29. //load app test cases
  30. $apps=OC_App::getEnabledApps();
  31. foreach($apps as $app){
  32. if(is_dir(OC::$SERVERROOT.'/apps/'.$app.'/tests')){
  33. loadTests(OC::$SERVERROOT.'/apps/'.$app.'/tests');
  34. }
  35. }
  36. function loadTests($dir=''){
  37. if(OC::$CLI){
  38. $reporter='TextReporter';
  39. $test=isset($_SERVER['argv'][1])?$_SERVER['argv'][1]:false;
  40. }else{
  41. $reporter='HtmlReporter';
  42. $test=isset($_GET['test'])?$_GET['test']:false;
  43. }
  44. if($dh=opendir($dir)){
  45. while($name=readdir($dh)){
  46. if($name[0]!='.'){//no hidden files, '.' or '..'
  47. $file=$dir.'/'.$name;
  48. if(is_dir($file)){
  49. loadTests($file);
  50. }elseif(substr($file,-4)=='.php' and $file!=__FILE__){
  51. $name=getTestName($file);
  52. if($test===false or $test==$name or substr($name,0,strlen($test))==$test){
  53. $testCase=new TestSuite($name);
  54. $testCase->addFile($file);
  55. if($testCase->getSize()>0){
  56. $testCase->run(new $reporter());
  57. }
  58. }
  59. }
  60. }
  61. }
  62. }
  63. }
  64. function getTestName($file){
  65. // //TODO: get better test names
  66. $file=substr($file,strlen(OC::$SERVERROOT));
  67. return substr($file,0,-4);//strip .php
  68. }