permissions_functions.inc.test.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <?php
  2. require_once api_get_path(SYS_CODE_PATH).'blog/permissions/permissions_functions.inc.php';
  3. //require_once dirname(__FILE__).'/../main/permissions/permissions_functions.inc.php';
  4. class TestPermissions extends UnitTestCase {
  5. public function __construct() {
  6. $this->UnitTestCase('Permissions library - main/permissions/permissions_functions.inc.test.php');
  7. }
  8. /**
  9. * This function is called when we assign a role to a user or a group
  10. * @param string
  11. * @param string
  12. * @param int
  13. * @param int
  14. * @return string
  15. */
  16. function testAssignRole(){
  17. $content='';
  18. $action='';
  19. $id=1;
  20. $role_id=1;
  21. $scope='course';
  22. $res = assign_role($content, $action, $id, $role_id, $scope);
  23. $this->assertTrue(is_string($res));
  24. //var_dump($res);
  25. }
  26. /**
  27. This function displays a checked or unchecked checkbox. The checkbox will be checked if the
  28. * user, group or role has the permission for the given tool, unchecked if the user, group or role
  29. * does not have the right
  30. * @param array
  31. * @param string
  32. * @param string
  33. * @param array
  34. * @return null
  35. */
  36. function testDisplayCheckboxMatrix(){
  37. ob_start();
  38. $permission_array=array();
  39. $tool='';
  40. $permission=1;
  41. $inherited_permissions=array();
  42. $res = display_checkbox_matrix($permission_array, $tool, $permission, $inherited_permissions);
  43. $this->assertTrue(is_null($res));
  44. ob_end_clean();
  45. //var_dump($res);
  46. }
  47. /**
  48. * This function displays a checked or unchecked image. The image will be checked if the
  49. * user, group or role has the permission for the given tool, unchecked if the user, group or role
  50. * does not have the right
  51. * @param $permission_array the array that contains all the permissions of the user, group, role
  52. * @param $tool the tool we want to check a permission for
  53. * @param $permission the permission we want to check for
  54. */
  55. function testDisplayImageMatrix(){
  56. //ob_start();
  57. $permission_array=array();
  58. $tool=1;
  59. $permission=1;
  60. $inherited_permissions=array($tool => array());
  61. $course_admin=false;
  62. $editable=true;
  63. $res = display_image_matrix($permission_array, $tool, $permission,$inherited_permissions, $course_admin, $editable);
  64. $this->assertTrue(is_null($res));
  65. //ob_end_clean();
  66. //var_dump($res);
  67. }
  68. /**
  69. * Slightly modified: Toon Keppens
  70. * This function displays a checked or unchecked image. The image will be checked if the
  71. * user, group or role has the permission for the given tool, unchecked if the user, group or role
  72. * does not have the right
  73. * @param int
  74. * @param string
  75. * @param string
  76. * @param array
  77. * @param bool
  78. */
  79. function testDisplayImageMatrixForBlogs(){
  80. $permission_array=array();
  81. $user_id=1;
  82. $tool=1;
  83. $permission=1;
  84. $inherited_permissions=array();
  85. $course_admin=false;
  86. $editable=true;
  87. $res = display_image_matrix_for_blogs($permission_array, $user_id, $tool, $permission,$inherited_permissions, $course_admin, $editable);
  88. $this->assertTrue(is_null($res));
  89. //var_dump($res);
  90. }
  91. /**
  92. * This function displays a list off all the roles of the course (and those defined by the platform admin)
  93. * @param
  94. * @param
  95. */
  96. function testDisplayRoleList(){
  97. $current_course_roles='';
  98. $current_platform_roles='';
  99. $res = display_role_list($current_course_roles, $current_platform_roles);
  100. $this->assertTrue(is_null($res));
  101. //var_dump($res);
  102. }
  103. /**
  104. * This function gets all the current roles of the user or group
  105. * @param string
  106. * @return array that contains the name of the roles the user has
  107. */
  108. function testGetAllRoles(){
  109. $content='course';
  110. $res = get_all_roles($content);
  111. if (!is_null($res)){
  112. $this->assertTrue(is_array($res));
  113. }
  114. //var_dump($res);
  115. }
  116. /**
  117. * This function retrieves the existing permissions of a user, group or role.
  118. * @param $content are we retrieving the rights of a user, a group or a role (the database depends on it)
  119. * @param $id the id of the user, group or role
  120. */
  121. function testGetPermissions(){
  122. $content='user';
  123. $id=1;
  124. $res = get_permissions($content, $id);
  125. $this->assertTrue(is_array($res));
  126. //var_dump($res);
  127. }
  128. /**
  129. * This function gets all the current roles of the user or group
  130. * @param $content are we finding the roles for a user or a group (the database depends on it)
  131. * @param $id the id of the user or group
  132. * @return array that contains the name of the roles the user has
  133. */
  134. function testGetRoles(){
  135. $content='user';
  136. $id=1;
  137. $scope='course';
  138. $res = get_roles($content, $id, $scope);
  139. $this->assertTrue(is_array($res));
  140. //var_dump($res);
  141. }
  142. /**
  143. * This function gets all the roles that are defined
  144. * @param $content are we finding the roles for a user or a group (the database depends on it)
  145. * @param $id the id of the user or group
  146. * @param string Deprecated parameter allowing use of 'platform' scope - the corresponding tables don't exist anymore so the scope is always set to 'course'
  147. * @return array that contains the name of the roles the user has
  148. */
  149. function testGetRolesPermissions(){
  150. $content='user';
  151. $id=1;
  152. $scope='course';
  153. $res = get_roles_permissions($content, $id, $scope);
  154. if (!is_null($res)){
  155. $this->assertTrue(is_array($res));
  156. }
  157. //var_dump($res);
  158. }
  159. /**
  160. * the array that contains the current permission a user, group or role has will now be changed depending on
  161. * the Dokeos Config Setting for the permissions (limited [add, edit, delete] or full [view, add, edit, delete, move, visibility]
  162. * @param $content are we retrieving the rights of a user, a group or a role (the database depends on it)
  163. * @param $id the id of the user, group or role
  164. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  165. * @version 1.0
  166. * @todo currently there is a setting user_permissions and group_permissions. We should merge this in one config setting.
  167. */
  168. function testLimitedOrFull(){
  169. $current_permissions=array();
  170. $res = limited_or_full($current_permissions);
  171. if (!is_null($res)){
  172. $this->assertTrue(is_array($res));
  173. }
  174. //var_dump($res);
  175. }
  176. function testMyPrintR(){
  177. ob_start();
  178. $array='';
  179. $res = my_print_r($array);
  180. $this->assertTrue(is_null($res));
  181. ob_end_clean();
  182. //var_dump($res);
  183. }
  184. /**
  185. * This function merges permission arrays. Each permission array has the following structure
  186. * a permission array has a tool contanst as a key and an array as a value. This value array consists of all the permissions that are granted in that tool.
  187. */
  188. function testPermissionArrayMerge(){
  189. $array1=array();
  190. $array2=array();
  191. $res = permission_array_merge($array1, $array2);
  192. $this->assertTrue(is_array($res));
  193. //var_dump($res);
  194. }
  195. /**
  196. * This function stores one permission in the correct table.
  197. * @param $content are we storing rights for a user, a group or a role (the database depends on it)
  198. * @param $action are we granting or revoking a permission?
  199. * @param $id the id of the user, group or role
  200. * @param $tool the tool
  201. * @param $permission the permission the user, group or role has been granted or revoked
  202. */
  203. function testStoreOnePermission(){
  204. $res = store_one_permission('user', 'grant', 2, 'link','');
  205. if(!$res === NULL){
  206. $this->assertTrue(is_string($res));
  207. } else {
  208. $this->assertNull($res);
  209. }
  210. //var_dump($res);
  211. }
  212. /**
  213. * This function stores the permissions in the correct table.
  214. * Since Checkboxes are used we do not know which ones are unchecked.
  215. * That's why we first delete them all (for the given user/group/role
  216. * and afterwards we store the checked ones only.
  217. * @param $content are we storing rights for a user, a group or a role (the database depends on it)
  218. * @param $id the id of the user, group or role
  219. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  220. * @version 1.0
  221. */
  222. function testStorePermissions(){
  223. $content='user';
  224. $id=1;
  225. $res = store_permissions($content, $id);
  226. $this->assertTrue(is_string($res));
  227. //var_dump($res);
  228. }
  229. }
  230. ?>