userInfoLib.test.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. require_once(api_get_path(SYS_CODE_PATH).'user/userInfoLib.php');
  3. class TestUserInfoLib extends UnitTestCase {
  4. /**
  5. * clean the content of a bloc for information category
  6. */
  7. function testcleanout_cat_content(){
  8. global $TBL_USERINFO_CONTENT;
  9. $user_id=1;
  10. $definition_id=1;
  11. $res=cleanout_cat_content($user_id, $definition_id);
  12. $this->assertTrue(($res));
  13. //var_dump($res);
  14. }
  15. /**
  16. * create a new category definition for the user information
  17. */
  18. function testcreate_cat_def() {
  19. global $TBL_USERINFO_DEF;
  20. $res=create_cat_def($title="test", $comment="comment test", $nbline="5");
  21. $this->assertTrue(($res));
  22. //var_dump($res);
  23. }
  24. /**
  25. * Edit a bloc for information category
  26. */
  27. function testedit_cat_content() {
  28. global $TBL_USERINFO_CONTENT;
  29. $definition_id=1;
  30. $user_id=1;
  31. $res=edit_cat_content($definition_id, $user_id, $content ="", $user_ip="");
  32. $this->assertTrue(is_bool($res));
  33. //var_dump($res);
  34. }
  35. /**
  36. * modify the definition of a user information category
  37. */
  38. function testedit_cat_def() {
  39. $id=1;
  40. $title='test';
  41. $comment='comment test';
  42. $nbline=2;
  43. $res=edit_cat_def($id, $title, $comment, $nbline);
  44. $this->assertTrue(is_bool($res));
  45. //var_dump($res);
  46. }
  47. /**
  48. * fill a bloc for information category
  49. */
  50. function testfill_new_cat_content() {
  51. $definition_id='';
  52. $user_id=1;
  53. $res=fill_new_cat_content($definition_id, $user_id, $content="", $user_ip="");
  54. $this->assertTrue(is_bool($res));
  55. //var_dump($res);
  56. }
  57. /**
  58. * get the user content of a categories plus the categories definition
  59. */
  60. function testget_cat_content() {
  61. global $TBL_USERINFO_CONTENT, $TBL_USERINFO_DEF;
  62. $userId=1;
  63. $catId=1;
  64. $sql = "SELECT 1";
  65. $result = Database::query($sql,__FILE__,__LINE__);
  66. $catContent = Database::fetch_array($result);
  67. $res=get_cat_content($userId, $catId);
  68. $this->assertTrue(is_array($catContent));
  69. $this->assertTrue(is_bool($res));
  70. //var_dump($res);
  71. }
  72. function testget_cat_def() {
  73. global $TBL_USERINFO_DEF;
  74. $catId=1;
  75. $res=get_cat_def($catId);
  76. $this->assertTrue(is_bool($res));
  77. //var_dump($res);
  78. }
  79. function testget_cat_def_list() {
  80. global $TBL_USERINFO_DEF;
  81. $res=get_cat_def_list();
  82. $this->assertTrue(is_bool($res));
  83. //var_dump($res);
  84. }
  85. function testget_course_user_info() {
  86. global $TBL_USERINFO_CONTENT, $TBL_USERINFO_DEF;
  87. $user_id=1;
  88. $res=get_course_user_info($user_id);
  89. $this->assertTrue(is_bool($res));
  90. //var_dump($res);
  91. }
  92. function testget_main_user_info() {
  93. $user_id=1;
  94. $courseCode='TEST';
  95. $res=get_main_user_info($user_id,$courseCode);
  96. if(!is_bool($res))$this->assertTrue(is_array($res));
  97. var_dump($res);
  98. }
  99. function testhtmlize() {
  100. global $charset;
  101. $phrase='test';
  102. $res=htmlize($phrase);
  103. $this->assertTrue(is_string($res));
  104. //var_dump($res);
  105. }
  106. function testmove_cat_rank() {
  107. global $TBL_USERINFO_DEF;
  108. $id=1;
  109. $direction='up';
  110. $res=move_cat_rank($id, $direction);
  111. $this->assertTrue(is_bool($res));
  112. //var_dump($res);
  113. }
  114. function testmove_cat_rank_by_rank() {
  115. global $TBL_USERINFO_DEF;
  116. $rank=5;
  117. $direction='up';
  118. $res=move_cat_rank_by_rank($rank, $direction);
  119. $this->assertTrue(is_bool($res));
  120. //var_dump($res);
  121. }
  122. /**
  123. * remove a category from the category list
  124. * @param - int $id - id of the category
  125. * or "ALL" for all category
  126. * @param - boolean $force - FALSE (default) : prevents removal if users have
  127. * already fill this category
  128. * TRUE : bypass user content existence check
  129. * @param - int $nbline - lines number for the field the user will fill.
  130. * @return - bollean - TRUE if succeed, ELSE otherwise
  131. */
  132. function testremove_cat_def() {
  133. global $TBL_USERINFO_CONTENT, $TBL_USERINFO_DEF;
  134. $id=1;
  135. $res=remove_cat_def($id, $force = false);
  136. if(!is_null($res))$this->assertTrue(is_bool($res));
  137. //var_dump($res);
  138. }
  139. /**
  140. * @author Hugues Peeters - peeters@ipm.ucl.ac.be
  141. * @param int $user_id
  142. * @param string $course_code
  143. * @param array $properties - should contain 'role', 'status', 'tutor_id'
  144. * @return boolean true if succeed false otherwise
  145. */
  146. function testupdate_user_course_properties() {
  147. $user_id=1;
  148. $course_code='test';
  149. $properties=array();
  150. $res=update_user_course_properties($user_id, $course_code, $properties);
  151. $this->assertTrue(is_bool($res));
  152. //var_dump($res);
  153. }
  154. }
  155. ?>