hotpotatoes.lib.test.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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='testnameofthefolder';
  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('test');
  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. $course_code = 'COURSETEST';
  40. $path = 'exercice_submit.php';
  41. $query ="select comment from $dbTable where path='$path'";
  42. $res=GetComment($path,$course_code);
  43. $this->assertTrue(is_string($res));
  44. //var_dump($res);
  45. }
  46. /* Deprecated
  47. function testGetFileName() {
  48. $fname='main/exercice/hotpotatoes.lib.php';
  49. $res=GetFileName($fname);
  50. $this->assertTrue(is_string($res));
  51. //var_dump($res);
  52. }*/
  53. function testGetFolderName() {
  54. $fname='main/exercice/hotpotatoes.lib.php';
  55. $res=GetFolderName($fname);
  56. $this->assertTrue(is_string($res));
  57. //var_dump($res);
  58. }
  59. function testGetFolderPath() {
  60. $fname='main/exercice/hotpotatoes.lib.php';
  61. $res=GetFolderPath($fname);
  62. $this->assertTrue(is_string($res));
  63. //var_dump($res);
  64. }
  65. function testGetImgName() {
  66. $imgtag='<img src="example.jpg">';
  67. $res=GetImgName($imgtag);
  68. $this->assertTrue(is_string($res));
  69. //var_dump($res);
  70. }
  71. function testGetImgParams() {
  72. $fname='/main/css/academica/images/bg.jpg';
  73. $fpath='main/css/academica/images/';
  74. $imgparams= array();
  75. $imgcount='';
  76. $res=GetImgParams($fname,$fpath,&$imgparams,&$imgcount);
  77. $this->assertTrue(is_null($res));
  78. //var_dump($res);
  79. }
  80. function testGetQuizName() {
  81. $course_code = 'COURSETEST';
  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($res);
  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 testHotPotGCt() {
  102. $folder='/main/exercice';
  103. $flag=4;
  104. $userID=1;
  105. $res=HotPotGCt($folder,$flag,$userID);
  106. $this->assertTrue(is_null($res));
  107. //var_dump($res);
  108. }
  109. function testmyarraysearch() {
  110. $array=array();
  111. $node='';
  112. $res=myarraysearch($array,$node);
  113. if(!is_bool($res))$this->assertTrue(is_null($res));
  114. //var_dump($res);
  115. }
  116. function testReadFileCont() {
  117. $full_file_path='';
  118. $res=ReadFileCont($full_file_path);
  119. if(!is_bool($res))$this->assertTrue(is_string($res));
  120. //var_dump($res);
  121. }
  122. function testReplaceImgTag() {
  123. $content='src="test2.jpg"';
  124. $res=ReplaceImgTag($content);
  125. $this->assertTrue(is_string($res));
  126. //var_dump($res);
  127. }
  128. function testSetComment() {
  129. global $dbTable;
  130. $path='/main/exercice';
  131. $comment='testing this function';
  132. $comment = Database::escape_string($comment);
  133. $query = "UPDATE $dbTable set comment='$comment' where path='$path'";
  134. $result = Database::query($query);
  135. $res=SetComment($path,$comment);
  136. $this->assertTrue(is_string($res));
  137. //var_dump($resu);
  138. }
  139. function testWriteFileCont() {
  140. $course_code = 'COURSETEST';
  141. $full_file_path='/main/exercice/';
  142. $content='test test test';
  143. $res=WriteFileCont($full_file_path,$content);
  144. $this->assertTrue(is_bool($res));
  145. //var_dump($res);
  146. }
  147. }
  148. ?>