main_api.lib.test.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. <?php
  2. use ChamiloSession as Session;
  3. require_once(api_get_path(LIBRARY_PATH).'course.lib.php');
  4. class TestMainApi extends UnitTestCase {
  5. function TestMainApi() {
  6. $this->UnitTestCase('Main API library - main/inc/lib/main_api.lib.test.php');
  7. }
  8. /*
  9. function testApiProtectCourseScript(){
  10. ob_start();
  11. $res= api_protect_course_script($print_headers=null);
  12. ob_get_contents();
  13. $this->assertTrue(is_string($res));
  14. ob_end_clean();
  15. }
  16. function testApiProtectAdminScript(){
  17. ob_start();
  18. $res = api_protect_admin_script($allow_sessions_admins=false);
  19. ob_end_clean();
  20. //$this->assertTrue(is_string($res));
  21. }
  22. function testApiBlockAnonymousUser(){
  23. ob_start();
  24. $res = api_block_anonymous_users();
  25. $this->assertTrue(is_string($res));
  26. ob_end_clean();
  27. }
  28. */
  29. function testApiGetNavigator(){
  30. ob_start();
  31. $res=api_get_navigator();
  32. $this->assertTrue($res);
  33. ob_end_clean();
  34. }
  35. function testApiIsSelfRegistrationAllowed(){
  36. $res = api_is_self_registration_allowed();
  37. $this->assertTrue(is_bool($res));
  38. //var_dump($res);
  39. }
  40. function testApiGetPath() {
  41. $path_type = trim($path_type);
  42. $path = array(
  43. WEB_PATH => '',
  44. SYS_PATH => '',
  45. REL_PATH => '',
  46. WEB_SERVER_ROOT_PATH => '',
  47. SYS_SERVER_ROOT_PATH => '',
  48. WEB_COURSE_PATH => '',
  49. SYS_COURSE_PATH => '',
  50. REL_COURSE_PATH => '',
  51. REL_CODE_PATH => '',
  52. WEB_CODE_PATH => '',
  53. SYS_CODE_PATH => '',
  54. SYS_LANG_PATH => 'lang/',
  55. WEB_IMG_PATH => 'img/',
  56. WEB_CSS_PATH => 'css/',
  57. GARBAGE_PATH => 'archive/', // Deprecated?
  58. SYS_PLUGIN_PATH => 'plugin/',
  59. WEB_PLUGIN_PATH => 'plugin/',
  60. SYS_ARCHIVE_PATH => 'archive/',
  61. WEB_ARCHIVE_PATH => 'archive/',
  62. INCLUDE_PATH => 'inc/',
  63. LIBRARY_PATH => 'inc/lib/',
  64. CONFIGURATION_PATH => 'inc/conf/',
  65. WEB_LIBRARY_PATH => 'inc/lib/',
  66. WEB_AJAX_PATH => 'inc/ajax/'
  67. );
  68. $res=api_get_path($path_type, $path);
  69. $this->assertTrue(is_null($res));
  70. //var_dump($res);
  71. }
  72. function testApiGetUserId(){
  73. $res= api_get_user_id();
  74. $this->assertPattern('/\d/',$res);
  75. }
  76. function testApiGetUserCoursesReturnTrueWhenOutOfCoursesContext(){
  77. global $tbl_user;
  78. $userid=1;
  79. $fetch_session=true;
  80. $res = api_get_user_courses($userid,$fetch_session);
  81. if(!is_null($res)) :
  82. $this->assertTrue(is_array($res));
  83. endif;
  84. //var_dump($res);
  85. }
  86. function testApiGetUserInfoReturnFalseWhenOutOfUserInfoContext(){
  87. $user_id= 1;
  88. $res = api_get_user_info($user_id);
  89. $this->assertTrue(is_array($res));
  90. //var_dump($res);
  91. }
  92. function testApiGetUserInfoUsernameReturnTrueWhenOutOfUserInfoUsernameContext(){
  93. $res=api_get_user_info_from_username();
  94. $this->assertTrue(is_bool($res));
  95. //var_dump($res);
  96. }
  97. /* Causing problems for some reason on automated tests server
  98. function testApiGetCourseIdReturnFalseWhenOutOfCourseIdContext(){
  99. $res = api_get_course_id();
  100. $this->assertEqual($res,-1);
  101. }
  102. function testApiGetCoursePathReturnFalseWhenOutOfCoursePathContext(){
  103. $res = api_get_course_path();
  104. $this->assertTrue(empty($res));
  105. }
  106. */
  107. function testApiGetCourseSettingReturnFalseWhenOutOfCourseSeetingContext(){
  108. global $_course;
  109. $course_code = $_course;
  110. $setting_name = 1;
  111. $res = api_get_course_setting($setting_name, $course_code);
  112. $this->assertTrue($res);
  113. }
  114. function testApiGetAnonymousId(){
  115. $res = api_get_anonymous_id();
  116. $this->assertTrue(is_numeric($res));
  117. }
  118. function testApiGetCidreq(){
  119. $res=api_get_cidreq();
  120. $this->assertTrue(is_string($res));
  121. }
  122. function testApiGetCourseInfo(){
  123. ob_start();
  124. $res=api_get_course_info();
  125. $this->assertTrue($res);
  126. ob_end_clean();
  127. }
  128. // function testApiSessionRegister(){
  129. // $$variable[session_register]=false;
  130. // global $$variable;
  131. // if (!headers_sent()) {
  132. // $res=Session::register($$variable, $$variable);
  133. // }
  134. // $this->assertTrue(is_null($res));
  135. // $this->assertTrue(is_null($variable[session_register]));
  136. // }
  137. function testApiSessionUnregister() {
  138. $variable=strval($variable);
  139. $res=Session::erase($variable);
  140. $this->assertTrue(is_null($res));
  141. $this->assertTrue(is_null($_SESSION[$variable]=null));
  142. }
  143. function testApiSessionClear() {
  144. $variable = 'test';
  145. if (!headers_sent()) {
  146. $res=Session::clear($variable);
  147. }
  148. $this->assertTrue(is_null($res));
  149. //var_dump($res);
  150. }
  151. function testApiSessionDestroy(){
  152. if (!headers_sent()) {
  153. $res=Session::destroy();
  154. }
  155. $this->assertTrue(is_null($res));
  156. //var_dump($res);
  157. }
  158. function testApiAddUrlParamReturnsUrlWhenNoParam() {
  159. global $url;
  160. $res=api_add_url_param($url, null, $filter_xss=true);
  161. $this->assertEqual($res,$url);
  162. }
  163. function testApiGeneratePassword() {
  164. $res = api_generate_password($length = 8);
  165. $this->assertTrue(is_string($res));
  166. //var_dump($res);
  167. }
  168. function testApiCheckPassword(){
  169. $password = '';
  170. $res = api_check_password($password);
  171. $this->assertTrue(is_bool($res));
  172. //var_dump($res);
  173. }
  174. function testApiClearAnonymous(){
  175. global $_user;
  176. $_user['user_id'] = 1;
  177. $res = api_clear_anonymous($db_check=false);
  178. $this->assertTrue(is_bool($res));
  179. //var_dump($res);
  180. $this->assertTrue(isset($_user['user_id'] ));
  181. }
  182. function testApiTruncStr() {
  183. $text= 'test';
  184. $res= api_trunc_str($text, $length = 30, $suffix = '...', $middle = false, $encoding = null);
  185. $this->assertTrue(is_string($res));
  186. }
  187. function testDomesticate(){
  188. $input= 'dome';
  189. $res = domesticate($input);
  190. $this->assertTrue($res);
  191. }
  192. function testGetStatusFromCode(){
  193. $status_code = 1;
  194. $res=get_status_from_code($status_code);
  195. $this->assertTrue($res);
  196. }
  197. function testApiSetFailure(){
  198. global $api_failureList;
  199. $failureType=true;
  200. $res = api_set_failure($failureType);
  201. $this->assertTrue(is_bool($res));
  202. $this->assertTrue($api_failureList);
  203. }
  204. function testApiSetAnonymous(){
  205. $res = api_set_anonymous();
  206. $this->assertTrue(is_bool($res));
  207. }
  208. function testApiGetLastFailure(){
  209. $res= api_Get_last_failure();
  210. $this->assertTrue($res);
  211. }
  212. function testApiGetSessionId(){
  213. $res = api_get_session_id();
  214. $this->assertTrue(is_numeric($res));
  215. //var_dump($res);
  216. }
  217. function testApiGetSessionName(){
  218. $session_id='';
  219. $res = api_get_session_name($session_id);
  220. //$this->assertTrue(is_string($res));
  221. $this->assertTrue(is_null($res));
  222. //var_dump($res);
  223. }
  224. function testAPiGetSetting(){
  225. global $variable, $_setting;
  226. $res=api_get_setting($variable, $key= NULL);
  227. $this->assertTrue(is_null($res));
  228. //var_dump($res);
  229. }
  230. function testApiGetSelf(){
  231. $res = api_get_self();
  232. $this->assertTrue(is_string($res));
  233. //var_dump($res);
  234. }
  235. /* function deprecated
  236. function testGetLang(){
  237. global $language_interface, $language_interface_initial_value, $language_file,$variable;
  238. $res = get_lang($variable, $notrans = 'DLTT', $language = null);
  239. $this->assertTrue(is_string($res));
  240. //var_dump($res);
  241. }
  242. function testGetLangToSystemEncoding(){
  243. global $language, $name;
  244. $res=&get_lang_to_system_encoding(& $string, $language);
  245. ob_start();
  246. api_disp_html_area($name, $content ='', $height='', $width='100%', $optAttrib='');
  247. $res = ob_get_contents();
  248. $this->assertNotEqual($res,'');
  249. ob_end_clean();
  250. }
  251. function testApiGetInterfaceLanguage(){
  252. global $language_interface;
  253. $language_interface=false;
  254. ob_start();
  255. $res = api_get_interface_language();
  256. $res = ob_get_contents();
  257. $this->assertTrue(is_string($res));
  258. $this->assertTrue(isset($language_interface));
  259. ob_end_clean();
  260. //var_dump($res);
  261. }
  262. */
  263. function testApiIsPlatformAdmin(){
  264. ob_start();
  265. global $_user;
  266. $_user['status']=true;
  267. $allow_sessions_admins=true;
  268. $res= api_is_platform_admin($allow_sessions_admins=true);
  269. $this->assertTrue(is_bool($res));
  270. $this->assertTrue($_SESSION['is_platformAdmin']=true);
  271. $this->assertTrue(isset($_user['status']));
  272. ob_end_clean();
  273. //var_dump($res);
  274. }
  275. function testApiIsAllowedToCreateCourse() {
  276. $res=api_is_allowed_to_create_course();
  277. if(!is_bool($res)){
  278. $this->assertTrue(is_null($res));
  279. }
  280. }
  281. function testApiIsCourseAdminIsFalseWhenNoCourseContextDefined() {
  282. $res=api_is_course_admin();
  283. if($_SESSION['is_courseAdmin'] === 1) {
  284. $this->assertTrue($res);
  285. } else {
  286. $this->assertFalse($res);
  287. }
  288. }
  289. function testApiIsCourseCoach() {
  290. $res=api_is_course_coach();
  291. if(!is_bool($res)){
  292. $this->assertTrue(is_null($res));
  293. }
  294. }
  295. function testApiIsCoach(){
  296. global $_user;
  297. global $sessionIsCoach;
  298. $_user['user_id']=2;
  299. $sessionIsCoach=Database::store_result($result=false);
  300. $res=api_is_coach();
  301. $this->assertTrue(is_bool($res));
  302. //var_dump($res);
  303. $this->assertTrue($_user['user_id']);
  304. $this->assertTrue(is_array($sessionIsCoach));
  305. //var_dump($sessionIsCoach);
  306. }
  307. function testApiIsSessionAdmin(){
  308. global $_user;
  309. $_user['status']=true;
  310. $res=api_is_session_admin();
  311. $this->assertTrue(is_bool($res));
  312. $this->assertTrue(is_array($_user));
  313. //var_dump($_user);
  314. }
  315. function testApiDisplayToolTitle(){
  316. $tit=true;
  317. $titleElement['mainTitle']=$tit;
  318. ob_start();
  319. api_display_tool_title($titleElement);
  320. $res = ob_get_contents();
  321. $this->assertEqual($res,'<h3>1</h3>');
  322. $this->assertTrue(isset($titleElement));
  323. $this->assertTrue($titleElement['mainTitle']);
  324. $this->assertPattern('/<h3>1<\/h3>/', $res);
  325. ob_end_clean();
  326. }
  327. /* This test fails but it doesn't say much anyway
  328. function testApiDisplayToolViewOption(){
  329. ob_start();
  330. api_display_tool_view_option();
  331. $res = ob_get_contents();
  332. ob_end_clean();
  333. $this->assertTrue(empty($res));
  334. }
  335. */
  336. function testApiIsAllowedToEdit(){
  337. $is_courseAdmin=false;
  338. $res=api_is_allowed_to_edit($tutor=false,$scoach=false);
  339. $this->assertTrue(is_bool($res));
  340. $this->assertTrue(isset($is_courseAdmin));
  341. }
  342. function testApiIsAllowed(){
  343. global $_course, $_user;
  344. $tool= 'full';
  345. $action = 'delete';
  346. $res=api_is_allowed($tool, $action, $task_id=0);
  347. if(!is_bool($res)){
  348. $this->assertTrue(is_null($res));
  349. }
  350. $this->assertTrue($action);
  351. $this->assertTrue($_user['user_id']);
  352. }
  353. function testApiIsAnonymous(){
  354. global $_user, $use_anonymous;
  355. $_user['is_anonymous']=False;
  356. $res=api_is_anonymous($user_id=null, $db_check=false);
  357. $this->assertTrue(is_bool($res));
  358. $this->assertFalse(isset($user_id));
  359. $this->assertTrue(isset($_user['is_anonymous']));
  360. $this->assertTrue(is_null($use_anonymous));
  361. $this->assertTrue(is_bool($db_check));
  362. //var_dump($db_check);
  363. }
  364. function testApiNotAllowed(){
  365. ob_start();
  366. //api_not_allowed($print_headers = false);
  367. $res = ob_get_contents();
  368. $this->assertEqual($res,'');
  369. ob_end_clean();
  370. }
  371. /*
  372. function testConvertMysqlDate(){
  373. $last_post_datetime = array();
  374. $res=convert_mysql_date($last_post_datetime);
  375. $this->assertTrue($res);
  376. }
  377. */
  378. function testApiGetDatetime(){
  379. $res=api_get_datetime($time=null);
  380. $this->assertTrue($res);
  381. $this->assertFalse(isset($time));
  382. }
  383. function testApiGetItemVisibility(){
  384. global $_course;
  385. $tool = 'document';
  386. $id=1;
  387. $_course['dbName']=false;
  388. $res =api_get_item_visibility($_course,$tool,$id);
  389. $this->assertTrue(is_numeric($res));
  390. $this->assertFalse(is_bool($res));
  391. }
  392. function testApiItemPropertyUpdate(){
  393. global $_course, $tool, $item_id, $lastedit_type, $user_id;
  394. $res=api_item_property_update($_course, $tool, $item_id, $lastedit_type, $user_id, $to_group_id = 0, $to_user_id = NULL, $start_visible = 0, $end_visible = 0);
  395. $this-> assertTrue($res);
  396. }
  397. function testApiGetLanguagesCombo(){
  398. $res=api_get_languages_combo($name="language");
  399. $this->assertTrue($res);
  400. }
  401. function testApiDisplayLanguageForm(){
  402. ob_start();
  403. api_display_language_form($hide_if_no_choice=false);
  404. $res = ob_get_contents();
  405. $this->assertNotEqual($res,'');
  406. ob_end_clean();
  407. }
  408. function testApiGetLanguages(){
  409. $res= api_get_languages();
  410. $this->assertTrue($res);
  411. }
  412. function testApiGetThemes(){
  413. $cssdir= api_get_path(SYS_CSS_PATH);
  414. $res=api_get_themes();
  415. $this->assertTrue($res);
  416. $this->assertTrue($cssdir);
  417. }
  418. function testApiMaxSortValue(){
  419. $user_course_category=1;
  420. $user_id =1;
  421. $res= api_max_sort_value($user_course_category,$user_id);
  422. $this->assertTrue(is_null($res));
  423. //var_dump($res);
  424. }
  425. function testString2Boolean(){
  426. global $string;
  427. $res=api_string_2_boolean($string);
  428. $this->assertFalse($res);
  429. }
  430. function testApiNumberOfPlugins(){
  431. global $_plugins;
  432. $location=2;
  433. $_plugins[$location]=1;
  434. $res=api_number_of_plugins($location);
  435. $this->assertFalse($res);
  436. $this->assertTrue($_plugins[$location]);
  437. }
  438. function testApiTimeToHms(){
  439. $seconds = -1;
  440. ob_start();
  441. api_time_to_hms($seconds);
  442. $res = ob_get_contents();
  443. $this-> assertTrue(is_string($res));
  444. ob_end_clean();
  445. //var_dump($res);
  446. }
  447. public function testApiGetPermissionsForNewDirectories() {
  448. $perm = trim(api_get_setting('permissions_for_new_directories'));
  449. $perm = octdec(!empty($perm) ? $perm : '0777');
  450. $res = api_get_permissions_for_new_directories();
  451. $this->assertTrue($res === $perm);
  452. //var_dump($res);
  453. }
  454. public function testApiGetPermissionsForNewFiles() {
  455. $perm = trim(api_get_setting('permissions_for_new_files'));
  456. $perm = octdec(!empty($perm) ? $perm : '0666');
  457. $res = api_get_permissions_for_new_files();
  458. $this->assertTrue($res === $perm);
  459. //var_dump($res);
  460. }
  461. function testCopyr_file_to_nothing(){
  462. $source = api_get_path(SYS_CODE_PATH).'admin/add_users_to_session.php';
  463. $dest = '';
  464. $res = copyr($source, $dest, $exclude=array(), $copied_files=array());
  465. $this->assertFalse($res,'Function coyr() should have not proceeeded because of empty destination');
  466. //var_dump($res);
  467. }
  468. function testApiGetVersion(){
  469. global $_configuration;
  470. $res = api_get_version();
  471. $this->assertTrue($res);
  472. }
  473. function testApiStatusExists(){
  474. $status_asked = 'user';
  475. $res = api_status_exists($status_asked);
  476. $this->assertTrue(is_bool($res));
  477. }
  478. /* Fails for some reason on automated tests server
  479. function testApiStatusKey(){
  480. $status = 'user';
  481. $res = api_status_key($status);
  482. //var_dump($res);
  483. $this->assertEqual($res,STUDENT);
  484. }
  485. */
  486. function testApiGetStatusLangvars(){
  487. $res = api_get_status_langvars();
  488. $this->assertTrue(is_array($res));
  489. }
  490. function testApiSetSetting(){
  491. ob_start();
  492. $var = 0;
  493. $value = 2;
  494. $res = api_set_setting($var,$value,$subvar=null,$cat=null,$access_url=1);
  495. $this->assertTrue(is_bool($res));
  496. ob_end_clean();
  497. //var_dump($res);
  498. }
  499. function testApiSetSettingsCategory(){
  500. $category = $_GET['category'];
  501. $res = api_set_settings_category($category,$value=null,$access_url=1);
  502. $this->assertTrue(is_null($category));
  503. $this->assertTrue(is_bool($res));
  504. //var_dump($res);
  505. //var_dump($category);
  506. }
  507. function testApiGetAccessUrls(){
  508. $res = api_get_access_urls($from=0,$to=1000000,$order='url',$direction='ASC');
  509. $this->assertTrue(is_array($res));
  510. //var_dump($res);
  511. }
  512. function testApiGetAccessUrl(){
  513. $id=1;
  514. $res = api_get_access_url($id);
  515. $this->assertTrue(is_array($res));
  516. }
  517. function testApiAddAccessUrl(){
  518. $u = Database::escape_string($u);
  519. $d = Database::escape_string($d);
  520. $res = api_add_access_url($u,$d='',$a=1);
  521. $this->assertTrue(is_numeric($res));
  522. //var_dump($res);
  523. }
  524. function testApiGetSettings(){
  525. $res = api_get_settings($cat=null,$ordering='list',$access_url=1,$url_changeable=0);
  526. $this->assertTrue(is_array($res));
  527. //var_dump($res);
  528. }
  529. function testApiGetSettingsCategories(){
  530. $res = api_get_settings_categories($exceptions=array(),$access_url=1);
  531. $this->assertTrue(is_array($res));
  532. //var_dump($res);
  533. }
  534. function testApiDeleteSetting(){
  535. $v = false;
  536. $res = api_delete_setting($v, $s=NULL, $a=1);
  537. $this->assertTrue(is_bool($res));
  538. //var_dump($res);
  539. }
  540. /*
  541. function testApiDeleteCategorySettings(){
  542. $c= false;
  543. $res = api_delete_category_settings($c,$a=1);
  544. $this->assertTrue(is_bool($res));
  545. //var_dump($res);
  546. }
  547. */
  548. function testApiAddSetting(){
  549. $sk=null;
  550. $type='textfield';
  551. $c=null;
  552. $title='';
  553. $com='';
  554. $sc=null;
  555. $skt=null;
  556. $a=1;
  557. $v=0;
  558. $va=array('val'=>10, 'var'=>'name');
  559. $res= api_add_setting($va['val'],$va['var'],null,null,null,null,null,null,null,null,null);
  560. $this->assertTrue(is_bool($res));
  561. //var_dump($res);
  562. }
  563. function testApiIsCourseVisibleForUser() {
  564. global $_user, $cidReq;
  565. $userid = $_user;
  566. $cid = $cidReq ;
  567. $res = api_is_course_visible_for_user($userid, $cid);
  568. $this->assertTrue(is_bool($res));
  569. //var_dump($res);
  570. }
  571. function testApiIsElementInTheSession(){
  572. ob_start();
  573. $_tool['tool'] = 'TOOL_SURVEY';
  574. $_id['element_id']=3;
  575. $res = api_is_element_in_the_session($_tool['tool'], $_id['element_id'], $session_id=null);
  576. $this->assertTrue(is_bool($res));
  577. $this->assertTrue((isset($_tool['tool'],$_id['element_id'])));
  578. ob_end_clean();
  579. //var_dump($res);
  580. }
  581. function testReplaceDangerousChar(){
  582. $filename =ereg_replace("\.+$", "", substr(strtr(ereg_replace(
  583. "[^!-~\x80-\xFF]", "_", trim($filename)), '\/:*?"<>|\'',
  584. /*Keep C1 controls for UTF-8 streams **/ '-----_---_'), 0, 250));
  585. $res = api_replace_dangerous_char($filename, $strict = 'loose');
  586. $this->assertEqual($res,$filename, $message = 'no se pudo');
  587. }
  588. function testApiRequestUri(){
  589. $res = api_request_uri();
  590. $this->assertTrue($res);
  591. }
  592. function testApiGetCurrentAccessUrlId(){
  593. $res=api_get_current_access_url_id();
  594. $this->assertTrue($res);
  595. }
  596. function testApiGetAccessUrlFromUser(){
  597. $user_id=1;
  598. $res= api_get_access_url_from_user($user_id);
  599. $this->assertTrue(is_array($res));
  600. //var_dump($res);
  601. }
  602. function testApiGetStatusOfUserInCourse(){
  603. $id = array(
  604. 'c_id'=>'1',
  605. 'user_id'=>'1');
  606. $res=api_get_status_of_user_in_course($id['user_id'], $id['c_id']);
  607. $this->assertTrue(is_null($res));
  608. //var_dump($res);
  609. }
  610. function testApiIsInCourse(){
  611. $_SESSION['_course']['sysCode']=0;
  612. $res=api_is_in_course($course_code=null);
  613. $this->assertTrue(is_bool($res));
  614. $this->assertTrue(isset($_SESSION['_course']['sysCode']));
  615. //var_dump($res);
  616. }
  617. function testApiIsInGroup(){
  618. $res=api_is_in_group($group_id=null, $course_code=null);
  619. $this->assertTrue(is_bool($res));
  620. //var_dump($res);
  621. }
  622. function testApiIsXmlHttpRequest(){
  623. $res=api_is_xml_http_request();
  624. $this->assertTrue(isset($res));
  625. }
  626. function testApiIsValidSecretKey(){
  627. global $_configuration;
  628. $key = array(
  629. 'original_key_secret'=>'2121212',
  630. 'security_key'=>'2121212');
  631. $res = api_is_valid_secret_key($key['original_key_secret'],$key['security_key']);
  632. $this->assertTrue($_configuration);
  633. $this->assertFalse($res);
  634. $this->assertTrue($key);
  635. $this->assertEqual($key['original_key_secret'],$key['security_key'], $message ='%s');
  636. }
  637. function testApiIsUserOfCourse(){
  638. $course_id = 1;
  639. $user_id = 1;
  640. $tbl_course_rel_user =false;
  641. $sql='SELECT user_id FROM '.$tbl_course_rel_user.' WHERE course_code="'.Database::escape_string($course_id).'" AND user_id="'.Database::escape_string($user_id).'"';
  642. $res= api_is_user_of_course($course_id, $user_id);
  643. $this->assertFalse($res);
  644. $this->assertFalse($tbl_course_rel_user);
  645. $this->assertTrue($sql);
  646. }
  647. function testApiIsWindowsOs(){
  648. $res= api_is_windows_os();
  649. $this->assertTrue(is_bool($res));
  650. //var_dump($res);
  651. }
  652. function testApiResizeImage(){
  653. //global $image, $target_width, $target_height;
  654. $resize = array('image' =>'image.jpg', 'target_width'=>100, 'target_height'=>100);
  655. $res = api_resize_image($resize['image'],$resize['target_width'],$resize['target_height']);
  656. $this->assertTrue(is_array($res));
  657. $this->assertWithinMargin($first = 10, $second=20,$margin=200, $message = 'no se pudo redimensionar imagen');
  658. //var_dump($res);
  659. }
  660. function testApiCalculateImageSize(){
  661. global $image_width, $image_height, $target_width, $target_height;
  662. $result = array($image_width, $image_height);
  663. $res = api_calculate_image_size($image_width, $image_height, $target_width, $target_height);
  664. $this->assertTrue(is_array($res));
  665. $this->assertTrue($result);
  666. //var_dump($res);
  667. }
  668. function testApiGetToolsLists(){
  669. $tool_list = 'false';
  670. $res = api_get_tools_lists($my_tool =null);
  671. $this->assertTrue(is_array($res));
  672. $this->assertTrue($tool_list);
  673. //var_dump($res);
  674. }
  675. public function TestDeleteCourse() {
  676. $code = 'COURSETEST';
  677. $res = CourseManager::delete_course($code);
  678. $path = api_get_path(SYS_PATH).'archive';
  679. if ($handle = opendir($path)) {
  680. while (false !== ($file = readdir($handle))) {
  681. if (strpos($file,$code)!==false) {
  682. if (is_dir($path.'/'.$file)) {
  683. rmdirr($path.'/'.$file);
  684. }
  685. }
  686. }
  687. closedir($handle);
  688. }
  689. }
  690. }
  691. ?>