index.php 2.8 KB

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