main_api.lib.test.php 19 KB

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