groupmanager.lib.test.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. <?php
  2. require_once(api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  3. require_once(api_get_path(LIBRARY_PATH).'database.lib.php');
  4. require_once(api_get_path(LIBRARY_PATH).'course.lib.php');
  5. require_once(api_get_path(LIBRARY_PATH).'classmanager.lib.php');
  6. require_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  7. require_once(api_get_path(LIBRARY_PATH).'fileManage.lib.php');
  8. //require_once(api_get_path(LIBRARY_PATH).'tablesort.lib.php');moved to autoload
  9. class TestGroupManager extends UnitTestCase {
  10. public function __construct() {
  11. $this->UnitTestCase('Group manager library - main/inc/lib/groupmanager.lib.test.php');
  12. TestManager::create_test_course('COURSEGROUP');
  13. }
  14. public function __destruct() {
  15. TestManager::delete_test_course('COURSEGROUP');
  16. }
  17. /**
  18. * Tests about groupmanager csv using many class database, class manager,
  19. * file manager, course manager and table sort.
  20. * @author Ricardo Rodriguez Salazar
  21. */
  22. public function testGetGroupList(){
  23. global $_user;
  24. $res = GroupManager::get_group_list();
  25. $this->assertTrue(is_array($res));
  26. }
  27. public function testCreateGroupIsNumeric(){
  28. $name='1';
  29. $category_id='1';
  30. $tutor='';
  31. $places='1';
  32. global $_course, $_user;
  33. $res = GroupManager::create_group($name, $category_id, $tutor, $places);
  34. $this->assertTrue(is_numeric($res));
  35. $this->assertTrue($res > 0);
  36. }
  37. public function testCreateSubgroups(){
  38. global $_course;
  39. $group_id = 1;
  40. $number_of_groups = 2;
  41. $res = GroupManager::create_subgroups($group_id, $number_of_groups);
  42. $this->assertTrue(is_null($res));
  43. //var_dump($res);
  44. }
  45. public function testCreateGroupsFromVirtualCourses(){
  46. $res = GroupManager::create_groups_from_virtual_courses();
  47. $this->assertTrue($res);
  48. $this->assertTrue(is_array($res));
  49. //var_dump($res);
  50. }
  51. public function testCreateClassGroups(){
  52. $category_id=2;
  53. $res =GroupManager::create_class_groups($category_id);
  54. $this->assertTrue(is_array($res));
  55. //var_dump($res);
  56. }
  57. public function testDeleteGroups(){
  58. $group_ids='01';
  59. $course_code=null;
  60. $res =GroupManager::delete_groups($group_ids, $course_code = null);
  61. $this->assertTrue(is_numeric($res));
  62. //var_dump($res);
  63. }
  64. public function testGetGroupProperties(){
  65. $group_id=01;
  66. $res = GroupManager::get_group_properties($group_id);
  67. $this->assertTrue($res);
  68. $this->assertTrue(is_array($res));
  69. //var_dump($res);
  70. }
  71. public function testSetGroupProperties()
  72. {
  73. $group = array(
  74. 'group_id'=>'01',
  75. 'name'=>'1',
  76. 'description'=>'',
  77. 'maximum_number_of_students'=>'2',
  78. 'doc_state' =>'',
  79. 'work_state' =>'',
  80. 'calendar_state' =>'',
  81. 'announcements_state'=>'',
  82. 'forum_state'=>'',
  83. 'wiki_state'=>'',
  84. 'chat_state' =>'',
  85. 'self_registration_allowed'=>'',
  86. 'self_unregistration_allowed'=>'',
  87. 'category_id' => null
  88. );
  89. $res = GroupManager::set_group_properties(
  90. $group['group_id'],
  91. $group['name'],
  92. $group['description'],
  93. $group['maximum_number_of_students'],
  94. $group['doc_state'],
  95. $group['work_state'],
  96. $group['calendar_state'],
  97. $group['announcements_state'],
  98. $group['forum_state'],
  99. $group['wiki_state'],
  100. $group['chat_state'],
  101. $group['self_registration_allowed'],
  102. $group['self_unregistration_allowed'],
  103. $group['category_id']
  104. );
  105. $this->assertTrue(is_bool($res));
  106. //var_dump($res);
  107. }
  108. public function testGetNumberOfGroups(){
  109. $res = GroupManager::get_number_of_groups();
  110. $this->assertTrue(($res));
  111. $this->assertTrue(is_string($res));
  112. //var_dump($res);
  113. }
  114. public function testGetCategories(){
  115. $course_code ='COURSETEST';
  116. $course_db = 'chamilo_COURSETEST';
  117. $res = GroupManager::get_categories($course_code);
  118. $this->assertTrue(is_array($res));
  119. //var_dump($res);
  120. }
  121. public function testGetCategory(){
  122. $id =2;
  123. $course_code = 'COURSETEST';
  124. $res = GroupManager::get_category($id,$course_code);
  125. $this->assertTrue(is_array($res));
  126. $this->assertTrue($res);
  127. //var_dump($res);
  128. }
  129. public function testGetCategoryFromGroup(){
  130. $course_code='COURSETEST';
  131. $group_id= 1;
  132. $course_db = 'chamilo_COURSETEST';
  133. $resu = GroupManager::get_category_from_group($group_id,$course_code);
  134. $this->assertTrue(is_bool($resu));
  135. //var_dump($res);
  136. //var_dump($cat);
  137. }
  138. public function testDeleteCategory(){
  139. $cat_id=1;
  140. $course_code = 'COURSETEST';
  141. $course_db = 'chamilo_COURSETEST';
  142. $res = GroupManager::delete_category($cat_id, $course_code);
  143. $this->assertTrue(is_null($res));
  144. $this->assertNull($res);
  145. //var_dump($res);
  146. }
  147. public function testCreateCategory(){
  148. $categ = array(
  149. 'title'=>'group test',
  150. 'description'=>'description test',
  151. 'doc_state'=> 1,
  152. 'work_state'=> 1,
  153. 'calendar_state'=> 1,
  154. 'announcements_state' => 1,
  155. 'forum_state' => 1,
  156. 'wiki_state' => 1,
  157. 'chat_state' => 1,
  158. 'self_registration_allowed' => TRUE,
  159. 'self_unregistration_allowed' => FALSE,
  160. 'maximum_number_of_students'=> 2,
  161. 'groups_per_user'=>4);
  162. $res = GroupManager::create_category($categ['title'], $categ['description'],
  163. $categ['doc_state'], $categ['work_state'], $categ['calendar_state'],
  164. $categ['announcements_state'], $categ['forum_state'],$categ['wiki_state'],
  165. $categ['chat_state'],$categ['self_registration_allowed'],$categ['self_unregistration_allowed'],
  166. $categ['maximum_number_of_students'],$categ['groups_per_user']);
  167. $this->assertTrue(is_numeric($res));
  168. //var_dump($res);
  169. }
  170. public function testUpdateCategory(){
  171. $categ = array(
  172. 'id'=>2,
  173. 'title'=>'DefaultGroupCategory',
  174. 'description'=>'xxxxx',
  175. 'doc_state'=>'xxxx',
  176. 'work_state'=>'xxxxx',
  177. 'calendar_state'=>'',
  178. 'announcements_state'=>'',
  179. 'forum_state'=>'',
  180. 'wiki_state'=>'',
  181. 'chat_state' =>'',
  182. 'self_registration_allowed'=>'',
  183. 'self_unregistration_allowed'=>'',
  184. 'maximum_number_of_students'=>'',
  185. 'groups_per_user'=>'0');
  186. $res = GroupManager::update_category($categ['id'], $categ['title'], $categ['description'],
  187. $categ['doc_state'], $categ['work_state'], $categ['calendar_state'], $categ['announcements_state'],
  188. $categ['forum_state'],$categ['wiki_state'], $categ['chat_state'],$categ['self_registration_allowed'],$categ['self_unregistration_allowed'],
  189. $categ['maximum_number_of_students'],$categ['groups_per_user']);
  190. $this->assertTrue(is_null($res));
  191. $this->assertTrue($res ===null);
  192. }
  193. public function testGetCurrenMaxGroupsPerUser(){
  194. $category_id = 2;
  195. $course_code = 'COURSEGROUP';
  196. $res =GroupManager::get_current_max_groups_per_user($category_id = null, $course_code = null);
  197. $this->assertTrue(is_Null($res));
  198. }
  199. public function testSwapCategoryOrder(){
  200. $id1= 1;
  201. $id2= 3;
  202. $res = GroupManager::swap_category_order($id1,$id2);
  203. $this->assertFalse($res);
  204. $this->assertNull($res,true);
  205. }
  206. public function testGetUsers(){
  207. $group_id= 1;
  208. $res =GroupManager::get_users($group_id);
  209. $this->assertTrue(is_array($res));
  210. $this->assertTrue($res ===array());
  211. }
  212. public function testFillGroups(){
  213. global $_course;
  214. $group_ids= 2;
  215. $res = GroupManager::fill_groups($group_ids);
  216. $this->assertNull($res);
  217. $this->assertEqual($res,0);
  218. }
  219. public function testNumberOfStudents(){
  220. global $_course;
  221. $group_id= 2;
  222. $res = GroupManager::number_of_students($group_id);
  223. $this->assertFalse($res);
  224. $this->assertTrue(is_string($res));
  225. //var_dump($res);
  226. }
  227. public function testMaximumNumberOfStudents(){
  228. global $_course;
  229. $group_id = 2;
  230. $res =GroupManager::maximum_number_of_students($group_id);
  231. $this->assertTrue($res);
  232. $this->assertTrue(is_string($res));
  233. //var_dump($res);
  234. }
  235. public function testUserInNumberOfGroups(){
  236. global $_course;
  237. $user_id= 1;
  238. $cat_id = 6;
  239. $res = GroupManager::user_in_number_of_groups($user_id,$cat_id);
  240. $this->assertTrue(is_numeric($cat_id));
  241. $this->assertTrue(is_string($res));
  242. //var_dump($res);
  243. }
  244. public function testIsSelfRegistrationAllowed(){
  245. $user_id = 1;
  246. $group_id = 6;
  247. $res = GroupManager::is_self_registration_allowed($user_id,$group_id);
  248. $this->assertTrue(is_bool($res));
  249. $this->assertTrue($res === false);
  250. //var_dump($res);
  251. }
  252. public function testIsSelfUnregistrationAllowed(){
  253. $user_id = 2 ;
  254. $group_id = 6;
  255. $res =GroupManager::is_self_unregistration_allowed($user_id,$group_id);
  256. $this->assertTrue(is_bool($res));
  257. $this->assertTrue($res === false);
  258. //var_dump($res);
  259. }
  260. public function testIsSubscribed(){
  261. $db_result = 2;
  262. $user_id = 2;
  263. $group_id = 6;
  264. $res = GroupManager::is_subscribed($user_id, $group_id);
  265. $this->assertTrue(is_bool($res));
  266. //var_dump($res);
  267. }
  268. public function testCanUserSubscribe(){
  269. global $user_id;
  270. $group_id = 2;
  271. global $_course;
  272. $res = GroupManager::can_user_subscribe($user_id, $group_id);
  273. $this->assertTrue(is_numeric($res));
  274. //var_dump($res);
  275. }
  276. public function testCanUserUnsubscribe(){
  277. global $user_id;
  278. $group_id = 6;
  279. $res = GroupManager::can_user_unsubscribe($user_id, $group_id);
  280. $this->assertTrue(is_bool($res));
  281. $this->assertTrue($res === false);
  282. //var_dump($res);
  283. }
  284. public function testGetSubscribedUsers(){
  285. $group_id = 2;
  286. $res = GroupManager::get_subscribed_users($group_id);
  287. $this->assertTrue(is_array($res));
  288. //var_dump($res);
  289. }
  290. public function testGetSubscribedTutors(){
  291. $group_id = 2;
  292. $res = GroupManager::get_subscribed_tutors($group_id);
  293. $this->assertTrue(is_array($res));
  294. //var_dump($res);
  295. }
  296. public function testSubscribeUsers(){
  297. global $user_ids;
  298. $group_id = 2;
  299. $res = GroupManager::subscribe_users($user_ids, $group_id);
  300. $this->assertTrue(is_numeric($res));
  301. //var_dump($res);
  302. }
  303. public function testSubscribeTutors(){
  304. global $user_id;
  305. $group_id='6';
  306. $res &= GroupManager::subscribe_tutors($user_id, $group_id);
  307. $this->assertTrue(is_numeric($res));
  308. //var_dump($res);
  309. }
  310. public function testUnsubscribeUsers(){
  311. $user_ids = array(5);
  312. $group_id = 5;
  313. $res &= GroupManager::unsubscribe_users($user_ids, $group_id);
  314. $this->assertTrue(is_numeric($res));
  315. //var_dump($res);
  316. }
  317. public function testUnsubscribeAllUsers(){
  318. $group_ids=array(2);
  319. $res = GroupManager::unsubscribe_all_users($group_ids);
  320. $this->assertTrue(is_bool($res));
  321. //var_dump($res);
  322. }
  323. public function testUnsubscribeAllTutors(){
  324. $group_ids =array(6,9,10,11,14,15,16,19);
  325. $res = GroupManager::unsubscribe_all_tutors($group_ids);
  326. $this->assertTrue(is_bool($res));
  327. //var_dump($res);
  328. }
  329. public function testIsTutorOfGroup(){
  330. global $user_id;
  331. $group_id=2;
  332. $res = GroupManager::is_tutor_of_group($user_id,$group_id);
  333. $this->assertTrue(is_bool($res));
  334. //var_dump($res);
  335. }
  336. public function testIsUserInGroup(){
  337. global $user_id;
  338. $group_id= 4;
  339. $res =GroupManager::is_user_in_group($user_id, $group_id);
  340. $this->assertTrue(is_bool($res));
  341. $this->assertTrue($res === false);
  342. $this->assertFalse($res);
  343. //var_dump($res);
  344. }
  345. public function testGetGroupIds(){
  346. global $user_id;
  347. $course_db= 'chamilo_COURSETEST';
  348. $res = GroupManager::get_group_ids($course_db,$user_id);
  349. $this->assertTrue(is_array($res));
  350. //var_dump($res);
  351. }
  352. public function testGetCompleteListOfUsersThatCanBeAddedToGroup(){
  353. global $_course, $_user;
  354. $course_code= 'chamilo_COURSETEST';
  355. $group_id=2;
  356. $res = GroupManager::get_complete_list_of_users_that_can_be_added_to_group($course_code, $group_id);
  357. $this->assertTrue(is_array($res));
  358. $this->assertTrue($res);
  359. //var_dump($res);
  360. }
  361. public function testfilter_duplicates(){
  362. $user_array_in = '';
  363. $compare_field = '';
  364. $res = GroupManager::filter_duplicates($user_array_in, $compare_field);
  365. $this->assertTrue(is_array($res));
  366. //var_dump($res);
  367. }
  368. public function testFilterUsersAlreadyInGroup(){
  369. global $_course;
  370. $user_array_in = array();
  371. $group_id = 2;
  372. $res = GroupManager::filter_users_already_in_group($user_array_in, $group_id);
  373. $this->assertTrue(is_null($res));
  374. $this->assertNull($res);
  375. //var_dump($res);
  376. }
  377. public function testFilterOnlyStudents(){
  378. $user_array_in=array();
  379. $res= GroupManager::filter_only_students($user_array_in);
  380. $this->assertTrue(is_array($res));
  381. //var_dump($res);
  382. }
  383. public function testUserHasAccess(){
  384. global $user_id;
  385. $group_id='5';
  386. $tool='wiki_state';
  387. $res = GroupManager::user_has_access($user_id, $group_id, $tool);
  388. $this->assertTrue(is_bool($res));
  389. $this->assertTrue($res === false);
  390. //var_dump($res);
  391. }
  392. public function testGetUserGroupName(){
  393. global $user_id;
  394. $res=GroupManager::get_user_group_name($user_id);
  395. $this->assertTrue(is_array($res));
  396. //var_dump($res);
  397. }
  398. /*
  399. public function TestDeleteCourse(){
  400. $code = 'COURSETEST';
  401. $res = CourseManager::delete_course($code);
  402. $path = api_get_path(SYS_PATH).'archive';
  403. if ($handle = opendir($path)) {
  404. while (false !== ($file = readdir($handle))) {
  405. if (strpos($file,$code)!==false) {
  406. if (is_dir($path.'/'.$file)) {
  407. rmdirr($path.'/'.$file);
  408. }
  409. }
  410. }
  411. closedir($handle);
  412. }
  413. }
  414. */
  415. }
  416. ?>