index.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. $testSuiteName="ownCloud Unit Test Suite";
  28. // prepare the reporter
  29. if(OC::$CLI){
  30. $reporter=new TextReporter;
  31. $test=isset($_SERVER['argv'][1])?$_SERVER['argv'][1]:false;
  32. if($test=='xml'){
  33. $reporter= new XmlReporter;
  34. $test=false;
  35. if(isset($_SERVER['argv'][2])){
  36. $testSuiteName=$testSuiteName." (".$_SERVER['argv'][2].")";
  37. }
  38. }
  39. }else{
  40. $reporter=new HtmlReporter;
  41. $test=isset($_GET['test'])?$_GET['test']:false;
  42. }
  43. // test suite instance
  44. $testSuite=new TestSuite($testSuiteName);
  45. //load core test cases
  46. loadTests(dirname(__FILE__), $testSuite, $test);
  47. //load app test cases
  48. //
  49. // TODO: define a list of apps to be enabled + enable them
  50. //
  51. $apps=OC_App::getEnabledApps();
  52. foreach($apps as $app){
  53. if(is_dir(OC::$SERVERROOT.'/apps/'.$app.'/tests')){
  54. loadTests(OC::$SERVERROOT.'/apps/'.$app.'/tests', $testSuite, $test);
  55. }
  56. }
  57. // run the suite
  58. if($testSuite->getSize()>0){
  59. $testSuite->run($reporter);
  60. }
  61. // helper below
  62. function loadTests($dir,$testSuite, $test){
  63. if($dh=opendir($dir)){
  64. while($name=readdir($dh)){
  65. if($name[0]!='.'){//no hidden files, '.' or '..'
  66. $file=$dir.'/'.$name;
  67. if(is_dir($file)){
  68. loadTests($file, $testSuite, $test);
  69. }elseif(substr($file,-4)=='.php' and $file!=__FILE__){
  70. $name=getTestName($file);
  71. if($test===false or $test==$name or substr($name,0,strlen($test))==$test){
  72. $extractor = new SimpleFileLoader();
  73. $loadedSuite=$extractor->load($file);
  74. if ($loadedSuite->getSize() > 0)
  75. $testSuite->add($loadedSuite);
  76. }
  77. }
  78. }
  79. }
  80. }
  81. }
  82. function getTestName($file){
  83. // //TODO: get better test names
  84. $file=substr($file,strlen(OC::$SERVERROOT));
  85. return substr($file,0,-4);//strip .php
  86. }