dropbox_functions.inc.test.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. <?php
  2. //include_once(api_get_path(LIBRARY_PATH)."/pclzip/pclzip.lib.php");
  3. require_once(api_get_path(LIBRARY_PATH).'document.lib.php');
  4. class TestDropboxFunctions extends UnitTestCase {
  5. /**
  6. * This function is a wrapper function for the multiple actions feature.
  7. * @return Mixed If there is a problem, return a string message, otherwise nothing
  8. */
  9. function testhandle_multiple_actions() {
  10. global $_user, $is_courseAdmin, $is_courseTutor;
  11. $res= handle_multiple_actions();
  12. if(!is_null($res)){
  13. $this->assertTrue(is_string($res));
  14. }
  15. //var_dump($res);
  16. }
  17. /**
  18. * Displays the form to move one individual file to a category
  19. * @return html code of the form that appears in a dokeos message box.
  20. */
  21. function testdisplay_move_form() {
  22. ob_start();
  23. $id= 1;
  24. $part = 'test';
  25. $res= display_move_form($part, $id, $target=array());
  26. ob_end_clean();
  27. if(!is_null($res)){
  28. $this->assertTrue(is_string($res));
  29. }
  30. //var_dump($res);
  31. }
  32. /**
  33. * This functions displays all teh possible actions that can be performed on multiple files. This is the dropdown list that
  34. * appears below the sortable table of the sent / or received files.
  35. * @return html value for the dropdown list
  36. */
  37. function testdisplay_action_options() {
  38. ob_start();
  39. $categories= 1;
  40. $part = 'test';
  41. $res= display_action_options($part, $categories, $current_category=0);
  42. ob_end_clean();
  43. if(!is_null($res)){
  44. $this->assertTrue(is_string($res));
  45. }
  46. //var_dump($res);
  47. }
  48. /**
  49. * this function returns the html code that displays the checkboxes next to the files so that
  50. * multiple actions on one file are possible.
  51. * @param $id the unique id of the file
  52. * @param $part are we dealing with a sent or with a received file?
  53. * @return html code
  54. */
  55. function testdisplay_file_checkbox() {
  56. $id= 1;
  57. $part = 'test';
  58. $res= display_file_checkbox($id, $part);
  59. if(!is_null($res)){
  60. $this->assertTrue(is_string($res));
  61. }
  62. //var_dump($res);
  63. }
  64. /**
  65. * This function displays the form to add a new category.
  66. *
  67. * @param $category_name this parameter is the name of the category (used when no section is selected)
  68. * @param $id this is the id of the category we are editing.
  69. *
  70. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  71. * @version march 2006
  72. */
  73. function testdisplay_addcategory_form() {
  74. global $dropbox_cnf;
  75. ob_start();
  76. $action= 'test';
  77. $res= display_addcategory_form($category_name='', $id='',$action);
  78. ob_end_clean();
  79. if(!is_null($res)){
  80. $this->assertTrue(is_string($res));
  81. }
  82. //var_dump($res);
  83. }
  84. /**
  85. * this function displays the form to upload a new item to the dropbox.
  86. *
  87. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  88. * @version march 2006
  89. */
  90. function testDisplay_add_form() {
  91. global $_user, $is_courseAdmin, $is_courseTutor, $course_info, $origin, $dropbox_unid;
  92. ob_start();
  93. $res= display_add_form();
  94. ob_end_clean();
  95. if(!is_null($res)){
  96. $this->assertTrue(is_string($res));
  97. }
  98. //var_dump($res);
  99. }
  100. /**
  101. * This function displays the firstname and lastname of the user as a link to the user tool.
  102. * @see this is the same function as in the new forum, so this probably has to move to a user library.
  103. * @todo move this function to the user library
  104. */
  105. function testdisplayuserlink() {
  106. global $_otherusers;
  107. $user_id = 1;
  108. $res= display_user_link($user_id, $name='');
  109. if(!is_null($res)){
  110. $this->assertTrue(is_string($res));
  111. }
  112. //var_dump($res);
  113. }
  114. /**
  115. * returns username or false if user isn't registered anymore
  116. * @todo check if this function is still necessary. There might be a library function for this.
  117. */
  118. function testGetUserNameFromId() {
  119. global $dropbox_cnf;
  120. $id = 1;
  121. $res= getUserNameFromId($id);
  122. if(!is_null($res)){
  123. $this->assertTrue(is_string($res));
  124. }
  125. //var_dump($res);
  126. }
  127. /**
  128. * returns loginname or false if user isn't registered anymore
  129. * @todo check if this function is still necessary. There might be a library function for this.
  130. */
  131. function testGetLoginFromId() {
  132. $id = 1;
  133. $res= getLoginFromId($id);
  134. if(!is_null($res)){
  135. $this->assertTrue(is_string($res));
  136. }
  137. //var_dump($res);
  138. }
  139. /**
  140. * @desc This function retrieves the number of feedback messages on every document. This function might become obsolete when
  141. * the feedback becomes user individual.
  142. */
  143. function testget_total_number_feedback() {
  144. global $dropbox_cnf;
  145. $res= get_total_number_feedback($file_id='');
  146. if(!is_null($res)){
  147. $this->assertTrue(is_string($res));
  148. }
  149. //var_dump($res);
  150. }
  151. /**
  152. * This function retrieves all the dropbox categories and returns them as an array
  153. * @param $filter default '', when we need only the categories of the sent or the received part.
  154. * @return array
  155. */
  156. function testGetdropbox_categories() {
  157. $res= get_dropbox_categories($filter='');
  158. if(!is_null($res)){
  159. $this->assertTrue(is_array($res));
  160. }
  161. //var_dump($res);
  162. }
  163. /**
  164. * Mailing zip-file is posted to (dest_user_id = ) mailing pseudo_id
  165. * and is only visible to its uploader (user_id).
  166. * Mailing content files have uploader_id == mailing pseudo_id, a normal recipient,
  167. * and are visible initially to recipient and pseudo_id.
  168. * @todo check if this function is still necessary.
  169. */
  170. function testgetUserOwningThisMailing() {
  171. global $dropbox_cnf;
  172. $mailingPseudoId = '1';
  173. $res= getUserOwningThisMailing($mailingPseudoId, $owner = 0, $or_die = '');
  174. if(!is_null($res)){
  175. $this->assertTrue(is_string($res));
  176. }
  177. //var_dump($res);
  178. }
  179. /**
  180. * Get the last access to a given tool of a given user
  181. * @param $tool string the tool constant
  182. * @param $course_code the course_id
  183. * @param $user_id the id of the user
  184. * @return string last tool access date
  185. * @todo consider moving this function to a more appropriate place.
  186. */
  187. function testget_last_tool_access() {
  188. global $_course, $_user;
  189. $tool = '1';
  190. $res= get_last_tool_access($tool, $course_code='', $user_id='');
  191. if(!is_null($res)){
  192. $this->assertTrue(is_string($res));
  193. }
  194. //var_dump($res);
  195. }
  196. /**
  197. * This functions stores a new dropboxcategory
  198. * @var it might not seem very elegant if you create a category in sent and in received with the same name that you get two entries in the
  199. * dropbox_category table but it is the easiest solution. You get
  200. * cat_name | received | sent | user_id
  201. * test | 1 | 0 | 237
  202. * test | 0 | 1 | 237
  203. * more elegant would be
  204. * test | 1 | 1 | 237
  205. */
  206. function teststoreaddcategory() {
  207. global $_user,$dropbox_cnf;
  208. $res= store_addcategory();
  209. if(!is_null($res)){
  210. $this->assertTrue(is_string($res));
  211. }
  212. //var_dump($res);
  213. }
  214. /**
  215. * This function moves a file to a different category
  216. * @param $id the id of the file we are moving
  217. * @param $target the id of the folder we are moving to
  218. * @param $part are we moving a received file or a sent file?
  219. * @return language string
  220. */
  221. function testStoremove() {
  222. $id= 1;
  223. $part = 'test';
  224. $target = array();
  225. $res= store_move($id, $target, $part);
  226. if(!is_null($res)){
  227. $this->assertTrue(is_string($res));
  228. }
  229. //var_dump($res);
  230. }
  231. /**
  232. *@return selected string
  233. */
  234. function teststoreadddropbox() {
  235. global $dropbox_cnf;
  236. global $_user;
  237. global $_course;
  238. $res= store_add_dropbox();
  239. if(!is_null($res)){
  240. $this->assertTrue(is_string($res));
  241. }
  242. //var_dump($res);
  243. }
  244. /**
  245. * @return boolean indicating if user with user_id=$user_id is a course member
  246. * @todo eliminate global
  247. * @todo check if this function is still necessary. There might be a library function for this.
  248. */
  249. function testIsCourseMember() {
  250. $user_id = 1;
  251. $res= isCourseMember($user_id);
  252. if(!is_null($res)){
  253. $this->assertTrue(is_bool($res));
  254. }
  255. //var_dump($res);
  256. }
  257. /**
  258. * this function transforms the array containing all the feedback into something visually attractive.
  259. * @param an array containing all the feedback about the given message.
  260. */
  261. function testfeedback() {
  262. $array = array();
  263. $res= feedback($array);
  264. if(!is_null($res)){
  265. $this->assertTrue(is_string($res));
  266. }
  267. //var_dump($res);
  268. }
  269. /**
  270. * This function returns the html code to display the feedback messages on a given dropbox file
  271. * @param $feedback_array an array that contains all the feedback messages about the given document.
  272. * @return html code
  273. * @todo add the form for adding new comment (if the other party has not deleted it yet).
  274. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  275. * @version march 2006
  276. */
  277. function testformat_feedback() {
  278. $feedback = array();
  279. $res= format_feedback($feedback);
  280. if(!is_null($res)){
  281. $this->assertTrue(is_string($res));
  282. }
  283. //var_dump($res);
  284. }
  285. /**
  286. * this function returns the code for the form for adding a new feedback message to a dropbox file.
  287. * @return html code
  288. */
  289. function testfeedback_form() {
  290. global $dropbox_cnf;
  291. $res= feedback_form();
  292. if(!is_null($res)){
  293. $this->assertTrue(is_string($res));
  294. }
  295. //var_dump($res);
  296. }
  297. /**
  298. * @return a language string (depending on the success or failure.
  299. */
  300. function teststore_feedback() {
  301. global $dropbox_cnf;
  302. global $_user;
  303. $res= store_feedback();
  304. if(!is_null($res)){
  305. $this->assertTrue(is_string($res));
  306. }
  307. //var_dump($res);
  308. }
  309. /**
  310. * @desc This function checks if the real filename of the dropbox files doesn't already exist in the temp folder. If this is the case then
  311. * it will generate a different filename;
  312. */
  313. function testcheck_file_name() {
  314. global $_course;
  315. $file_name_2_check = 'test';
  316. $res= check_file_name($file_name_2_check, $counter=0);
  317. if(!is_null($res)){
  318. $this->assertTrue(is_string($res));
  319. }
  320. //var_dump($res);
  321. }
  322. /**
  323. * @desc this function checks if the key exists. If this is the case it returns the value, if not it returns 0
  324. */
  325. function testcheck_number_feedback() {
  326. $key = 'test';
  327. $array = array();
  328. $res= check_number_feedback($key, $array);
  329. if(!is_null($res)){
  330. $this->assertTrue(is_numeric($res));
  331. }
  332. //var_dump($res);
  333. }
  334. /**
  335. * @desc generates the contents of a html file that gives an overview of all the files in the zip file.
  336. * This is to know the information of the files that are inside the zip file (who send it, the comment, ...)
  337. */
  338. function testgenerate_html_overview() {
  339. $files = array();
  340. $res= generate_html_overview($files, $dont_show_columns=array(), $make_link=array());
  341. if(!is_null($res)){
  342. $this->assertTrue(is_string($res));
  343. }
  344. //var_dump($res);
  345. }
  346. /**
  347. * This function downloads all the files of the inputarray into one zip
  348. * @param $array an array containing all the ids of the files that have to be downloaded.
  349. * @todo consider removing the check if the user has received or sent this file (zip download of a folder already sufficiently checks for this).
  350. * @todo integrate some cleanup function that removes zip files that are older than 2 days
  351. */
  352. /*
  353. function testzip_download() {
  354. global $_course;
  355. global $dropbox_cnf;
  356. global $_user;
  357. global $files;
  358. $array = array();
  359. $res= zip_download($array);
  360. if(!is_string($res)){
  361. $this->assertTrue(is_null($res));
  362. }
  363. //var_dump($res);
  364. }
  365. */
  366. /**
  367. * Function that finds a given config setting
  368. */
  369. function testdropbox_cnf() {
  370. $variable = 'test';
  371. $res= dropbox_cnf($variable);
  372. if(!is_null($res)){
  373. $this->assertTrue(is_string($res));
  374. }
  375. //var_dump($res);
  376. }
  377. /**
  378. * This is a callback function to decrypt the files in the zip file to their normal filename (as stored in the database)
  379. * @param $p_event a variable of PCLZip
  380. * @param $p_header a variable of PCLZip
  381. */
  382. function testmy_pre_add_callback() {
  383. global $files;
  384. $p_event = 'test';
  385. $res= my_pre_add_callback($p_event, &$p_header);
  386. if(!is_null($res)){
  387. $this->assertTrue(is_numeric($res));
  388. }
  389. //var_dump($res);
  390. }
  391. /**
  392. * @desc Cleans the temp zip files that were created when users download several files or a whole folder at once.
  393. * T
  394. * @return true
  395. */
  396. function testcleanup_temp_dropbox() {
  397. global $_course;
  398. $res= cleanup_temp_dropbox();
  399. if(!is_null($res)){
  400. $this->assertTrue(is_bool($res));
  401. }
  402. //var_dump($res);
  403. }
  404. /**
  405. * This function deletes a dropbox category
  406. * @todo give the user the possibility what needs to be done with the files in this category: move them to the root, download them as a zip, delete them
  407. */
  408. function testdelete_category() {
  409. global $_user, $is_courseAdmin, $is_courseTutor,$dropbox_cnf;
  410. $id= 1;
  411. $action = 'test';
  412. $res= delete_category($action, $id);
  413. if(!is_null($res)){
  414. $this->assertTrue(is_string($res));
  415. }
  416. //var_dump($res);
  417. }
  418. /**
  419. * Checks if there are files in the dropbox_file table that aren't used anymore in dropbox_person table.
  420. * If there are, all entries concerning the file are deleted from the db + the file is deleted from the server
  421. */
  422. function testremoveUnusedFiles() {
  423. $res= removeUnusedFiles();
  424. if(!is_null($res)){
  425. $this->assertTrue(is_array($res));
  426. }
  427. //var_dump($res);
  428. }
  429. /**
  430. * @todo check if this function is still necessary.
  431. */
  432. function testremoveMoreIfMailing() {
  433. $file_id = 1;
  434. $res= removeMoreIfMailing($file_id);
  435. if(!is_null($res)){
  436. $this->assertTrue(is_array($res));
  437. }
  438. //var_dump($res);
  439. }
  440. }
  441. ?>