usermanager.lib.test.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <?php
  2. //require_once('../../../simpletest/autorun.php');
  3. require_once (api_get_path(LIBRARY_PATH).'urlmanager.lib.php');
  4. require_once(api_get_path(LIBRARY_PATH).'usermanager.lib.php');
  5. class TestUserManager extends UnitTestCase {
  6. public function __construct() {
  7. $this->UnitTestCase('User Manager library - main/inc/lib/usermanager.lib.test.php');
  8. }
  9. public function testCreateUser() {
  10. $firstName='test_first';
  11. $lastName='test_last';
  12. $status='1';
  13. $email='test@chamilo.org';
  14. $loginName='testlogin';
  15. $password='testlogin';
  16. $official_code='testcode';
  17. $language='english';
  18. $phone = '';
  19. $picture_uri ='';
  20. global $_user;
  21. ob_start();
  22. $res= ob_get_contents();
  23. UserManager::create_user($firstName, $lastName, $status, $email, $loginName, $password, $official_code, $language, $phone, $picture_uri);
  24. ob_end_clean();
  25. $this->assertTrue(is_string($res));
  26. }
  27. /*
  28. function testDeleteUserReturnsTrue() {
  29. $user = array('username' => 'ywarnier',
  30. 'pass' => 'ywarnier',
  31. 'firstname' => 'Yannick',
  32. 'lastname' => 'Warnier',
  33. 'status' => 6,
  34. 'auth_source' => 'platform',
  35. 'email' => 'yannick.warnier@testdokeos.com',
  36. 'creator_id' => 1,
  37. 'active' => 1,
  38. );
  39. $res = UserManager::create_user($user['firstname'],$user['lastname'],$user['status'],$user['email'],$user['username'],$user['pass'],null,null,null,null,$user['auth_source'],null,$user['active']);
  40. $res = UserManager::delete_user($res);
  41. $this->assertTrue($res);
  42. }
  43. */
  44. function testDeleteUser() {
  45. $user_id='';
  46. $res = UserManager::delete_user($user_id);
  47. $this->assertTrue(is_bool($res));
  48. $_configuration['user_id']='';
  49. $res1= UserManager::delete_user($_configuration['user_id']);
  50. $this->assertTrue(is_bool($res1));
  51. //var_dump($res1);
  52. }
  53. /*
  54. function testUpdateUser() {
  55. $user = array('username' => 'ywarnier',
  56. 'pass' => 'ywarnier',
  57. 'firstname' => 'Yannick',
  58. 'lastname' => 'Warnier',
  59. 'status' => 6,
  60. 'auth_source' => 'platform',
  61. 'email' => 'yannick.warnier@testdokeos.com',
  62. 'creator_id' => 1,
  63. 'active' => 1,
  64. );
  65. $update = array('user_id'=>'12',
  66. 'firstname'=>'Ricardo',
  67. 'lastname'=>'Rodriguez',
  68. 'username'=>'richi',
  69. 'email'=>'xxxx@xxxx.com',
  70. 'status'=>6,
  71. 'official_code'=>'2121',
  72. 'phone'=>'',
  73. 'picture_uri'=>'',
  74. 'expiration_date'=>'',
  75. 'active'=>1
  76. );
  77. $res = UserManager::create_user($user['firstname'],$user['lastname'],$user['status'],$user['email'],$user['username'],$user['pass'],null,null,null,null,$user['auth_source'],null,$user['active']);
  78. $this->assertTrue(is_bool($res));
  79. $res = UserManager::update_user($update['user_id'],$update['firstname'],$update['lastname'],$update['username'],null,null,$update['email'],$update['status'],$update['official_code'],$update['phone'],
  80. $update['picture_uri'],$update['expiration_date'],$update['active'],null,null,null,null);
  81. $this->assertTrue($res);
  82. $res=UserManager::delete_user($res);
  83. $this->assertTrue(is_bool($res));
  84. }*/
  85. /*
  86. function testCreateExtraField() {
  87. $extra = array('fieldvarname' =>'nuevo campo',
  88. 'fieldtype' => '2',
  89. 'fieldtitle' => 'english',
  90. 'fielddefault' => 'default'
  91. );
  92. $res = UserManager::create_extra_field($extra['fieldvarname'],$extra['fieldtype'],$extra['fieldtitle'],$extra['fielddefault'],null);
  93. $this->assertTrue('/\d/',$res);
  94. }*/
  95. function testCreateExtraField() {
  96. $fieldvarname='nuevo campo';
  97. $fieldtype='1';
  98. $fieldtitle='english';
  99. $fielddefault='5';
  100. $res=UserManager::create_extra_field($fieldvarname, $fieldtype, $fieldtitle, $fielddefault,null);
  101. //var_dump($res);
  102. $this->assertTrue(is_numeric($fieldtype));
  103. }
  104. function testCanDeleteUser() {
  105. $res=UserManager::can_delete_user(1);
  106. $this->assertTrue(is_bool($res));
  107. }
  108. function testAddApiKey() {
  109. $res=UserManager::add_api_key();
  110. $this->assertTrue(is_bool($res));
  111. }
  112. function testBuildProductionListIsFalse() {
  113. $res = UserManager::build_production_list(1, false, false);
  114. $this->assertFalse($res);
  115. }
  116. function testDeleteApiKey() {
  117. $res=UserManager::delete_api_key(1);
  118. //var_dump($res);
  119. $this->assertTrue(is_bool($res));
  120. }
  121. function testGetApiKeyIdEmptyServiceReturnsFalse() {
  122. $api_service = '';
  123. $res = UserManager::get_api_key_id(1,$api_service);
  124. $this->assertFalse($res);
  125. }
  126. function testGetApiKeyIdNonEmptyServiceWithExtremeUserIdReturnsFalse() {
  127. $api_service = '';
  128. $res = UserManager::get_api_key_id(5000000,$api_service);
  129. $this->assertFalse($res);
  130. }
  131. function testGetApiKeys() {
  132. $res=UserManager::get_api_keys();
  133. $this->assertTrue(is_bool($res));
  134. }
  135. function testGetExtraFieldInformation() {
  136. $res=UserManager::get_extra_field_information(1);
  137. $this->assertTrue(is_array($res));
  138. }
  139. function testGetExtraFieldInformationByName() {
  140. $sql="SELECT 1";
  141. $field_variable=Database::query($sql);
  142. $res=UserManager::get_extra_field_information_by_name($field_variable);
  143. //var_dump($res);
  144. $this->assertTrue(is_bool($res));
  145. }
  146. function testGetEextraFields() {
  147. $res=UserManager::get_extra_fields(0, 0, 5, 'ASC', true);
  148. $this->assertTrue($res);
  149. }
  150. function testGetExtraUserData() {
  151. $res=UserManager::get_extra_user_data(1, null,null,null);
  152. $this->assertTrue(is_array($res),'Somehow there were no visible fields for user 1');
  153. //since Chamilo 1.8.8 we always have 3 visible fields for notifications
  154. }
  155. function testGetExtraUserDataByField() {
  156. $res=UserManager::get_extra_user_data_by_field(1, 'field variable', null,null, null);
  157. $this->assertTrue(is_array($res));
  158. }
  159. function testGetExtraUserDataByValue(){
  160. $res=UserManager::get_extra_user_data_by_value('able', 45, null);
  161. $this->assertTrue(is_array($res));
  162. }
  163. function testGetNumberOfUsers() {
  164. $res=UserManager::get_number_of_users();
  165. $this->assertFalse(!(bool)$res);
  166. }
  167. function testGetPersonalSessionCourseList() {
  168. global $_configuration;
  169. $res=UserManager::get_personal_session_course_list(1);
  170. //var_dump($res);
  171. $this->assertTrue(is_array($res));
  172. }
  173. function testGetPictureUser() {
  174. $res=UserManager::getUserPicture(1, 'unknown.jpg');
  175. $this->assertFalse(!(bool)$res);
  176. }
  177. function testGetUserIdFromUsername() {
  178. $res=UserManager::get_user_id_from_username('arthur3');
  179. $this->assertTrue(!(bool)$res);
  180. }
  181. function testGetUserInfo() {
  182. $res=UserManager::get_user_info('arthur2');
  183. $this->assertTrue(!(bool)$res);
  184. }
  185. function testGetUserList() {
  186. $res=UserManager::get_user_list(null,null);
  187. $this->assertTrue(is_array($res));
  188. }
  189. function testGetUserListLike() {
  190. $res=UserManager::get_user_list_like(null,null);
  191. $this->assertTrue(is_array($res));
  192. }
  193. function testGetUserPicturePathById() {
  194. $id=5;
  195. $res=UserManager::get_user_picture_path_by_id($id,null,null);
  196. $this->assertTrue(is_array($res));
  197. }
  198. function testGetUserProductions() {
  199. $user_id='1';
  200. $res=UserManager::get_user_productions($user_id);
  201. $this->assertFalse(is_array($res===0));
  202. }
  203. function testGetUserUploadFilesByCourse() {
  204. $user_id='1';
  205. $course='MATH';
  206. $res=UserManager::get_user_upload_files_by_course($user_id, $course,null);
  207. $this->assertTrue(is_string($res));
  208. }
  209. function testIsAdmin() {
  210. $user_id=1;
  211. $res=UserManager::is_admin($user_id);
  212. //var_dump($res);
  213. $this->assertTrue(is_bool($res));
  214. }
  215. function testIsExtraFieldAvailable() {
  216. $fieldname='name3';
  217. $res=UserManager::is_extra_field_available($fieldname);
  218. $this->assertFalse(is_string($res));
  219. }
  220. function testIsUsernameAvailable() {
  221. $username='Arthur';
  222. $res=UserManager::is_username_available($username);
  223. $this->assertFalse(is_string($res));
  224. }
  225. function testRemoveUserProductionIsFalseWhenProductionDoesNotExist() {
  226. $user_id=1;
  227. $production='my_files/abc'; //shouldn't exist
  228. $res=UserManager::remove_user_production($user_id,$production);
  229. $this->assertFalse($res);
  230. }
  231. function testResizePictureEmptyPicture() {
  232. $file='';
  233. $max_size_for_picture='';
  234. $res=UserManager::resize_picture($file, $max_size_for_picture);
  235. $this->assertNull($res);
  236. }
  237. function testSendMessageInOutbox() {
  238. $email_administrator='arthur@dokeos.com';
  239. $user_id='1';
  240. $title='hola í';
  241. $content='prueba de este í mensaje';
  242. global $charset;
  243. $res=UserManager::send_message_in_outbox($email_administrator,$user_id,$title, $content);
  244. $this->assertNull($res);
  245. $this->assertTrue(is_null($res));
  246. }
  247. /*
  248. //DEPRECATED
  249. function testSuscribeUsersToSession() {
  250. $id_session=1;
  251. $UserList='';
  252. $res=UserManager::suscribe_users_to_session($id_session,$UserList);
  253. $this->assertTrue(is_null($res));
  254. }
  255. */
  256. function testUpdateApiKey() {
  257. $user_id=121;
  258. $api_service='string';
  259. $res=UserManager::update_api_key($user_id,$api_service);
  260. $this->assertTrue(is_numeric($user_id),is_string($api_service));
  261. $this->assertTrue(is_numeric($res));
  262. $this->assertTrue($this->$res===null);
  263. $this->assertNull(null,$res);
  264. }
  265. function testUpdateExtraFieldValue() {
  266. $user_id='121';
  267. $fname='name';
  268. $res=UserManager::update_extra_field_value($user_id,$fname,null);
  269. $this->assertTrue(is_bool($res));
  270. }
  271. function testUpdateOpenid() {
  272. $user_id='121';
  273. $openid='default';
  274. $res=UserManager::update_openid($user_id, $openid);
  275. $this->assertTrue(is_bool($res));
  276. }
  277. }