work.lib.test.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <?php
  2. require_once(api_get_path(SYS_CODE_PATH).'work/work.lib.php');
  3. require_once(api_get_path(LIBRARY_PATH).'course.lib.php');
  4. class TestWork extends UnitTestCase {
  5. /**
  6. * @param string Base work dir (.../work)
  7. * @param string $desiredDirName complete path of the desired name
  8. * @return string actual directory name if it succeeds, boolean false
  9. * otherwise
  10. */
  11. function testcreate_unexisting_work_directory() {
  12. $path_name = api_get_path(SYS_COURSE_PATH);
  13. $base_work_dir=$path_name.'testing/';
  14. $desired_dir_name= $path_name.'testing';
  15. $res=create_unexisting_work_directory($base_work_dir,$desired_dir_name);
  16. $this->assertTrue(is_bool($res));
  17. }
  18. /**
  19. * Builds the form thats enables the user to
  20. * select a directory to browse/upload in
  21. * This function has been copied from the document/document.inc.php library
  22. *
  23. * @param array $folders
  24. * @param string $curdirpath
  25. * @param string $group_dir
  26. * @return string html form
  27. */
  28. function testbuild_work_directory_selector() {
  29. $folders=array();
  30. $curdirpath='';
  31. $group_dir='';
  32. $res=build_work_directory_selector($folders,$curdirpath,$group_dir='');
  33. $this->assertTrue(is_string($res));
  34. //var_dump($res);
  35. }
  36. /**
  37. * Builds the form thats enables the user to
  38. * move a document from one directory to another
  39. * This function has been copied from the document/document.inc.php library
  40. *
  41. * @param array $folders
  42. * @param string $curdirpath
  43. * @param string $move_file
  44. * @return string html form
  45. */
  46. function testbuild_work_move_to_selector() {
  47. $folders=array();
  48. $curdirpath='';
  49. $move_file='';
  50. $group_dir='';
  51. $res=build_work_move_to_selector($folders,$curdirpath,$move_file,$group_dir='');
  52. $this->assertTrue(is_string($res));
  53. //var_dump($res);
  54. }
  55. function testconvert_date_to_array() {
  56. $date=date('d/m/Y',time());
  57. $group=array();
  58. $res=convert_date_to_array($date,$group);
  59. $this->assertTrue(is_array($res));
  60. //var_dump($res);
  61. }
  62. /**
  63. * This function displays the number of files contained in a directory
  64. * @param string the path of the directory complete e.g. /var/www/dokeos
  65. * @param boolean true if we want the total quantity of files include in others child directorys , false only files in the directory
  66. * @return array the first element is an integer with the number of files in the folder, the second element is the number of directories
  67. */
  68. function testcount_dir() {
  69. $path_name = api_get_path(SYS_COURSE_PATH);
  70. $path_dir=$path_name;
  71. $recurse=0;
  72. ob_start();
  73. $res=count_dir($path_dir, $recurse);
  74. $this->assertTrue(is_array($res));
  75. ob_end_clean();
  76. //var_dump($res);
  77. }
  78. /**
  79. * create a group of select from a date
  80. * @return array list
  81. */
  82. function testcreate_group_date_select() {
  83. $res=create_group_date_select($prefix='');
  84. $this->assertTrue(is_array($res));
  85. //var_dump($res);
  86. }
  87. /**
  88. * Transform an all directory structure (only directories) in an array
  89. * @param string path of the directory
  90. * @return array the directory structure into an array
  91. */
  92. function testdirectory_to_array() {
  93. $path_name = api_get_path(SYS_PATH);
  94. $directory= $path_name;
  95. $res=directory_to_array($directory);
  96. $this->assertTrue(is_array($res));
  97. //var_dump($res);
  98. }
  99. /**
  100. * Displays action links (for admins, authorized groups members and authorized students)
  101. * @param string Current dir
  102. * @param integer Whether to show tool options
  103. * @param integer Whether to show upload form option
  104. * @return void
  105. */
  106. function testdisplay_action_links() {
  107. $cur_dir_path='';
  108. $always_show_tool_options=1;
  109. $always_show_upload_form=1;
  110. ob_start();
  111. $res=display_action_links($cur_dir_path, $always_show_tool_options, $always_show_upload_form);
  112. $this->assertTrue(is_null($res));
  113. ob_end_clean();
  114. //var_dump($res);
  115. }
  116. /**
  117. * Displays the form where course admins can specify wether uploaded documents
  118. * are visible or invisible by default.
  119. *
  120. * @param $uploadvisibledisabled
  121. * @return html with two list radio button
  122. */
  123. function testdisplay_default_visibility_form() {
  124. $uploadvisibledisabled='';
  125. ob_start();
  126. $res=display_default_visibility_form($uploadvisibledisabled);
  127. $this->assertTrue(is_null($res));
  128. ob_end_clean();
  129. //var_dump($res);
  130. }
  131. /**
  132. * Displays all options for this tool.
  133. * These are
  134. * - make all files visible / invisible
  135. * - set the default visibility of uploaded files
  136. *
  137. * @param $uploadvisibledisabled
  138. * @param $origin
  139. * @param $base_work_dir Base working directory (up to '/work')
  140. * @param $cur_dir_path Current subdirectory of 'work/'
  141. * @param $cur_dir_path_url Current subdirectory of 'work/', url-encoded
  142. */
  143. function testdisplay_tool_options() {
  144. global $charset, $group_properties,$gradebook,$base_work_dir;
  145. $uploadvisibledisabled='';
  146. $origin='';
  147. $cur_dir_path='';
  148. $cur_dir_path_url='';
  149. ob_start();
  150. $res=display_tool_options($uploadvisibledisabled, $origin,$base_work_dir,$cur_dir_path,$cur_dir_path_url);
  151. $this->assertTrue(is_null($res));
  152. ob_end_clean();
  153. //var_dump($res);
  154. }
  155. /**
  156. * create a group of select from a date
  157. */
  158. function testget_date_from_group() {
  159. $group='';
  160. $res=get_date_from_group($group);
  161. $this->assertTrue(is_string($res));
  162. //var_dump($res);
  163. }
  164. /**
  165. * @param string Path of the directory
  166. * @return array The list of ids of all the directories in the path
  167. */
  168. function testget_parent_directories() {
  169. $my_cur_dir_path='';
  170. $res=get_parent_directories($my_cur_dir_path);
  171. $this->assertTrue(is_array($res));
  172. //var_dump($res);
  173. }
  174. /**
  175. * Gets the id of a student publication with a given path
  176. * @param string $path
  177. * @return true if is found / false if not found
  178. */
  179. function testget_work_id() {
  180. global $cidReq;
  181. $path_name = api_get_path(SYS_PATH);
  182. $path=$path_name.$cidReq;
  183. $res=get_work_id($path);
  184. $this->assertTrue(is_bool($res));
  185. //var_dump($res);
  186. }
  187. /**
  188. * Get the path of a document in the student_publication table (path relative to the course directory)
  189. * @param integer Element ID
  190. * @return string Path (or -1 on error)
  191. */
  192. function testget_work_path() {
  193. $id=1;
  194. $res=get_work_path($id);
  195. $this->assertTrue(is_numeric($res));
  196. //var_dump($res);
  197. }
  198. /**
  199. * Insert into the DB of the course all the directories
  200. * @param string path of the /work directory of the course
  201. * @return -1 on error, sql query result on success
  202. * @version April 2008
  203. */
  204. function testinsert_all_directory_in_course_table() {
  205. $path_name = api_get_path(SYS_COURSE_PATH);
  206. $base_work_dir=$path_name.'work/testing';
  207. $dir_to_array =directory_to_array($base_work_dir,true);
  208. $res=insert_all_directory_in_course_table($base_work_dir);
  209. $this->assertTrue(is_null($res));
  210. //var_dump($res);
  211. }
  212. /**
  213. * returns all the javascript that is required for easily
  214. * validation when you create a work
  215. * this goes into the $htmlHeadXtra[] array
  216. */
  217. function testto_javascript_work() {
  218. $res=to_javascript_work();
  219. $this->assertTrue(is_string($res));
  220. //var_dump($res);
  221. }
  222. /**
  223. * converts 1-9 to 01-09
  224. */
  225. function testtwo_digits() {
  226. $number=1;
  227. $res=two_digits($number);
  228. $this->assertTrue(is_numeric($res));
  229. //var_dump($res);
  230. }
  231. /**
  232. * Update the url of a dir in the student_publication table
  233. * @param string old path
  234. * @param string new path
  235. */
  236. function testupdate_dir_name() {
  237. global $base_work_dir;
  238. $path='';
  239. $new_name='';
  240. $res=update_dir_name($path,$new_name);
  241. $this->assertTrue(is_null($res));
  242. //var_dump($res);
  243. }
  244. /**
  245. * Update the url of a work in the student_publication table
  246. * @param integer ID of the work to update
  247. * @param string Destination directory where the work has been moved (must end with a '/')
  248. * @return -1 on error, sql query result on success
  249. */
  250. function testupdate_work_url() {
  251. $id=1;
  252. $path_name = api_get_path(SYS_COURSE_PATH);
  253. $new_path=$path_name.'work/testing';
  254. $res=update_work_url($id,$new_path);
  255. $this->assertTrue(is_numeric($res));
  256. //var_dump($res);
  257. }
  258. /**
  259. * Delete a work-tool directory
  260. * @param string Base "work" directory for this course as /var/www/dokeos/courses/ABCD/work/
  261. * @param string The directory name as the bit after "work/", without trailing slash
  262. * @return integer -1 on error
  263. */
  264. function testdel_dir() {
  265. global $cidReq;
  266. $path_name = api_get_path(SYS_PATH);
  267. $base_work_dir=$path_name.$cidReq.'work/testing';
  268. $dir= $path_name.'testing/';
  269. $id=-1;
  270. $res=del_dir($base_work_dir,$dir,$id);
  271. $this->assertTrue(is_numeric($res));
  272. //var_dump($res);
  273. }
  274. }
  275. ?>