usermanager.lib.test.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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 testGetUserList() {
  182. $res=UserManager::get_user_list(null,null);
  183. $this->assertTrue(is_array($res));
  184. }
  185. function testGetUserListLike() {
  186. $res=UserManager::get_user_list_like(null,null);
  187. $this->assertTrue(is_array($res));
  188. }
  189. function testGetUserPicturePathById() {
  190. $id=5;
  191. $res=UserManager::get_user_picture_path_by_id($id,null,null);
  192. $this->assertTrue(is_array($res));
  193. }
  194. function testGetUserProductions() {
  195. $user_id='1';
  196. $res=UserManager::get_user_productions($user_id);
  197. $this->assertFalse(is_array($res===0));
  198. }
  199. function testGetUserUploadFilesByCourse() {
  200. $user_id='1';
  201. $course='MATH';
  202. $res=UserManager::get_user_upload_files_by_course($user_id, $course,null);
  203. $this->assertTrue(is_string($res));
  204. }
  205. function testIsAdmin() {
  206. $user_id=1;
  207. $res=UserManager::is_admin($user_id);
  208. //var_dump($res);
  209. $this->assertTrue(is_bool($res));
  210. }
  211. function testIsExtraFieldAvailable() {
  212. $fieldname='name3';
  213. $res=UserManager::is_extra_field_available($fieldname);
  214. $this->assertFalse(is_string($res));
  215. }
  216. function testIsUsernameAvailable() {
  217. $username='Arthur';
  218. $res=UserManager::is_username_available($username);
  219. $this->assertFalse(is_string($res));
  220. }
  221. function testRemoveUserProductionIsFalseWhenProductionDoesNotExist() {
  222. $user_id=1;
  223. $production='my_files/abc'; //shouldn't exist
  224. $res=UserManager::remove_user_production($user_id,$production);
  225. $this->assertFalse($res);
  226. }
  227. function testResizePictureEmptyPicture() {
  228. $file='';
  229. $max_size_for_picture='';
  230. $res=UserManager::resize_picture($file, $max_size_for_picture);
  231. $this->assertNull($res);
  232. }
  233. function testSendMessageInOutbox() {
  234. $email_administrator='arthur@dokeos.com';
  235. $user_id='1';
  236. $title='hola í';
  237. $content='prueba de este í mensaje';
  238. global $charset;
  239. $res=UserManager::send_message_in_outbox($email_administrator,$user_id,$title, $content);
  240. $this->assertNull($res);
  241. $this->assertTrue(is_null($res));
  242. }
  243. /*
  244. //DEPRECATED
  245. function testSuscribeUsersToSession() {
  246. $id_session=1;
  247. $UserList='';
  248. $res=UserManager::suscribe_users_to_session($id_session,$UserList);
  249. $this->assertTrue(is_null($res));
  250. }
  251. */
  252. function testUpdateApiKey() {
  253. $user_id=121;
  254. $api_service='string';
  255. $res=UserManager::update_api_key($user_id,$api_service);
  256. $this->assertTrue(is_numeric($user_id),is_string($api_service));
  257. $this->assertTrue(is_numeric($res));
  258. $this->assertTrue($this->$res===null);
  259. $this->assertNull(null,$res);
  260. }
  261. function testUpdateExtraFieldValue() {
  262. $user_id='121';
  263. $fname='name';
  264. $res=UserManager::update_extra_field_value($user_id,$fname,null);
  265. $this->assertTrue(is_bool($res));
  266. }
  267. function testUpdateOpenid() {
  268. $user_id='121';
  269. $openid='default';
  270. $res=UserManager::update_openid($user_id, $openid);
  271. $this->assertTrue(is_bool($res));
  272. }
  273. }