main_api.lib.test.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  1. <?php //$id:$
  2. class TestMainApi extends UnitTestCase {
  3. function TestMainApi() {
  4. $this->UnitTestCase('Main API tests');
  5. }
  6. // todo function testApiProtectCourseScriptReturnsFalse()
  7. // todo function testApiProtectAdminScriptReturnsFalse()
  8. // todo function testApiBlockAnonymousUsers()
  9. // todo function testApiGetNavigatorReturnArray($name,$version)
  10. // todo function testApiIsSelfRegistrationAllowedReturnTrue()
  11. // todo function testApiGetPathReturnString()
  12. // todo function testApiGetUserIdReturnInteger()
  13. // todo function testApiGetUserCoursesReturnArray()
  14. // todo function testApiGetUserInfoReturnArray($user_id)
  15. // todo function testApiGetUserInfoFromUsernameReturnArray($username)
  16. // todo function testApiGetCourseIdReturnInteger()
  17. // todo function testApiGetCoursePath()
  18. // todo function testApiGetCourseSetting()
  19. // todo function testApiGetAnonymousIdReturnInt()
  20. // todo function testApiGetCidreq()
  21. // todo function testApiGetCourseInfoReturnString()
  22. // todo function testApiSqlQuery()
  23. // todo function testApiStoreResultReturnArray()
  24. // todo function testApiSessionStartReturnTrue()
  25. // todo function testApiSessionRegister()
  26. // todo function testApiSessionUnregister()
  27. // todo function testApiSessionClearReturnArray()
  28. // todo function testApiSessionDestroyReturnArray()
  29. // todo function testApiAdd_UrlParamReturnString()
  30. // todo function testApiGeneratePasswordReurnPassword()
  31. // todo function testApiCheckPasswordReturnTrue()
  32. // todo function testApiClearAnonymousReturnFalse()
  33. // todo function testApiTruncStr()
  34. // todo function testDomesticate
  35. // todo function testGetStatusFromCodeReturnString()
  36. // todo function testApiSetFailureReturnFalse()
  37. // todo function testApiSetAnonymousReturnTrue()
  38. // todo function testGetLastFailureRetunrString()
  39. // todo function testApiGetSessionIdReturnInt()
  40. // todo function testApiGetSessionNameReturnString()
  41. // todo function testApiGetSelfReturnRightValue()
  42. // todo function testGetLangReturnRightValue()
  43. // todo function testApiGetInterfaceLanguageReturnString()
  44. // todo function testApiIsPlatformAdminReturnTrue()
  45. // todo function testApiIsAllowedToCreateCourseReturnTrue()
  46. // todo function testApiIsCourseAdminRetunTrue()
  47. // todo function testApiIsCourseCoachReturnTrue()
  48. // todo function testApiIsCourseTutorReturnTrue()
  49. // todo function testApiIsCoachReturnTrue()
  50. // todo function testApiIsSessionAdminReturnTrue()
  51. // todo function testApiDisplayToolTitle($titleElement)
  52. // todo function testApiDisplayToolViewOption()
  53. // todo function testApiDisplayArray()
  54. // todo function testApiDisplayDebugInfo()
  55. // todo function testApiIsAllowedToEdit()
  56. // todo function testApiIsAllowed()
  57. // todo function testApiIsAnonymous()
  58. // todo function testApiNotAllowed()
  59. // todo function testConvertMysqlDate()
  60. // todo function testApiGetDatetime()
  61. // todo function testApiGetItemVisibility()
  62. // todo function testApiItemPropertyUpdate()
  63. // todo function testApiGetLanguagesCombo()
  64. // todo function testApiDisplayLanguageForm()
  65. // todo function testApiGetLanguages()
  66. // todo function testApiGetLanguageIsocode()
  67. // todo function testApiGetThemesReturnArray()
  68. // todo function testApiDispHtmlArea()
  69. // todo function testApiReturnHtmlArea()
  70. // todo function testApiSendMail()
  71. // todo function testApiMaxSortValue()
  72. // todo function testString2Boolean()
  73. // todo function testApiNumberOfPlugins()
  74. // todo function testApiPlugin()
  75. // todo function testApiIsPluginInstalled()
  76. // todo function testApiParseTex()
  77. // todo function testApiTimeToHms()
  78. // todo function testCopyr()
  79. // todo function testApiChmodR()
  80. // todo function testApiGetVersionReturnString()
  81. // todo function testApiStatusExistsReturnTrue()
  82. // todo function testApiStatusKeyReturnTrue()
  83. // todo function testApiStatusLangvarsReturnArray()
  84. // todo function testApiSetSetting()
  85. // todo function testApiSetSettingsCategoryReturnTrue()
  86. // todo function testApiGetAccessUrlsReturnArray()
  87. // todo function testApiGetAccessUrlReturnArray()
  88. // todo function testApiAddAccessUrlReturnInt()
  89. // todo function testApiGetSettingsReturnArray()
  90. // todo function testApiGetSettingsCategoriesReturnArray()
  91. // todo function testApiDeleteSettingReturnTrue()
  92. // todo function testApiDeleteCategorySettingsReturnTrue()
  93. // todo function testApiAddSettingReturnTrue()
  94. // todo function testApiIsCourseVisibleForUserReturnBooleanValue()
  95. // todo function testApiIsElementInTheSessionReturnBooleanValue()
  96. // todo function testReplaceDangerousChar()
  97. // todo function testApiRequestUri()
  98. // todo function testApiCreateIncludePathSetting()
  99. // todo function testApiGetCurrentAccessUrlIdReturnInt()
  100. // todo function testApiAccessUrlFromUserReturnInt()
  101. // todo function testApiGetStatusOfUserInCourseReturnInteger()
  102. // todo function testApiIsInCourseReturnBooleanValue()
  103. // todo function testApiIsInGroupReturnBooleanValue()
  104. // todo function testApiIsXmlHttpRequest()
  105. // todo function testApiGetEncryptedPassword()
  106. // todo function testApiIsValidSecretKeyReturnBooleanValue()
  107. // todo function testApiIsUserOfCourseReturnBooleanValue()
  108. // todo function testApiIsWnidowsOsReturnBooleanValue()
  109. // todo function testApiUrlToLocalPathReturnString()
  110. // todo function testApiResizeImage()
  111. // todo function testApiCalculateImageSizeReturnArray()
  112. /**
  113. * Test out of a course context
  114. */
  115. function testApiProtectCourseScriptReturnsFalseWhenOutOfCourseContext(){
  116. $res= api_protect_course_script();
  117. $this->assertTrue($res);
  118. }
  119. function testApiGetSettingReturnsTrueWhenIsRightValue(){
  120. $res=api_get_setting();
  121. $this->assertFalse($res);
  122. }
  123. /**
  124. /* Test out of a Admin context
  125. */
  126. function testApiProtectAdminScriptReturnsFalseWhenOutOfCourseContext(){
  127. $res= api_protect_admin_script();
  128. $this->assertTrue($res);
  129. }
  130. function testApiBlockAnonymousUsersReturnTrueWhenUserIsAnonymous(){
  131. $res=api_block_anonymous_users();
  132. $this->assertTrue($res);
  133. }
  134. function testApiGetNavigator(){
  135. $res=api_get_navigator();
  136. $this->assertTrue($res);
  137. }
  138. function testApiIsSelfRegistrationAllowed(){
  139. $res = api_is_self_registration_allowed();
  140. $this->assertFalse($res);
  141. }
  142. function testApiGetPath($path_type){
  143. $res=api_get_path();
  144. $this->assertFalse($res);
  145. }
  146. function testApiGetUserId(){
  147. $res= api_get_user_id();
  148. $this->assertPattern('/\d/',$res);
  149. }
  150. function testApiGetUserCoursesReturnTrueWhenOutOfCoursesContext(){
  151. $res = api_get_user_courses();
  152. $this->assertFalse($res);
  153. }
  154. function testApiGetUserInfoReturnFalseWhenOutOfUserInfoContext(){
  155. $res = api_get_user_info();
  156. $this->assertTrue($res);
  157. }
  158. function testApiGetUserInfoUsernameReturnTrueWhenOutOfUserInfoUsernameContext(){
  159. $res=api_get_user_info_from_username();
  160. $this->assertFalse($res);
  161. }
  162. function testApiGetCourseIdReturnFalseWhenOutOfCourseIdContext(){
  163. $res =api_get_course_id();
  164. $this->assertTrue($res);
  165. }
  166. function testApiGetCoursePathReturnFalseWhenOutOfCoursePathContext(){
  167. $res = api_get_course_path();
  168. $this->assertFalse($res);
  169. }
  170. function testApiGetCourseSettingReturnFalseWhenOutOfCourseSeetingContext(){
  171. $res = api_get_course_setting();
  172. $this->assertTrue($res);
  173. }
  174. function testApiGetAnonymousId(){
  175. $res = api_get_anonymous_id();
  176. $this->assertTrue($res);
  177. }
  178. function testApiGetCidreq(){
  179. $res=api_get_cidreq();
  180. $this->assertTrue($res);
  181. }
  182. function testApiGetCourseInfo(){
  183. $res=api_get_course_info();
  184. $this->assertTrue($res);
  185. }
  186. function testApiSqlQuery(){
  187. $res = api_sql_query();
  188. $this->assertFalse($res);
  189. }
  190. function testApiStoreResult(){
  191. $res = api_store_result();
  192. $this->assertFalse($res);
  193. }
  194. function testApiSessionStart(){
  195. $res = api_session_start($already_sintalled=true);
  196. $this->assertFalse($res);
  197. }
  198. function testApiSessionRegister(){
  199. $$variable[session_register]=false;
  200. $res=api_session_register($$variable);
  201. $this->assertFalse($res);
  202. $this->assertFalse($variable[session_register]);
  203. }
  204. function testApiSessionUnregister(){
  205. $variable=strval($variable);
  206. $res=api_session_unregister($variable);
  207. $this->assertFalse($res);
  208. $this->assertFalse(isset($GLOBALS[$variable]));
  209. $this->assertFalse($_SESSION[$variable]=null);
  210. }
  211. function testApiSessionClear(){
  212. $res=api_session_clear();
  213. $this->assertFalse($res);
  214. }
  215. function testApiSessionDestroy(){
  216. $res=api_session_destroy();
  217. $this->assertFalse($res);
  218. }
  219. function testApiAddUrlParam(){
  220. global $url , $param ;
  221. $res=api_add_url_param($url, $param, $filter_xss=true);
  222. $this->assertFalse($res);
  223. }
  224. function testApiGeneratePassword(){
  225. $res = api_generate_password();
  226. $this->assertTrue($res);
  227. }
  228. function testApiCheckPassword(){
  229. $lengthPass=strlen(5);
  230. $password= $lengthPass;
  231. $res = api_check_password($password);
  232. return $this->assertFalse($res);
  233. }
  234. function testApiClearAnonymous(){
  235. global $_user;
  236. $_user['user_id'] = 1;
  237. $res = api_clear_anonymous($db_check=false);
  238. $this->assertFalse($res);
  239. $this->assertTrue(isset($_user['user_id'] ));
  240. }
  241. function testApiTruncStr(){
  242. $res= api_trunc_str();
  243. return $this->assertFalse($res);
  244. }
  245. function testDomesticate(){
  246. $input= 'dome';
  247. $res = domesticate($input);
  248. return $this->assertTrue($res);
  249. }
  250. function testGetStatusFromCode(){
  251. $status_code = 1;
  252. $res=get_status_from_code($status_code);
  253. return $this->assertTrue($res);
  254. }
  255. function testApiSetFailure(){
  256. global $api_failureList;
  257. $failureType=true;
  258. $res = api_set_failure($failureType);
  259. $this->assertFalse($res);
  260. $this->assertTrue($api_failureList);
  261. }
  262. function testApiSetAnonymous(){
  263. $res = api_set_anonymous();
  264. return $this->assertFalse($res);
  265. }
  266. function testApiGetLastFailure(){
  267. $res= api_Get_last_failure();
  268. $this->assertTrue($res);
  269. }
  270. function testApiGetSessionId(){
  271. $res = api_get_session_id();
  272. return $this->assertFalse($res);
  273. }
  274. function testApiGetSessionName(){
  275. $session_id['sesion_id']=1;
  276. $res = api_get_session_name($session_id);
  277. $this->assertFalse($res);
  278. }
  279. function testAPiGetSetting(){
  280. global $variable;
  281. $res=api_get_setting($variable, $key= NULL);
  282. return $this->assertFalse($res);
  283. }
  284. function testApiGetSelf(){
  285. $res = api_get_self();
  286. return $this->assertTrue($res);
  287. }
  288. /**
  289. * function still unproved
  290. function testGetLang(){
  291. global $language_interface, $language_interface_initial_value, $language_file,$variable;
  292. static $cache=array();
  293. $language=$language_interface;
  294. $cache[$language]=array(false=> array(), true=>array());
  295. $res = get_lang($variable, $notrans = 'DLTT', $language = null);
  296. }
  297. /**
  298. * function still unproved
  299. function testGetLangToSystemEncoding(){
  300. $language;
  301. $res=&get_lang_to_system_encoding(& $string, $language);
  302. }*/
  303. function testApiGetInterfaceLanguage(){
  304. global $language_interface;
  305. $language_interface=false;
  306. $res=api_get_interface_language();
  307. $this->assertFalse($res);
  308. $this->assertTrue(isset($language_interface));
  309. }
  310. function testApiIsPlatformAdmin(){
  311. global $_user;
  312. $_user['status']=true;
  313. $allow_sessions_admins=true;
  314. $res= api_is_platform_admin($allow_sessions_admins=true);
  315. $this->assertTrue($res);
  316. $this->assertTrue($_SESSION['is_platformAdmin']=true);
  317. $this->assertTrue(isset($_user['status']));
  318. }
  319. function testApiIsAllowedToCreateCourse(){
  320. $res=api_is_allowed_to_create_course();
  321. $this->assertFalse($res);
  322. }
  323. function testApiIsCourseAdmin(){
  324. $res=api_is_course_admin();
  325. $this->assertFalse($res);
  326. }
  327. function testApiIsCourseCoach(){
  328. $res=api_is_course_coach();
  329. $this->assertFalse($res);
  330. }
  331. function testApiIsCoach(){
  332. global $_user;
  333. global $sessionIsCoach;
  334. $_user['user_id']=2;
  335. $sessionIsCoach=api_store_result($result=false);
  336. $res=api_is_coach();
  337. $this->assertFalse($res);
  338. $this->assertTrue($_user['user_id']);
  339. $this->assertFalse($sessionIsCoach);
  340. }
  341. function testApiIsSessionAdmin(){
  342. global $_user;
  343. $_user['status']=true;
  344. $res=api_is_session_admin();
  345. $this->assertTrue($res);
  346. $this->assertTrue($_user);
  347. }
  348. function testApiDisplayToolTitle(){
  349. $tit=true;
  350. $titleElement['mainTitle']=$tit;
  351. ob_start();
  352. api_display_tool_title($titleElement);
  353. $res = ob_get_contents();
  354. ob_end_clean();
  355. $this->assertEqual($res,'<h3>1</h3>');
  356. $this->assertTrue(isset($titleElement));
  357. $this->assertTrue($titleElement['mainTitle']);
  358. $this->assertPattern('/<h3>1<\/h3>/', $res);
  359. }/**
  360. untested
  361. function testApiDisplayToolViewOption(){
  362. $res=api_display_tool_view_option();
  363. }*/
  364. function testApiDisplayArray(){
  365. global $info_array;
  366. ob_start();
  367. api_display_array($info_array);
  368. $res = ob_get_contents();
  369. ob_end_clean();
  370. $this->assertNotEqual($res,'');
  371. $this->assertPattern('/<div class="normal-message">.*<\/div>/',$res);
  372. }
  373. function testApiDisplayDebugInfo(){
  374. $message = "mensaje de error"; // siempre que puedas, te conviene probar con valores creados al azar
  375. ob_start();
  376. api_display_debug_info($message);
  377. $res = ob_get_contents();
  378. ob_end_clean();
  379. $this->assertNotEqual($res,'');
  380. $this->assertPattern('/<i>Debug info<\/i>.*/',$res);
  381. }
  382. /**
  383. function is_allowed_to_edit() is deprecated and have been instead by
  384. * api_is_allowed_to_edit()
  385. */
  386. function testApiIsAllowedToEdit(){
  387. $is_courseAdmin=false;
  388. $res=api_is_allowed_to_edit($tutor=false,$scoach=false);
  389. $this->assertTrue($res);
  390. $this->assertTrue(isset($is_courseAdmin));
  391. //$this->assertTrue($is_courseAdmin);
  392. }
  393. function testApiIsAllowed(){
  394. global $_course;
  395. global $_user;
  396. $_user['user_id']=1;
  397. $_course['code']=0;
  398. $tool= true;
  399. $action= api_get_setting();
  400. $res=api_is_allowed($task_id=0);
  401. $this->assertFalse($res);
  402. $this->assertFalse($action);
  403. $this->assertTrue($_user['user_id']);
  404. $this->assertFalse($_course['code']);
  405. }
  406. function testApiIsAnonymous(){
  407. global $_user, $use_anonymous;
  408. $_user['is_anonymous']=False;
  409. $res=api_is_anonymous($user_id=null, $db_check=false);
  410. $this->assertFalse($res);
  411. $this->assertFalse(isset($user_id));
  412. $this->assertTrue(isset($_user['is_anonymous']));
  413. $this->assertFalse($use_anonymous);
  414. $this->assertFalse($db_check);
  415. }
  416. /**
  417. * test was stopped because of errors in the interpretation of
  418. * the role, find out more details.
  419. function testApiNotAllowed(){
  420. $res=api_not_allowed($sprint_headers=false);
  421. $this->assertFalse($res);
  422. }*/
  423. function testConvertMysqlDate(){
  424. $result=false;
  425. $myrow = Database::fetch_array($result);
  426. $last_post_datetime = $myrow['end_date'];
  427. $res=convert_mysql_date($last_post_datetime);
  428. $this->assertTrue($res);
  429. $this->assertFalse($result);
  430. $this->assertFalse($myrow);
  431. }
  432. function testApiGetDatetime(){
  433. $res=api_get_datetime($time=null);
  434. $this->assertTrue($res);
  435. $this->assertFalse(isset($time));
  436. }
  437. function testApiGetItemVisibility(){
  438. $_course= -1;
  439. $tool = Database::escape_string($tool);
  440. $id=Database::escape_string($id);
  441. $_course['dbName']=false;
  442. $res =api_get_item_visibility($_course,$tool,$id);
  443. $this->assertTrue($res);
  444. $this->assertFalse(isset($_course['dbName']));
  445. }/*
  446. * function very complex and analized test is empty
  447. *
  448. function testApiItemPropertyUpdate(){
  449. $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);
  450. }
  451. function testApiGetLanguagesCombo(){
  452. $platformLanguage = api_get_setting('platformLanguage');
  453. $language_list = api_get_languages();
  454. $res=api_get_languages_combo($name="language");
  455. $this->assertTrue($res);
  456. $this->assertTrue($platformLanguage);
  457. $this->assertTrue($language_list['name']);
  458. }
  459. function testApiDisplayLanguageForm(){
  460. $res=api_display_language_form($hide_if_no_choice=false);
  461. $this->assertFalse($res);
  462. }
  463. function testApiGetLanguages(){
  464. $result=true;
  465. $row = mysql_fetch_array($result);
  466. $res= api_get_languages();
  467. $this->assertTrue($res);
  468. $this->assertFalse($row);
  469. }
  470. function testApiGetLanguageIsocode(){
  471. $sql= true;
  472. $var=api_sql_query($sql,_FILE_,_LINE_);
  473. $res=api_get_language_isocode();
  474. $this->assertFalse($res);
  475. $this->assertTrue(isset($var));
  476. }
  477. */
  478. function testApiGetThemes(){
  479. $cssdir= api_get_path(SYS_PATH).'main/css/';
  480. $res=api_get_themes();
  481. $this->assertTrue($res);
  482. $this->assertTrue($cssdir);
  483. }
  484. function testApiDispHtmlArea(){
  485. $name = 'name';
  486. global $_configuration, $_course, $fck_attribute;
  487. ob_start();
  488. api_disp_html_area($name, $content ='', $height='', $width='100%', $optAttrib='');
  489. $res = ob_get_contents();
  490. ob_end_clean();
  491. $this->assertNotEqual($res,'');
  492. }
  493. function testApiReturnHtmlArea(){
  494. $name = true;
  495. global $_configuration, $_course, $fck_attribute;
  496. $res=api_return_html_area($name, $content='', $height='', $width='100%', $optAttrib='');
  497. $this->assertTrue($res);
  498. }
  499. function testApiSendMail(){
  500. $to= 'ricardo.rodriguez@dokeos.com';
  501. $subject='Hola';
  502. $message="prueba de envio";
  503. $send_mail=mail();
  504. $res=api_send_mail($to, $subject, $message, $additional_headers = null, $additional_parameters = null);
  505. $this->assertTrue($res);
  506. $this->assertFalse($send_mail);
  507. }
  508. function testApiMaxSortValue(){
  509. $user=array('user_course_category'=>21, 'user_id'=>1);
  510. $res= api_max_sort_value($user['user_course_category'],$user['user_id']);
  511. $this->assertFalse($res);
  512. $this->assertTrue($user);
  513. }
  514. function testString2Boolean(){
  515. global $string;
  516. $res=string_2_boolean($string);
  517. $this->assertFalse($res);
  518. }
  519. function testApiNumberOfPlugins(){
  520. global $_plugins;
  521. $location=2;
  522. $_plugins[$location]=1;
  523. $res=api_number_of_plugins($location);
  524. $this->assertFalse($res);
  525. $this->assertTrue($_plugins[$location]);
  526. }
  527. function testApiPlugin(){
  528. global $_plugins;
  529. $location=2;
  530. $_plugins[$location]=1;
  531. $res1 = api_plugin($location);
  532. $this->assertFalse($res1);
  533. $this->assertTrue($_plugins[$location]);
  534. }
  535. function testApiDeleteSetting(){
  536. }
  537. function testApiDeleteCategorySettings(){
  538. $c= false;
  539. $res = api_delete_category_settings($c,$a=1);
  540. $this->assertFalse($res);
  541. }
  542. function testApiAddSetting(){
  543. $sk=null;
  544. $type='textfield';
  545. $c=null;
  546. $title='';
  547. $com='';
  548. $sc=null;
  549. $skt=null;
  550. $a=1;
  551. $v=0;
  552. $va=array('val'=>10, 'var'=>'name');
  553. $res= api_add_setting($va['val'],$va['var'],null,null,null,null,null,null,null,null,null);
  554. $this->assertFalse($res);
  555. }
  556. function testApiIsCourseVisibleForUser(){
  557. $res = api_is_course_visible_for_user($userid=null, $cid=null);
  558. $this->assertFalse($res);
  559. }
  560. function testApiIsElementInTheSession(){
  561. $_tool['tool'] = 'TOOL_SURVEY';
  562. $_id['element_id']=3;
  563. $res = api_is_element_in_the_session($_tool['tool'], $_id['element_id'], $session_id=null);
  564. $this->assertFalse($res);
  565. $this->assertTrue((isset($_tool['tool'],$_id['element_id'])));
  566. }
  567. function testReplaceDangerousChar(){
  568. $filename =ereg_replace("\.+$", "", substr(strtr(ereg_replace(
  569. "[^!-~\x80-\xFF]", "_", trim($filename)), '\/:*?"<>|\'',
  570. /* Keep C1 controls for UTF-8 streams */ '-----_---_'), 0, 250));
  571. $res = replace_dangerous_char($filename, $strict = 'loose');
  572. $this->assertEqual($res,$filename, $message = 'no se pudo');
  573. }
  574. function testApiRequestUri(){
  575. $res = api_request_uri();
  576. $this->assertTrue($res);
  577. }
  578. function testApiCreateIncludePathSetting(){
  579. $res=api_create_include_path_setting();
  580. $this->assertTrue($res);
  581. }
  582. function testApiGetCurrentAccessUrlId(){
  583. $res=api_get_current_access_url_id();
  584. $this->assertTrue($res);
  585. }
  586. function testApiGetAccessUrlFromUser(){
  587. $user_id=1;
  588. $res= api_get_access_url_from_user($user_id);
  589. $this->assertFalse($res);
  590. }
  591. function testApiGetStatusOfUserInCourse(){
  592. $id = array(
  593. 'course_code'=>'211',
  594. 'user_id'=>'112');
  595. $res=api_get_status_of_user_in_course($id['course_code'],$id['user_id']);
  596. $this->assertFalse($res);
  597. //$this->assertPattern('/\d/',$res);
  598. }
  599. function testApiIsInCourse(){
  600. $_SESSION['_course']['sysCode']=0;
  601. $res=api_is_in_course($course_code=null);
  602. $this->assertTrue($res);
  603. $this->assertTrue(isset($_SESSION['_course']['sysCode']));
  604. }
  605. function testApiIsInGroup(){
  606. $res=api_is_in_group($group_id=null, $course_code=null);
  607. $this->assertFalse($res);
  608. }
  609. function testApiIsXmlHttpRequest(){
  610. $res=api_is_xml_http_request();
  611. $this->assertTrue(isset($res));
  612. }
  613. function testApiGetEncryptedPassword(){
  614. global $userPasswordCrypted;
  615. $pass= array ('password'=> '2222');
  616. $res=api_get_encrypted_password($pass['password'],null);
  617. $this->assertTrue($res);
  618. $this->assertPattern('/\d/',$res);
  619. }
  620. function testApiIsValidSecretKey(){
  621. global $_configuration;
  622. //$_configuration['key']=true;
  623. $key = array(
  624. 'original_key_secret'=>'2121212',
  625. 'security_key'=>'2121212');
  626. $res = api_is_valid_secret_key($key['original_key_secret'],$key['security_key']);
  627. $this->assertTrue($_configuration);
  628. $this->assertFalse($res);
  629. $this->assertTrue($key);
  630. $this->assertEqual($key['original_key_secret'],$key['security_key'], $message ='%s');
  631. }
  632. function testApiIsUserOfCourse(){
  633. $course_id = 1;
  634. $user_id = 1;
  635. $tbl_course_rel_user =false;
  636. $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).'"';
  637. $res= api_is_user_of_course($course_id, $user_id);
  638. $this->assertFalse($res);
  639. $this->assertFalse($tbl_course_rel_user);
  640. $this->assertTrue($sql);
  641. }
  642. function testApiIsWindowsOs(){
  643. $res= api_is_windows_os();
  644. $this->assertFalse($res);
  645. }
  646. function testApiUrlToLocalPath(){
  647. global $url;
  648. $cond= preg_match(false);
  649. $res= api_url_to_local_path($url);
  650. $this->assertFalse($res);
  651. $this->assertFalse($cond);
  652. }
  653. function testApiResizeImage(){
  654. //global $image, $target_width, $target_height;
  655. $resize = array('image' =>'image.jpg', 'target_width'=>100, 'target_height'=>100);
  656. $res = api_resize_image($resize['image'],$resize['target_width'],$resize['target_height']);
  657. $this->assertTrue($res);
  658. $this->assertWithinMargin($first = 10, $second=20,$margin=200, $message = 'no se pudo redimensionar imagen');
  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($res);
  665. $this->assertTrue($result);
  666. }
  667. function testApiGetToolsLists(){
  668. $tool_list = 'false';
  669. $res = api_get_tools_lists($my_tool =null);
  670. $this->assertTrue($res);
  671. $this->assertTrue($tool_list);
  672. }
  673. }
  674. ?>