groupmanager.lib.test.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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 testGetAllTutors(){
  346. $res =GroupManager::get_all_tutors();
  347. $this->assertTrue(is_array($res));
  348. //var_dump($res);
  349. }
  350. public function testIsTutor(){
  351. global $user_id, $_course;
  352. $res = GroupManager::is_tutor($user_id);
  353. $this->assertTrue(is_bool($res));
  354. $this->assertTrue($res === false);
  355. //var_dump($res);
  356. }
  357. public function testGetGroupIds(){
  358. global $user_id;
  359. $course_db= 'chamilo_COURSETEST';
  360. $res = GroupManager::get_group_ids($course_db,$user_id);
  361. $this->assertTrue(is_array($res));
  362. //var_dump($res);
  363. }
  364. public function testGetCompleteListOfUsersThatCanBeAddedToGroup(){
  365. global $_course, $_user;
  366. $course_code= 'chamilo_COURSETEST';
  367. $group_id=2;
  368. $res = GroupManager::get_complete_list_of_users_that_can_be_added_to_group($course_code, $group_id);
  369. $this->assertTrue(is_array($res));
  370. $this->assertTrue($res);
  371. //var_dump($res);
  372. }
  373. public function testfilter_duplicates(){
  374. $user_array_in = '';
  375. $compare_field = '';
  376. $res = GroupManager::filter_duplicates($user_array_in, $compare_field);
  377. $this->assertTrue(is_array($res));
  378. //var_dump($res);
  379. }
  380. public function testFilterUsersAlreadyInGroup(){
  381. global $_course;
  382. $user_array_in = array();
  383. $group_id = 2;
  384. $res = GroupManager::filter_users_already_in_group($user_array_in, $group_id);
  385. $this->assertTrue(is_null($res));
  386. $this->assertNull($res);
  387. //var_dump($res);
  388. }
  389. public function testFilterOnlyStudents(){
  390. $user_array_in=array();
  391. $res= GroupManager::filter_only_students($user_array_in);
  392. $this->assertTrue(is_array($res));
  393. //var_dump($res);
  394. }
  395. public function testUserHasAccess(){
  396. global $user_id;
  397. $group_id='5';
  398. $tool='wiki_state';
  399. $res = GroupManager::user_has_access($user_id, $group_id, $tool);
  400. $this->assertTrue(is_bool($res));
  401. $this->assertTrue($res === false);
  402. //var_dump($res);
  403. }
  404. public function testGetUserGroupName(){
  405. global $user_id;
  406. $res=GroupManager::get_user_group_name($user_id);
  407. $this->assertTrue(is_array($res));
  408. //var_dump($res);
  409. }
  410. /*
  411. public function TestDeleteCourse(){
  412. $code = 'COURSETEST';
  413. $res = CourseManager::delete_course($code);
  414. $path = api_get_path(SYS_PATH).'archive';
  415. if ($handle = opendir($path)) {
  416. while (false !== ($file = readdir($handle))) {
  417. if (strpos($file,$code)!==false) {
  418. if (is_dir($path.'/'.$file)) {
  419. rmdirr($path.'/'.$file);
  420. }
  421. }
  422. }
  423. closedir($handle);
  424. }
  425. }
  426. */
  427. }
  428. ?>