case.class.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?php
  2. require_once 'config.php';
  3. /**
  4. * for case running
  5. *
  6. * @author bell
  7. */
  8. class Kiss
  9. {
  10. public $projroot;
  11. /**
  12. * case name
  13. * @var string
  14. */
  15. public $name;
  16. public $path;
  17. private $ext;
  18. /**
  19. * type of case is core or another
  20. * @var boolean
  21. */
  22. public $is_core;
  23. /**
  24. * true means qunit, false means jsspec
  25. * @var boolean
  26. */
  27. public $js_frame;
  28. /**
  29. * case id shown in html
  30. * @var string
  31. */
  32. public $case_id;
  33. /**
  34. * 某些用例是空的,应该直接过滤掉
  35. * @var unknown_type
  36. */
  37. public $empty = false;
  38. /**
  39. *
  40. * @param string $projroot root of project
  41. * @param string $name namespace of case
  42. */
  43. function __construct( $projroot = '../../../' , $name = 'baidu.core.dom.domUtils' , $ext = '' )
  44. {
  45. $this->projroot = $projroot;
  46. $this->name = $name;
  47. $this->ext = $ext;
  48. if ( strlen( $ext ) > 0 ) {
  49. $ns = explode( '.' , $name );
  50. $n = array_pop( $ns );
  51. array_push( $ns , $ext , $n );
  52. $path = implode( '/' , $ns );
  53. } else {
  54. //$path = implode( '/' , explode( '.' , $name ) );
  55. $path = $name; //为了支持xx.xx.js类型的文件名而修改 田丽丽
  56. }
  57. // $dir = explode('/',$path);
  58. // if($dir[0]=='dialogs')
  59. // $this->path = $this->projroot . '_test/' . $path . '.html';
  60. // else
  61. $this->path = $this->projroot . '_test/' . $path . '.js';
  62. if ( filesize( $this->path ) < 20 ) {
  63. $this->empty = true;
  64. return;
  65. }
  66. $this->case_id = 'id_case_' . join( '_' , explode( '.' , $name ) );
  67. }
  68. public function print_js( $cov, $release = false )
  69. {
  70. print '<script type="text/javascript" src="js/jquery-1.5.1.js"></script>'. "\n";
  71. print '<script type="text/javascript" src="js/tangram.js"></script>'. "\n";
  72. print '<script type="text/javascript" src="js/testrunner.js"></script>'. "\n";
  73. print '<script type="text/javascript" src="js/ext_qunit.js"></script>'. "\n";
  74. print '<script type="text/javascript" src="js/UserAction.js"></script>'. "\n";
  75. print '<link media="screen" href="css/qunit.css" type="text/css" rel="stylesheet" />'. "\n";
  76. print '<link href="../../../themes/default/_css/ueditor.css" type="text/css" rel="stylesheet" />'. "\n";
  77. print '<script type="text/javascript" src="js/tools.js"></script>'. "\n";
  78. print '<script type="text/javascript" charset="utf-8" src="../../../third-party/SyntaxHighlighter/shCore.js"></script>'. "\n"; // print '<script type="text/javascript" charset="utf-8" src="../../ueditor.config_src.js"></script>' . "\n";
  79. print '<script type="text/javascript" charset="utf-8" src="../../../ueditor.config.js"></script>'. "\n";
  80. /* load case source*/
  81. $importurl = "{$this->projroot}_test/tools/br/import.php?f=$this->name";
  82. if ( $cov ) $importurl .= '^&cov=true';
  83. print "<script type='text/javascript' src='".$importurl."' ></script>\n";
  84. /* load case and case dependents*/
  85. //$ps = explode( '.' , $this->name );
  86. $ps = explode( '/' , $this->name ); //为了支持xx.xx.js类型的文件名而修改 田丽丽
  87. array_pop( $ps );
  88. array_push( $ps , 'tools' );
  89. if ( file_exists( $this->projroot . '_test/' . implode( '/' , $ps ) . '.js' ) ) //没有就不加载了
  90. print '<script type="text/javascript" src="' . $this->projroot . '_test/' . implode( '/' , $ps ) . '.js"></script>' . "\n";
  91. print '<script type="text/javascript" src="' . $this->path . '"></script>' . "\n";
  92. }
  93. public function print_all_js( $cov, $release = false )
  94. {
  95. print '<script type="text/javascript" src="js/jquery-1.5.1.js"></script>'. "\n";
  96. print '<script type="text/javascript" src="js/tangram.js"></script>'. "\n";
  97. print '<script type="text/javascript" src="js/testrunner.js"></script>'. "\n";
  98. print '<script type="text/javascript" src="js/ext_qunit.js"></script>'. "\n";
  99. print '<script type="text/javascript" src="js/UserAction.js"></script>'. "\n";
  100. print '<link media="screen" href="css/qunit.css" type="text/css" rel="stylesheet" />'. "\n";
  101. print '<link href="../../../themes/default/_css/ueditor.css" type="text/css" rel="stylesheet" />'. "\n";
  102. print '<script type="text/javascript" src="js/tools.js"></script>'. "\n";
  103. print '<script type="text/javascript" charset="utf-8" src="../../../third-party/SyntaxHighlighter/shCore.js"></script>'. "\n";
  104. print '<script type="text/javascript" charset="utf-8" src="../../../ueditor/ueditor.config.js"></script>' . "\n";
  105. /* load case source*/
  106. $importurl = "{$this->projroot}ueditor/ueditor.all.min.js";
  107. print "<script type='text/javascript' src='".$importurl."' ></script>\n";
  108. /* load case and case dependents*/
  109. //$ps = explode( '.' , $this->name );
  110. $ps = explode( '/' , $this->name ); //为了支持xx.xx.js类型的文件名而修改 田丽丽
  111. array_pop( $ps );
  112. array_push( $ps , 'tools' );
  113. if ( file_exists( $this->projroot . '_test/' . implode( '/' , $ps ) . '.js' ) ) //没有就不加载了
  114. print '<script type="text/javascript" src="' . $this->projroot . '_test/' . implode( '/' , $ps ) . '.js"></script>' . "\n";
  115. print '<script type="text/javascript" src="' . $this->path . '"></script>' . "\n";
  116. }
  117. public function match( $matcher )
  118. {
  119. if ( $matcher == '*' )
  120. return true;
  121. $len = strlen( $matcher );
  122. /**
  123. * 处理多选分支,有一个成功则成功,filter后面参数使用|切割
  124. * @var Array
  125. */
  126. $as = explode( ';' , $matcher );
  127. if ($as != false && sizeof( $as ) > 1 ) {
  128. //这里把或的逻辑改成与
  129. foreach ( $as as $matcher1 ) {
  130. if ( $this->match( $matcher1 ) )
  131. return true;
  132. }
  133. return false;
  134. }
  135. $ms = explode( ',' , $matcher );
  136. if ( sizeof( $ms ) > 1 ) {
  137. //这里把或的逻辑改成与
  138. foreach ( $ms as $matcher1 ) {
  139. if ( !$this->match( $matcher1 ) )
  140. return false;
  141. }
  142. return true;
  143. }
  144. /**
  145. * 处理反向选择分支
  146. */
  147. if ( substr( $matcher , 0 , 1 ) == '!' ) {
  148. $m = substr( $matcher , 1 );
  149. if ( substr( $this->name , 0 , strlen( $m ) ) == $m )
  150. return false;
  151. return true;
  152. }
  153. if ( $len > strlen( $this->name ) ) {
  154. return false;
  155. }
  156. return substr( $this->name , 0 , $len ) == $matcher;
  157. }
  158. public static function listcase( $filter = "*" , $filterRun = '*',$projroot = '../../../' )
  159. {
  160. $srcpath = $projroot . '_src/';
  161. $testpath = $projroot . '_test/';
  162. require_once 'filehelper.php';
  163. $caselist = getSameFile( $srcpath , $testpath , '' );
  164. sort($caselist,SORT_STRING);
  165. foreach ( $caselist as $caseitem ) {
  166. /*将文件名替换为域名方式,替换/为.,移除.js*/
  167. //$name = str_replace( '/' , '.' , substr( $caseitem , 0 , -3 ) );
  168. $name = substr( $caseitem , 0 , -3 ); //为了支持xx.xx.js类型的文件名而修改 田丽丽
  169. $c = new Kiss( $projroot , $name );
  170. if ( $c->empty )
  171. continue;
  172. if ( $c->match( $filterRun ) ) {
  173. $newName = explode( '\\.' , $name );
  174. $newName = $newName[ count( $newName ) - 1 ];
  175. print( "/*过长的时候屏蔽超出20的部分,因为隐藏的处理,所有用例不能直接使用标签a中的innerHTML,而应该使用title*/". $newName . "</a>\n" );
  176. }
  177. }
  178. /**
  179. * 设置在源码路径下没有同名文件对应的测试文件
  180. */
  181. foreach(Config::$special_Case as $s_caseitem => $s_source){
  182. //取形如 'plugins/config_test.js' 中 'plugins/config_test'部分
  183. $s_newName = str_replace(".js","", $s_caseitem );
  184. print( "<a href=\"run.php?case=$s_newName\" id=\"id_case_".str_replace('.','_',$s_newName)."\" class=\"jsframe_qunit\" target=\"_blank\" title=\"$s_newName\" onclick=\"run('$s_newName');\$('#id_rerun').html('$s_newName');return false;\">". $s_newName . "</a>\n" );
  185. }
  186. }
  187. public static function listSrcOnly( $print = true , $projroot = '../../../' )
  188. {
  189. $srcpath = $projroot . '_src/';
  190. $testpath = $projroot . '_test/';
  191. require_once 'filehelper.php';
  192. $caselist = getSameFile( $srcpath , $testpath , '' );
  193. $srclist = getSrcOnlyFile( $srcpath , $testpath , '' );
  194. $srcList = array();
  195. foreach ( $srclist as $case ) {
  196. if ( in_array( $case , $caselist ) )
  197. continue;
  198. $name = str_replace( '/' , '.' , substr( $case , 0 , -3 ) );
  199. $tag = "<a class=\"jsframe_qunit\" title=\"$name\">" . ( strlen( $name ) > 20 ? substr( $name , 6 )
  200. : $name ) . "</a>";
  201. array_push( $srcList , $tag );
  202. if ( $print )
  203. echo $tag;
  204. }
  205. return $srcList;
  206. }
  207. }
  208. ?>