hotpotatoes.lib.test.php 4.2 KB

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