hotpotatoes.lib.test.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. require_once(api_get_path(SYS_CODE_PATH).'exercice/hotpotatoes.lib.php');
  3. class TestHotpotatoes extends UnitTestCase {
  4. function testCheckImageName() {
  5. $imgparams=array();
  6. $string='';
  7. $checked = myarraysearch($imgparams,$string);
  8. $res=CheckImageName(&$imgparams,$string);
  9. $this->assertTrue(is_bool($res));
  10. $this->assertTrue(is_bool($checked));
  11. //var_dump($res);
  12. }
  13. function testCheckSubFolder() {
  14. $path='Location: /main/exercice/';
  15. $res=CheckSubFolder($path);
  16. $this->assertTrue(is_numeric($res));
  17. //var_dump($res);
  18. }
  19. function testFillFolderName() {
  20. $name='12doceletras';
  21. $nsize=12;
  22. $res=FillFolderName($name,$nsize);
  23. $this->assertTrue(is_string($res));
  24. //var_dump($res);
  25. }
  26. function testGenerateHiddenList() {
  27. $imgparams=array('abc');
  28. $res=GenerateHiddenList($imgparams);
  29. $this->assertTrue(is_string($res));
  30. //var_dump($res);
  31. }
  32. function testGenerateHpFolder() {
  33. $folder='main/exercice/hotpotatoes.lib.php';
  34. $res=GenerateHpFolder($folder);
  35. $this->assertTrue(is_string($res));
  36. //var_dump($res);
  37. }
  38. function testGetComment() {
  39. global $dbTable;
  40. $path = 'test';
  41. $course_code='test';
  42. $query ="select comment from $dbTable where path='$path'";
  43. $res=GetComment($path,$course_code);
  44. $this->assertTrue(is_string($res));
  45. //var_dump($res);
  46. }
  47. /* Deprecated
  48. function testGetFileName() {
  49. $fname='main/exercice/hotpotatoes.lib.php';
  50. $res=GetFileName($fname);
  51. $this->assertTrue(is_string($res));
  52. //var_dump($res);
  53. }*/
  54. function testGetFolderName() {
  55. $fname='main/exercice/hotpotatoes.lib.php';
  56. $res=GetFolderName($fname);
  57. $this->assertTrue(is_string($res));
  58. //var_dump($res);
  59. }
  60. function testGetFolderPath() {
  61. $fname='main/exercice/hotpotatoes.lib.php';
  62. $res=GetFolderPath($fname);
  63. $this->assertTrue(is_string($res));
  64. //var_dump($res);
  65. }
  66. function testGetImgName() {
  67. $imgtag='<img src="example.jpg">';
  68. $res=GetImgName($imgtag);
  69. $this->assertTrue(is_string($res));
  70. //var_dump($res);
  71. }
  72. function testGetImgParams() {
  73. $fname='/main/css/academica/images/bg.jpg';
  74. $fpath='main/css/academica/images/';
  75. $imgparams= array();
  76. $imgcount='';
  77. $res=GetImgParams($fname,$fpath,&$imgparams,&$imgcount);
  78. $this->assertTrue(is_null($res));
  79. //var_dump($res);
  80. }
  81. function testGetQuizName() {
  82. $fname='exercice_submit.php';
  83. $fpath='main/exercice/exercice_submit.php';
  84. $res=GetQuizName($fname,$fpath);
  85. $this->assertTrue(is_string($res));
  86. //var_dump($e_contents);
  87. }
  88. function testGetSrcName() {
  89. $imgtag='src="test.jpg""';
  90. $res=GetSrcName($imgtag);
  91. if(!is_string($res))$this->assertTrue(is_bool($res));
  92. //var_dump($res);
  93. }
  94. function testhotpotatoes_init() {
  95. $base = api_get_path(SYS_CODE_PATH);
  96. $baseWorkDir=$base.'exercice/';
  97. $res=hotpotatoes_init($baseWorkDir);
  98. $this->assertFalse($res);
  99. //var_dump($res);
  100. }
  101. function testhotpotatoes_initWithRemoveFolder() {
  102. $base = '/tmp/';
  103. $baseWorkDir=$base.'test123/';
  104. $res=hotpotatoes_init($baseWorkDir);
  105. $this->assertTrue($res);
  106. rmdir($baseWorkDir);
  107. //var_dump($res);
  108. }
  109. function testHotPotGCt() {
  110. $folder='/main/exercice';
  111. $flag=4;
  112. $userID=1;
  113. $res=HotPotGCt($folder,$flag,$userID);
  114. $this->assertTrue(is_null($res));
  115. //var_dump($res);
  116. }
  117. function testmyarraysearch() {
  118. $array=array();
  119. $node='';
  120. $res=myarraysearch($array,$node);
  121. if(!is_bool($res))$this->assertTrue(is_null($res));
  122. //var_dump($res);
  123. }
  124. function testReadFileCont() {
  125. $full_file_path='';
  126. $res=ReadFileCont($full_file_path);
  127. if(!is_bool($res))$this->assertTrue(is_string($res));
  128. //var_dump($res);
  129. }
  130. function testReplaceImgTag() {
  131. $content='src="test2.jpg"';
  132. $res=ReplaceImgTag($content);
  133. $this->assertTrue(is_string($res));
  134. //var_dump($res);
  135. }
  136. function testSetComment() {
  137. global $dbTable;
  138. $path='/main/exercice';
  139. $comment='testing this function';
  140. $comment = Database::escape_string($comment);
  141. $query = "UPDATE $dbTable set comment='$comment' where path='$path'";
  142. $result = api_sql_query($query,__FILE__,__LINE__);
  143. $res=SetComment($path,$comment);
  144. $this->assertTrue(is_string($res));
  145. //var_dump($resu);
  146. }
  147. function testWriteFileCont() {
  148. $full_file_path='/main/exercice/';
  149. $content='test test test';
  150. $res=WriteFileCont($full_file_path,$content);
  151. $this->assertTrue(is_bool($res));
  152. //var_dump($res);
  153. }
  154. }
  155. ?>