caseSource.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. /**
  3. * Created by JetBrains PhpStorm.
  4. * User: dongyancen
  5. * Date: 13-10-10
  6. * Time: 上午1:20
  7. * To change this template use File | Settings | File Templates.
  8. */
  9. require_once 'config.php';
  10. class Kiss
  11. {
  12. public $projroot ;
  13. public $name;
  14. public $srcPath;
  15. public $testPath;
  16. public $empty = false;
  17. public $case_id;
  18. function __construct( $name = '' )
  19. {
  20. $this->projroot = Config::$projroot;
  21. $this->srcPath = Config::$projroot.Config::$src_PATH;
  22. $this->testPath = Config::$projroot.Config::$test_PATH;
  23. $this->name = $name;
  24. $this->case_id = 'id_case_' . join( '_' , explode( '.' , $name ) );
  25. }
  26. public function print_js( $cov)
  27. {
  28. if($cov){
  29. $basePath = '../../spec/coverage';
  30. }
  31. else{
  32. $basePath = '../../src';
  33. }
  34. // print "<script src='../../dist/dev.php'></script>";
  35. print "<script type='text/javascript' src='./js/UserAction.js' ></script>\n";
  36. /* load case and case dependents*/
  37. $ps = explode( '/' , $this->name );
  38. /*load helper*/
  39. foreach(Config::$helperFiles as $f){
  40. if ( file_exists( $this->testPath . $f ) ) {
  41. print '<script type="text/javascript" src="' . $this->testPath . $f . '"></script>' . "\n";
  42. }
  43. }
  44. //先引用kity
  45. print "<script src='../../lib/jquery-2.1.0.min.js'></script>\n";
  46. print "<script src='../../lib/jquery.xml2json.js' charset='utf-8'></script>\n";
  47. print "<script src='../../lib/jquery.transit.min.js' charset='utf-8'></script>\n";
  48. print "<script src='../../lib/jquery.blob.js' charset='utf-8'></script>\n";
  49. print "<script src='../../lib/zip.js' charset='utf-8'></script>\n";
  50. print "<script src='../../lib/promise-1.0.0.js' charset='utf-8'></script>\n";
  51. print "<script src='../../lib/ZeroClipboard.min.js' charset='utf-8'></script>\n";
  52. print "<script src='../../lib/fui/dev-lib/jhtmls.min.js' charset='utf-8'></script>\n";
  53. print "<script src='../../lib/fui/dist/fui.all.js' charset='utf-8'></script>\n";
  54. print "<script src='../../lib/fio/src/fio.js' charset='utf-8'></script>\n";
  55. print "<script src='../../lib/fio/provider/netdisk/oauth.js' charset='utf-8'></script>\n";
  56. print "<script src='../../lib/fio/provider/netdisk/netdisk.js' charset='utf-8'></script>\n";
  57. print "<script src='../../lib/kity/dist/kity.js' charset='utf-8'></script>\n";
  58. //分成两部分:一部分默认加载(可配置),一部分针对文件加载(例如在文件头部有注释标注依赖文件,根据依赖文件动态加载)
  59. // core里面的文件全部加载,module加载用例对应的src文件,最后加载与用例同名的原文件
  60. $importurl = "{$this->testPath}tools/import.php?f=$this->name";
  61. if ( $cov ) $importurl .= '^&cov=true';
  62. print "<script type='text/javascript' src='".$importurl."' ></script>\n";
  63. print "<script src='../../kityminder.config.js' charset='utf-8'></script>\n";
  64. print "<script src='../../lang/zh-cn/zh-cn.js' charset='utf-8'></script>\n";
  65. print "<script type='text/javascript'>zip.inflateJSPath = '../../lib/inflate.js';</script>\n";
  66. print "<script type='text/javascript'>window._bd_share_config={'common':{'bdSnsKey':{},'bdMini':'2','bdMiniList':[],'bdPic':'','bdStyle':'1','bdSize':'32'},'share':{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>\n";
  67. // print "<script>zip.inflateJSPath = '../../lib/inflate.js';</script>\n";
  68. // print "<script src='../../lib/baidu-frontia-js-full-1.0.0.js' charset='utf-8'></script>\n";
  69. // print "<script src='../../social/draftmanager.js' charset='utf-8'></script>\n";
  70. // print "<script src='../../social/social.js' charset='utf-8'></script>\n";
  71. //引用测试文件
  72. print '<script type="text/javascript" src="' .$this->testPath.$this->name. '.js"></script>' . "\n";
  73. print "<link href='../../ui/theme/default/css/default.all.css' rel='stylesheet'>\n";
  74. // print "<link href='../../themes/default/css/import.css' type='text/css' rel='stylesheet' />\n";
  75. print "<link href='../../favicon.ico' type='image/x-icon' rel='shortcut icon'>\n";
  76. print "<link href='../../favicon.ico' type='image/x-icon' rel='apple-touch-icon-precomposed'>\n";
  77. }
  78. public function match( $matcher )
  79. {
  80. if ( $matcher == '*' )
  81. return true;
  82. $len = strlen( $matcher );
  83. /**
  84. * 处理多选分支,有一个成功则成功,filter后面参数使用|切割
  85. * @var unknown_type
  86. */
  87. $ms = explode( ',' , $matcher );
  88. if ( sizeof( $ms ) > 1 ) {
  89. foreach ( $ms as $matcher1 ) {
  90. if ( $this->match( $matcher1 ) )
  91. return true;
  92. }
  93. return false;
  94. }
  95. /**
  96. * 处理反向选择分支
  97. */
  98. if ( substr( $matcher , 0 , 1 ) == '!' ) {
  99. $m = substr( $matcher , 1 );
  100. if ( substr( $this->name , 0 , strlen( $m ) ) == $m )
  101. return false;
  102. return true;
  103. }
  104. if ( $len > strlen( $this->name ) ) {
  105. return false;
  106. }
  107. return substr( $this->name , 0 , $len ) == $matcher;
  108. }
  109. public static function listcase( $matcher = "*" ,$cov)
  110. {
  111. require_once 'fileHelper.php';
  112. /*get files both in src path and test path*/
  113. $caselist = getSameFile(Config::$projroot.Config::$src_PATH , Config::$projroot.Config::$test_PATH , '' );
  114. sort($caselist,SORT_STRING);
  115. foreach ( $caselist as $caseitem ) {
  116. /*remove '.js' */
  117. $name = substr( $caseitem , 0 , -3 );
  118. $c = new Kiss( $name );
  119. if ( $c->empty )
  120. continue;
  121. if ( $c->match( $matcher ) ) {
  122. $newName = explode( '\\.' , $name );
  123. $newName = $newName[ count( $newName ) - 1 ];
  124. if($cov){
  125. $covMsg = "&cov=true";
  126. }else{
  127. $covMsg="";
  128. }
  129. print( "<a href=\"run.php?case=$name".$covMsg."\" id=\"$c->case_id\" target=\"_blank\" title=\"$name\" onclick=\"run('$name');return false;\">". $newName . "</a>" );
  130. }
  131. }
  132. }
  133. public static function listSrcOnly( $print = true )
  134. {
  135. $srcpath = Config::$projroot.Config::$src_PATH;
  136. $testpath = Config::$projroot.Config::$test_PATH;
  137. require_once 'fileHelper.php';
  138. $caselist = getSameFile( $srcpath , $testpath , '' );
  139. $srclist = getSrcOnlyFile( $srcpath , $testpath , '' );
  140. $srcList = array();
  141. foreach ( $srclist as $case ) {
  142. if ( in_array( $case , $caselist ) )
  143. continue;
  144. $name = str_replace( '/' , '.' , substr( $case , 0 , -3 ) );
  145. $tag = "<a title=\"$name\">" . ( strlen( $name ) > 20 ? substr( $name , 6 )
  146. : $name ) . "</a>";
  147. array_push( $srcList , $tag );
  148. if ( $print )
  149. echo $tag;
  150. }
  151. return $srcList;
  152. }
  153. }