forumfunction.inc.test.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368
  1. <?php
  2. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/gradebookitem.class.php';
  3. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/abstractlink.class.php';
  4. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/evallink.class.php';
  5. class TestForumFunction extends UnitTestCase {
  6. public function TestForumFunction() {
  7. $this->UnitTestCase('Test forum function');
  8. }
  9. public function __construct() {
  10. // The constructor acts like a global setUp for the class
  11. require_once api_get_path(SYS_TEST_PATH).'setup.inc.php';
  12. }
  13. /**
  14. * This function add a attachment file into forum
  15. * @param string a comment about file
  16. * @param int last id from forum_post table
  17. * @return void
  18. */
  19. public function testadd_forum_attachment_file() {
  20. global $_course;
  21. $file_comment='testcoment';
  22. $last_id = 1;
  23. $res = add_forum_attachment_file($file_comment,$last_id);
  24. $this->assertTrue(is_null($res));
  25. //var_dump($res);
  26. }
  27. /**
  28. * This function approves a post = change
  29. *
  30. * @param $post_id the id of the post that will be deleted
  31. * @param $action make the post visible or invisible
  32. * @return string language variable
  33. */
  34. public function testapprove_post() {
  35. $action= 'invisible';
  36. $post_id = 1;
  37. $res = approve_post($post_id, $action);
  38. $this->assertTrue(is_string($res));
  39. //var_dump($res);
  40. }
  41. /**
  42. * This function changes the lock status in the database
  43. *
  44. * @param $content what is it that we want to (un)lock: forum category, forum, thread, post
  45. * @param $id the id of the content we want to (un)lock
  46. * @param $action do we lock (=>locked value in db = 1) or unlock (=> locked value in db = 0)
  47. * @return string, language variable
  48. * @todo move to itemmanager
  49. */
  50. public function testchange_lock_status() {
  51. $content = 'testcontent';
  52. $action= 'invisible';
  53. $id = 1;
  54. $res = change_lock_status($content, $id, $action);
  55. $this->assertTrue(is_string($res));
  56. //var_dump($res);
  57. }
  58. /**
  59. * This function changes the visibility in the database (item_property)
  60. *
  61. * @param $content what is it that we want to make (in)visible: forum category, forum, thread, post
  62. * @param $id the id of the content we want to make invisible
  63. * @param $target_visibility what is the current status of the visibility (0 = invisible, 1 = visible)
  64. * @todo change the get parameter so that it matches the tool constants.
  65. * @todo check if api_item_property_update returns true or false => returnmessage depends on it.
  66. * @todo move to itemmanager
  67. * @return string language variable
  68. */
  69. public function testchange_visibility() {
  70. $content= 'testcontent';
  71. $target_visibility = 1;
  72. $id = 1;
  73. $res = change_visibility($content, $id, $target_visibility);
  74. $this->assertTrue(is_string($res));
  75. //var_dump($res);
  76. }
  77. /**
  78. * This function gets the all information of the last (=most recent) post of the thread
  79. * This can be done by sorting the posts that have the field thread_id=$thread_id and sort them by post_date
  80. * @param $thread_id the id of the thread we want to know the last post of.
  81. * @return an bool or array if there is a last post found, false if there is no post entry linked to that thread => thread will be deleted
  82. */
  83. public function testcheck_if_last_post_of_thread() {
  84. $thread_id = 1;
  85. $res = check_if_last_post_of_thread($thread_id);
  86. if(!is_bool($res)) {
  87. $this->assertTrue(is_array($res));
  88. }
  89. //var_dump($res);
  90. }
  91. /**
  92. * This function returns a piece of html code that make the links grey (=invisible for the student)
  93. * @param boolean 0/1: 0 = invisible, 1 = visible
  94. * @return string language variable
  95. */
  96. public function testclass_visible_invisible() {
  97. $current_visibility_status = 0;
  98. $res = class_visible_invisible($current_visibility_status);
  99. $this->assertTrue(is_string($res));
  100. //var_dump($res);
  101. }
  102. /**
  103. * This function counts the number of forums inside a given category
  104. * @param $cat_id the id of the forum category
  105. * @todo an additional parameter that takes the visibility into account. For instance $countinvisible=0 would return the number
  106. * of visible forums, $countinvisible=1 would return the number of visible and invisible forums
  107. * @return int the number of forums inside the given category
  108. */
  109. public function testcount_number_of_forums_in_category() {
  110. $cat_id = 1;
  111. $res = count_number_of_forums_in_category($cat_id);
  112. $this->assertTrue(is_numeric($res));
  113. //var_dump($res);
  114. }
  115. /**
  116. * This function counts the number of post inside a thread user
  117. * @param int Thread ID
  118. * @param int User ID
  119. * @return int the number of post inside a thread user
  120. */
  121. public function testcount_number_of_post_for_user_thread() {
  122. $thread_id = 1;
  123. $user_id = 1;
  124. $res = count_number_of_post_for_user_thread($thread_id, $user_id);
  125. $this->assertTrue(is_numeric($res));
  126. //var_dump($res);
  127. }
  128. /**
  129. * This function counts the number of post inside a thread
  130. * @param int Thread ID
  131. * @return int the number of post inside a thread
  132. */
  133. public function testcount_number_of_post_in_thread() {
  134. $thread_id = 1;
  135. $res = count_number_of_post_in_thread($thread_id);
  136. $this->assertTrue(is_numeric($res));
  137. //var_dump($res);
  138. }
  139. /**
  140. * This function counts the number of user register in course
  141. * @param int Course ID
  142. * @return int the number of user register in course
  143. */
  144. public function testcount_number_of_user_in_course() {
  145. global $cidReq;
  146. $course_id = $cidReq;
  147. $res = count_number_of_user_in_course($course_id);
  148. $this->assertTrue(is_numeric($res));
  149. //var_dump($res);
  150. }
  151. /**
  152. *
  153. * This function show current thread qualify .
  154. * @param integer contains the information the current thread id
  155. * @param integer contains the information the current session id
  156. * @return array or null if is empty
  157. */
  158. public function testcurrent_qualify_of_thread() {
  159. $thread_id = 1;
  160. $session_id = 1;
  161. $res = current_qualify_of_thread($thread_id,$session_id);
  162. $this->assertTrue(is_null($res));
  163. //var_dump($res);
  164. }
  165. /**
  166. * Display the search results
  167. * @return void HTML - display the results
  168. */
  169. public function testdisplay_forum_search_results() {
  170. global $origin;
  171. $search_term = 'testterm';
  172. ob_start();
  173. $res = display_forum_search_results($search_term);
  174. ob_end_clean();
  175. $this->assertTrue(is_null($res));
  176. //var_dump($res);
  177. }
  178. /**
  179. * This function takes care of the display of the lock icon
  180. * @param $content what is it that we want to (un)lock: forum category, forum, thread, post
  181. * @param $id the id of the content we want to (un)lock
  182. * @param $current_visibility_status what is the current status of the visibility (0 = invisible, 1 = visible)
  183. * @return void display the lock HTML.
  184. */
  185. function testdisplay_lock_unlock_icon() {
  186. $content = 'testterm';
  187. $id = 1;
  188. $current_lock_status = 0;
  189. ob_start();
  190. $res = display_lock_unlock_icon($content, $id, $current_lock_status, $additional_url_parameters='');
  191. ob_end_clean();
  192. $this->assertTrue(is_null($res));
  193. //var_dump($res);
  194. }
  195. /**
  196. * This function takes care of the display of the up and down icon
  197. * @param $content what is it that we want to make (in)visible: forum category, forum, thread, post
  198. * @param $id is the id of the item we want to display the icons for
  199. * @param $list is an array of all the items. All items in this list should have an up and down icon except for the first (no up icon) and the last (no down icon)
  200. * The key of this $list array is the id of the item.
  201. * @return void HTML
  202. */
  203. public function testdisplay_up_down_icon() {
  204. $content = 'testcontent';
  205. $id = 1;
  206. $list = array('test');
  207. ob_start();
  208. $res = display_up_down_icon($content, $id, $list);
  209. ob_end_clean();
  210. $this->assertTrue(is_null($res));
  211. //var_dump($res);
  212. }
  213. /**
  214. * This function displays the user image from the profile, with a link to the user's details.
  215. * @param int User's database ID
  216. * @param str User's name
  217. * @return string An HTML with the anchor and the image of the user
  218. */
  219. public function testdisplay_user_image() {
  220. $name = 'testcontent';
  221. $user_id = 1;
  222. $res = display_user_image($user_id,$name, $origin='');
  223. $this->assertTrue(is_string($res));
  224. //var_dump($res);
  225. }
  226. /**
  227. * This function displays the firstname and lastname of the user as a link to the user tool.
  228. * @param string
  229. * @return string HTML
  230. */
  231. public function testdisplay_user_link() {
  232. $name = 'testcontent';
  233. $user_id = 1;
  234. $res = display_user_link($user_id, $name, $origin='');
  235. $this->assertTrue(is_string($res));
  236. //var_dump($res);
  237. }
  238. /**
  239. * This function takes care of the display of the visibility icon
  240. * @param $content what is it that we want to make (in)visible: forum category, forum, thread, post
  241. * @param $id the id of the content we want to make invisible
  242. * @param $current_visibility_status what is the current status of the visibility (0 = invisible, 1 = visible)
  243. * @return void string HTML
  244. */
  245. public function testdisplay_visible_invisible_icon() {
  246. $content = 'testcontent';
  247. $current_visibility_status = 0;
  248. $id = 1;
  249. ob_start();
  250. $res = display_visible_invisible_icon($content, $id, $current_visibility_status, $additional_url_parameters='');
  251. ob_end_clean();
  252. $this->assertTrue(is_null($res));
  253. //var_dump($res);
  254. }
  255. /**
  256. * This function edit a attachment file into forum
  257. * @param string a comment about file
  258. * @param int Post Id
  259. * @param int attachment file Id
  260. * @return void
  261. */
  262. public function testedit_forum_attachment_file() {
  263. $file_comment = 'testcontent';
  264. $id_attach = 1;
  265. $post_id = 1;
  266. $res = edit_forum_attachment_file($file_comment,$post_id,$id_attach);
  267. $this->assertTrue(is_null($res));
  268. //var_dump($res);
  269. }
  270. /**
  271. * Display the search form for the forum and display the search results
  272. * @return void display an HTML search results
  273. */
  274. public function testforum_search() {
  275. ob_start();
  276. $res = forum_search();
  277. ob_end_clean();
  278. $this->assertTrue(is_null($res));
  279. //var_dump($res);
  280. }
  281. /** This function gets all the post written by an user
  282. * @param int user id
  283. * @param string db course name
  284. * @return string
  285. */
  286. public function testget_all_post_from_user() {
  287. global $_course;
  288. $course_db = $_course['dbName'];
  289. $user_id = 1;
  290. $res = get_all_post_from_user($user_id, $course_db);
  291. $this->assertTrue(is_string($res));
  292. //var_dump($res);
  293. }
  294. /**
  295. * Show a list with all the attachments according to the post's id
  296. * @param the post's id
  297. * @return array with the post info
  298. */
  299. public function testget_attachment() {
  300. $post_id = 1;
  301. $res = get_attachment($post_id);
  302. $this->assertTrue(is_array($res));
  303. //var_dump($res);
  304. }
  305. /**
  306. * Retrieve all the information off the forum categories (or one specific) for the current course.
  307. * The categories are sorted according to their sorting order (cat_order
  308. * @param $id default ''. When an id is passed we only find the information about that specific forum category. If no id is passed we get all the forum categories.
  309. * @return an array containing all the information about all the forum categories
  310. */
  311. public function testget_forum_categories() {
  312. $res = get_forum_categories($id='');
  313. $this->assertTrue(is_array($res));
  314. //var_dump($res);
  315. }
  316. /**
  317. * This function retrieves all the information of a given forum_id
  318. * @param $forum_id integer that indicates the forum
  319. * @return array returns
  320. * @deprecated this functionality is now moved to get_forums($forum_id)
  321. */
  322. /*
  323. function testget_forum_information() {
  324. $forum_id = 1;
  325. $res = get_forum_information($forum_id);
  326. $this->assertTrue(is_array($res));
  327. //var_dump($res);
  328. }*/
  329. /**
  330. * This function retrieves all the information of a given forumcategory id
  331. * @param $forum_id integer that indicates the forum
  332. * @return array returns if there are category
  333. * @return bool returns if there aren't category
  334. */
  335. public function testget_forumcategory_information() {
  336. $cat_id = 1;
  337. $res = get_forumcategory_information($cat_id);
  338. if(!is_bool($res)){
  339. $this->assertTrue(is_array($res));
  340. } else {
  341. $this->assertTrue(is_bool($res));
  342. }
  343. //var_dump($res);
  344. }
  345. /**
  346. * Retrieve all the forums (regardless of their category) or of only one. The forums are sorted according to the forum_order.
  347. * Since it does not take the forum category into account there probably will be two or more forums that have forum_order=1, ...
  348. * @return an array containing all the information about the forums (regardless of their category)
  349. * @todo check $sql4 because this one really looks fishy.
  350. */
  351. public function testget_forums() {
  352. $res = get_forums($id='');
  353. if(!is_bool($res)){
  354. $this->assertTrue(is_array($res));
  355. } else {
  356. $this->assertTrue(is_bool($res));
  357. }
  358. //var_dump($res);
  359. }
  360. /**
  361. * This function retrieves all the fora in a given forum category
  362. * @param integer $cat_id the id of the forum category
  363. * @return an array containing all the information about the forums (regardless of their category)
  364. */
  365. public function testget_forums_in_category() {
  366. $cat_id = 1;
  367. $res = get_forums_in_category($cat_id);
  368. if(!is_bool($res)){
  369. $this->assertTrue(is_array($res));
  370. } else {
  371. $this->assertTrue(is_bool($res));
  372. }
  373. //var_dump($res);
  374. }
  375. /**
  376. * This function gets all the forum information of the all the forum of the group
  377. * @param integer $group_id the id of the group we need the fora of (see forum.forum_of_group)
  378. * @return array
  379. * @todo this is basically the same code as the get_forums function. Consider merging the two.
  380. */
  381. public function testget_forums_of_group() {
  382. $group_id = 1;
  383. $res = get_forums_of_group($group_id);
  384. if(!is_null($res)){
  385. $this->assertTrue(is_array($res));
  386. } else {
  387. $this->assertTrue(is_null($res));
  388. }
  389. //var_dump($res);
  390. }
  391. /**
  392. *
  393. * This function get qualify historical.
  394. * @param integer contains the information the current user id
  395. * @param integer contains the information the current thread id
  396. * @param boolean contains the information of option to run
  397. * @return array()
  398. */
  399. public function testGetThreadScoreHistory() {
  400. $user_id = 1;
  401. $thread_id = 1;
  402. $opt = true;
  403. $res = getThreadScoreHistory($user_id,$thread_id,$opt);
  404. if(!is_null($res)){
  405. $this->assertTrue(is_array($res));
  406. } else {
  407. $this->assertTrue(is_null($res));
  408. }
  409. //var_dump($res);
  410. }
  411. /**
  412. * This functions gets all the last post information of a certain forum
  413. * @param $forum_id the id of the forum we want to know the last post information of.
  414. * @param $show_invisibles
  415. * @return array containing all the information about the last post (last_post_id, last_poster_id, last_post_date, last_poster_name, last_poster_lastname, last_poster_firstname)
  416. */
  417. public function testget_last_post_information() {
  418. $forum_id = 1;
  419. $res = get_last_post_information($forum_id, $show_invisibles=false);
  420. if(!is_null($res)){
  421. $this->assertTrue(is_array($res));
  422. } else {
  423. $this->assertTrue(is_null($res));
  424. }
  425. //var_dump($res);
  426. }
  427. /** This function get the name of an thread by id
  428. * @param int thread_id
  429. * @return String
  430. **/
  431. public function testget_name_thread_by_id() {
  432. $thread_id = 1;
  433. $res = get_name_thread_by_id($thread_id);
  434. if(!is_null($res)){
  435. $this->assertTrue(is_string($res));
  436. } else {
  437. $this->assertTrue(is_null($res));
  438. }
  439. //var_dump($res);
  440. }
  441. /** This function get the name of an user by id
  442. * @param user_id int
  443. * return String
  444. */
  445. public function testget_name_user_by_id() {
  446. $user_id = 1;
  447. $res = get_name_user_by_id($user_id);
  448. if(!is_null($res)){
  449. $this->assertTrue(is_string($res));
  450. } else {
  451. $this->assertTrue(is_null($res));
  452. }
  453. //var_dump($res);
  454. }
  455. /**
  456. * This function retrieves all the email adresses of the users who wanted to be notified
  457. * about a new post in a certain forum or thread
  458. * @param string $content does the user want to be notified about a forum or about a thread
  459. * @param integer $id the id of the forum or thread
  460. * @return array
  461. */
  462. public function testget_notifications() {
  463. $id = 1;
  464. $content = 'test message notified';
  465. $res = get_notifications($content,$id);
  466. if(!is_null($res)){
  467. $this->assertTrue(is_array($res));
  468. } else {
  469. $this->assertTrue(is_null($res));
  470. }
  471. //var_dump($res);
  472. }
  473. /**
  474. * Get all the notification subscriptions of the user
  475. * = which forums and which threads does the user wants to be informed of when a new
  476. * post is added to this thread
  477. * @param integer $user_id the user_id of a user (default = 0 => the current user)
  478. * @param boolean $force force get the notification subscriptions (even if the information is already in the session
  479. * @return array
  480. */
  481. public function testget_notifications_of_user() {
  482. $res = get_notifications_of_user($user_id = 0, $force = false);
  483. if(!is_null($res)){
  484. $this->assertTrue(is_string($res));
  485. } else {
  486. $this->assertTrue(is_null($res));
  487. }
  488. //var_dump($res);
  489. }
  490. /**
  491. * This function retrieves all the information of a post
  492. * @param $forum_id integer that indicates the forum
  493. * @return array returns
  494. */
  495. public function testget_post_information() {
  496. $post_id = 1;
  497. $res = get_post_information($post_id);
  498. if(!is_null($res)){
  499. $this->assertTrue(is_array($res));
  500. } else {
  501. $this->assertTrue(is_null($res));
  502. }
  503. //var_dump($res);
  504. }
  505. /**
  506. * With this function we find the number of posts and topics in a given forum.
  507. * @param int
  508. * @return array
  509. * @todo consider to call this function only once and let it return an array where the key is the forum id and the value is an array with number_of_topics and number of post
  510. * as key of this array and the value as a value. This could reduce the number of queries needed (especially when there are more forums)
  511. * @todo consider merging both in one query.
  512. * @deprecated the counting mechanism is now inside the function get_forums
  513. */
  514. /*
  515. function testget_post_topics_of_forum() {
  516. $forum_id = 1;
  517. $res = get_post_topics_of_forum($forum_id);
  518. if(!is_null($res)){
  519. $this->assertTrue(is_array($res));
  520. } else {
  521. $this->assertTrue(is_null($res));
  522. }
  523. //var_dump($res);
  524. }*/
  525. /**
  526. * Retrieve all posts of a given thread
  527. * @param int $thread_id integer that indicates the forum
  528. * @return an array containing all the information about the posts of a given thread
  529. */
  530. public function testget_posts() {
  531. $thread_id = 1;
  532. $res = getPosts($thread_id);
  533. if(!is_null($res)){
  534. $this->assertTrue(is_array($res));
  535. } else {
  536. $this->assertTrue(is_null($res));
  537. }
  538. //var_dump($res);
  539. }
  540. /**
  541. * This function retrieves information of statistical
  542. * @param int Thread ID
  543. * @param int User ID
  544. * @param int Course ID
  545. * @return array the information of statistical
  546. */
  547. public function testget_statistical_information() {
  548. $thread_id = 1;
  549. $user_id = 1;
  550. $course_id = 1;
  551. $res = get_statistical_information($thread_id, $user_id, $course_id);
  552. if(!is_null($res)){
  553. $this->assertTrue(is_array($res));
  554. } else {
  555. $this->assertTrue(is_null($res));
  556. }
  557. //var_dump($res);
  558. }
  559. /**
  560. * This function retrieves all the information of a thread
  561. * @param $forum_id integer that indicates the forum
  562. * @return array returns
  563. */
  564. function testget_thread_information() {
  565. $thread_id = 1;
  566. $res = get_thread_information($thread_id);
  567. if(!is_bool($res)){
  568. $this->assertTrue(is_array($res));
  569. } else {
  570. $this->assertTrue(is_bool($res));
  571. }
  572. //var_dump($res);
  573. }
  574. /**
  575. * This function return the posts inside a thread from a given user
  576. * @param course code
  577. * @param int Thread ID
  578. * @param int User ID
  579. * @return int the number of post inside a thread
  580. */
  581. public function testget_thread_user_post() {
  582. global $_course;
  583. $thread_id = 1;
  584. $course_db = $_course['dbName'];
  585. $user_id = 1;
  586. $res = get_thread_user_post($course_db, $thread_id, $user_id );
  587. if(!is_null($res)){
  588. $this->assertTrue(is_array($res));
  589. } else {
  590. $this->assertTrue(is_null($res));
  591. }
  592. //var_dump($res);
  593. }
  594. /**
  595. * @param string
  596. * @param int
  597. * @param int
  598. * @param int
  599. * @return void
  600. */
  601. public function testget_thread_user_post_limit() {
  602. global $_course;
  603. $thread_id = 1;
  604. $course_db = $_course['dbName'];
  605. $user_id = 1;
  606. $res = get_thread_user_post_limit($course_db, $thread_id, $user_id, $limit=10);
  607. if(!is_null($res)){
  608. $this->assertTrue(is_array($res));
  609. } else {
  610. $this->assertTrue(is_null($res));
  611. }
  612. //var_dump($res);
  613. }
  614. /**
  615. * This function retrieves forum thread users details
  616. * @param int Thread ID
  617. * @param string Course DB name (optional)
  618. * @return resource Array of type ([user_id=>w,lastname=>x,firstname=>y,thread_id=>z],[])
  619. */
  620. public function testget_thread_users_details() {
  621. $thread_id = 1;
  622. $res = get_thread_users_details($thread_id);
  623. if(!is_null($res)){
  624. $this->assertTrue(is_resource($res));
  625. } else {
  626. $this->assertTrue(is_null($res));
  627. }
  628. //var_dump($res);
  629. }
  630. /**
  631. * This function retrieves forum thread users not qualify
  632. * @param int Thread ID
  633. * @param string Course DB name (optional)
  634. * @return array Array of type ([user_id=>w,lastname=>x,firstname=>y,thread_id=>z],[])
  635. */
  636. public function testget_thread_users_not_qualify() {
  637. $thread_id = 1;
  638. $res = get_thread_users_not_qualify($thread_id, $db_name = null);
  639. if(!is_null($res)){
  640. $this->assertTrue(is_resource($res));
  641. } else {
  642. $this->assertTrue(is_null($res));
  643. }
  644. //var_dump($res);
  645. }
  646. /**
  647. * This function retrieves forum thread users qualify
  648. * @param int Thread ID
  649. * @param string Course DB name (optional)
  650. * @return array Array of type ([user_id=>w,lastname=>x,firstname=>y,thread_id=>z],[])
  651. */
  652. public function testget_thread_users_qualify() {
  653. $thread_id = 1;
  654. $res = get_thread_users_qualify($thread_id, $db_name = null);
  655. if(!is_bool($res)){
  656. $this->assertTrue(is_resource($res));
  657. } else {
  658. $this->assertTrue(is_bool($res));
  659. }
  660. //var_dump($res);
  661. }
  662. /**
  663. * Retrieve all the threads of a given forum
  664. * @param int forum id
  665. * @return an array containing all the information about the threads
  666. */
  667. public function testget_threads() {
  668. $forum_id = 1;
  669. $res = get_threads($forum_id);
  670. if(!is_bool($res)){
  671. $this->assertTrue(is_array($res));
  672. } else {
  673. $this->assertTrue(is_bool($res));
  674. }
  675. //var_dump($res);
  676. }
  677. /**
  678. * This function retrieves all the unapproved messages for a given forum
  679. * This is needed to display the icon that there are unapproved messages in that thread (only the courseadmin can see this)
  680. * @param $forum_id the forum where we want to know the unapproved messages of
  681. * @return array returns
  682. */
  683. public function testget_unaproved_messages() {
  684. $forum_id = 1;
  685. $res = get_unaproved_messages($forum_id);
  686. if(!is_bool($res)){
  687. $this->assertTrue(is_array($res));
  688. } else {
  689. $this->assertTrue(is_bool($res));
  690. }
  691. //var_dump($res);
  692. }
  693. /**
  694. * This function is used to find all the information about what's new in the forum tool
  695. * @return void
  696. */
  697. public function testget_whats_new() {
  698. $res = get_whats_new();
  699. $this->assertTrue(is_null($res));
  700. //var_dump($res);
  701. }
  702. /**
  703. * This function handles all the forum and forumcategories actions. This is a wrapper for the
  704. * forum and forum categories. All this code code could go into the section where this function is
  705. * called but this make the code there cleaner.
  706. * @return void
  707. */
  708. public function testhandle_forum_and_forumcategories() {
  709. $res = handle_forum_and_forumcategories();
  710. $this->assertTrue(is_null($res));
  711. //var_dump($res);
  712. }
  713. /**
  714. * This function is called whenever something is made visible because there might be new posts and the user might have indicated that (s)he wanted
  715. * to be informed about the new posts by mail.
  716. * @param string
  717. * @param int
  718. * @return string language variable
  719. */
  720. public function testhandle_mail_cue() {
  721. $content = 'test content';
  722. $id = 1;
  723. $res = handle_mail_cue($content, $id);
  724. $this->assertTrue(is_string($res));
  725. //var_dump($res);
  726. }
  727. /**
  728. * This function return the html syntax for the image
  729. * @param $image_url The url of the image (absolute or relative)
  730. * @param $alt The alt text (when the images cannot be displayed). http://www.w3.org/TR/html4/struct/objects.html#adef-alt
  731. * @param $title The title of the image. Most browsers display this as 'tool tip'. http://www.w3.org/TR/html4/struct/global.html#adef-title
  732. * @todo this is the same as the Display::xxx function, so it can be removed => all calls have to be changed also
  733. * @return string url image
  734. */
  735. public function testicon() {
  736. $image_url = api_get_path(WEB_IMG_PATH).'test.png';
  737. $res = icon($image_url,$alt='',$title='');
  738. $this->assertTrue(is_string($res));
  739. //var_dump($res);
  740. }
  741. /**
  742. * The thread view counter gets increased every time someone looks at the thread
  743. * @param int
  744. * @return void
  745. */
  746. public function testincrease_thread_view() {
  747. $thread_id = 1;
  748. $res = increase_thread_view($thread_id);
  749. $this->assertTrue(is_null($res));
  750. //var_dump($res);
  751. }
  752. /**
  753. * This function displays the form for moving a post message to a different (already existing) or a new thread.
  754. * @return void HTML
  755. */
  756. public function testmove_post_form() {
  757. ob_start();
  758. $res = move_post_form();
  759. ob_end_clean();
  760. $this->assertTrue(is_null($res));
  761. //var_dump($res);
  762. }
  763. /**
  764. * This function displays the form for moving a thread to a different (already existing) forum
  765. * @return void HTML
  766. */
  767. public function testmove_thread_form() {
  768. ob_start();
  769. $res = move_thread_form();
  770. ob_end_clean();
  771. $this->assertTrue(is_null($res));
  772. //var_dump($res);
  773. }
  774. /**
  775. * This function moves a forum or a forum category up or down
  776. * @param $content what is it that we want to make (in)visible: forum category, forum, thread, post
  777. * @param $direction do we want to move it up or down.
  778. * @param $id the id of the content we want to make invisible
  779. * @todo consider removing the table_item_property calls here but this can prevent unwanted side effects when a forum does not have an entry in
  780. * the item_property table but does have one in the forum table.
  781. * @return string language variable
  782. */
  783. public function testmove_up_down() {
  784. $content = 'test content';
  785. $direction = 'test direction';
  786. $id = 1;
  787. $res = move_up_down($content, $direction, $id);
  788. $this->assertTrue(is_string($res));
  789. //var_dump($res);
  790. }
  791. /**
  792. * Prepares a string or an array of strings for display by stripping slashes
  793. * @param mixed String or array of strings
  794. * @return mixed String or array of strings
  795. */
  796. public function testprepare4display() {
  797. $res = prepare4display($input='');
  798. $this->assertTrue(is_string($res));
  799. //var_dump($res);
  800. }
  801. /**
  802. * Return the link to the forum search page
  803. */
  804. public function testsearch_link() {
  805. $res = search_link();
  806. $this->assertTrue(is_string($res));
  807. //var_dump($res);
  808. }
  809. /**
  810. * This function sends the mails for the mail notification
  811. * @param array
  812. * @param array
  813. * @return void
  814. */
  815. public function testsend_mail() {
  816. $res = send_mail($user_info=array(), $thread_information=array());
  817. $this->assertTrue(is_null($res));
  818. //var_dump($res);
  819. }
  820. /**
  821. * This function sends the notification mails to everybody who stated that they wanted to be informed when a new post
  822. * was added to a given thread.
  823. * @param int id thread
  824. * @param array reply information
  825. * @return void
  826. */
  827. public function testsend_notification_mails() {
  828. $thread_id = 1;
  829. $reply_info = array('test');
  830. $res = send_notification_mails($thread_id, $reply_info);
  831. $this->assertTrue(is_null($res));
  832. //var_dump($res);
  833. }
  834. /**
  835. * Get all the users who need to receive a notification of a new post (those subscribed to
  836. * the forum or the thread)
  837. * @param integer $forum_id the id of the forum
  838. * @param integer $thread_id the id of the thread
  839. * @param integer $post_id the id of the post
  840. * @return bool
  841. */
  842. public function testsend_notifications() {
  843. $res = send_notifications($forum_id=0, $thread_id=0, $post_id=0);
  844. $this->assertTrue(is_bool($res));
  845. //var_dump($res);
  846. }
  847. /**
  848. * This function stores which users have to be notified of which forums or threads
  849. * @param string $content does the user want to be notified about a forum or about a thread
  850. * @param integer $id the id of the forum or thread
  851. * @return string language variable
  852. */
  853. public function testset_notification() {
  854. $content = 'test content';
  855. $id = 1;
  856. $res = set_notification($content,$id, $add_only = false);
  857. $this->assertTrue(is_string($res));
  858. //var_dump($res);
  859. }
  860. /**
  861. * This public function displays the form that is used to add a forum category.
  862. * @param array
  863. * @return void HTML
  864. */
  865. public function testshow_add_forum_form() {
  866. ob_start();
  867. $res = show_add_forum_form($inputvalues=array());
  868. ob_end_clean();
  869. $this->assertTrue(is_null($res));
  870. //var_dump($res);
  871. }
  872. /**
  873. * This public function displays the form that is used to add a forum category.
  874. * @param array input values
  875. * @return void HTML
  876. */
  877. public function testshow_add_forumcategory_form() {
  878. ob_start();
  879. $res = show_add_forumcategory_form($inputvalues=array());
  880. ob_end_clean();
  881. $this->assertTrue(is_null($res));
  882. //var_dump($res);
  883. }
  884. /**
  885. * This public function displays the form that is used to add a post. This can be a new thread or a reply.
  886. * @param $action is the parameter that determines if we are
  887. * 1. newthread: adding a new thread (both empty) => No I-frame
  888. * 2. replythread: Replying to a thread ($action = replythread) => I-frame with the complete thread (if enabled)
  889. * 3. replymessage: Replying to a message ($action =replymessage) => I-frame with the complete thread (if enabled) (I first thought to put and I-frame with the message only)
  890. * 4. quote: Quoting a message ($action= quotemessage) => I-frame with the complete thread (if enabled). The message will be in the reply. (I first thought not to put an I-frame here)
  891. * @return void HTML
  892. */
  893. public function testshow_add_post_form() {
  894. ob_start();
  895. $res = show_add_post_form($action='', $id='', $form_values='');
  896. ob_end_clean();
  897. $this->assertTrue(is_null($res));
  898. //var_dump($res);
  899. }
  900. /**
  901. * This public function displays the form that is used to edit a forum category.
  902. * This is more or less a copy from the show_add_forumcategory_form public function with the only difference that is uses
  903. * some default values. I tried to have both in one public function but this gave problems with the handle_forum_and_forumcategories public function
  904. * (storing was done twice)
  905. * @param array
  906. * @return void HTML
  907. */
  908. public function testshow_edit_forumcategory_form() {
  909. ob_start();
  910. $res = show_edit_forumcategory_form($inputvalues=array());
  911. ob_end_clean();
  912. $this->assertTrue(is_null($res));
  913. //var_dump($res);
  914. }
  915. /**
  916. * This public function displays the form that is used to edit a post. This can be a new thread or a reply.
  917. * @param array contains all the information about the current post
  918. * @param array contains all the information about the current thread
  919. * @param array contains all info about the current forum (to check if attachments are allowed)
  920. * @param array contains the default values to fill the form
  921. * @return void
  922. */
  923. public function testshow_edit_post_form() {
  924. ob_start();
  925. $current_post = array('test');
  926. $current_thread = array('test2');
  927. $current_forum = array('test3');
  928. $res = show_edit_post_form($current_post, $current_thread, $current_forum, $form_values='',$id_attach=0);
  929. ob_end_clean();
  930. $this->assertTrue(is_null($res));
  931. //var_dump($res);
  932. }
  933. /**
  934. * This public function show qualify.
  935. * @param string contains the information of option to run
  936. * @param string contains the information the current course id
  937. * @param integer contains the information the current forum id
  938. * @param integer contains the information the current user id
  939. * @param integer contains the information the current thread id
  940. * @return integer qualify
  941. * @example $option=1 obtained the qualification of the current thread
  942. */
  943. public function testShowQualify() {
  944. $option = 1;
  945. $user_id = 1;
  946. $thread_id = 1;
  947. $res = showQualify($option, $user_id, $thread_id);
  948. if(!is_numeric($res)){
  949. $this->assertTrue(is_null($res));
  950. } else {
  951. $this->assertTrue(is_numeric($res));
  952. }
  953. //var_dump($res);
  954. }
  955. /**
  956. * This function builds an array of all the posts in a given thread where the key of the array is the post_id
  957. * It also adds an element children to the array which itself is an array that contains all the id's of the first-level children
  958. * @return an array containing all the information on the posts of a thread
  959. */
  960. public function testcalculate_children() {
  961. $rows = array();
  962. $res = calculate_children($rows);
  963. $this->assertTrue(is_array($res));
  964. //var_dump($res);
  965. }
  966. public function test_forum_recursive_sort() {
  967. $rows = array();
  968. $res = forumRecursiveSort($rows, &$threads, $seed=0, $indent=0);
  969. $this->assertTrue(is_null($res));
  970. //var_dump($res);
  971. }
  972. /**
  973. * This public function stores the edit of a post in the forum_post table.
  974. * @param array
  975. * @return void HTML
  976. */
  977. public function teststore_edit_post() {
  978. $values = array('test');
  979. ob_start();
  980. $res = store_edit_post($values);
  981. ob_end_clean();
  982. $this->assertTrue(is_null($res));
  983. //var_dump($res);
  984. }
  985. /**
  986. * This public function stores the forum in the database. The new forum is added to the end.
  987. * @param array
  988. * @return string language variable
  989. */
  990. public function teststore_forum() {
  991. $values = array('test');
  992. ob_start();
  993. $res = store_forum($values);
  994. ob_end_clean();
  995. $this->assertTrue(is_string($res));
  996. //var_dump($res);
  997. }
  998. /**
  999. * This public function stores the forum category in the database. The new category is added to the end.
  1000. * @param array
  1001. * @return void HMTL language variable
  1002. */
  1003. public function teststore_forumcategory() {
  1004. $values = array('test');
  1005. ob_start();
  1006. $res = store_forumcategory($values);
  1007. ob_end_clean();
  1008. $this->assertTrue(is_null($res));
  1009. //var_dump($res);
  1010. }
  1011. /**
  1012. *
  1013. * @param array
  1014. * @return string HTML language variable
  1015. */
  1016. public function teststore_move_post() {
  1017. $values = array('test');
  1018. ob_start();
  1019. $res = store_move_post($values);
  1020. ob_end_clean();
  1021. $this->assertTrue(is_string($res));
  1022. //var_dump($res);
  1023. }
  1024. /**
  1025. * @param array
  1026. * @return string HTML language variable
  1027. */
  1028. public function teststore_move_thread() {
  1029. $values = array('test');
  1030. ob_start();
  1031. $res = store_move_thread($values);
  1032. ob_end_clean();
  1033. $this->assertTrue(is_string($res));
  1034. //var_dump($res);
  1035. }
  1036. /**
  1037. *
  1038. * This public function store qualify historical.
  1039. * @param boolean contains the information of option to run
  1040. * @param string contains the information the current course id
  1041. * @param integer contains the information the current forum id
  1042. * @param integer contains the information the current user id
  1043. * @param integer contains the information the current thread id
  1044. * @param integer contains the information the current qualify
  1045. * @return void
  1046. * @example $option=1 obtained the qualification of the current thread
  1047. */
  1048. public function testSaveThreadScoreHistory() {
  1049. $option = 1;
  1050. $couser_id = 1;
  1051. $forum_id = 1;
  1052. $user_id = 1;
  1053. $thread_id = 1;
  1054. $current_qualify = 1;
  1055. $qualify_user_id = 1;
  1056. $res = saveThreadScoreHistory($option,$couser_id,$forum_id,$user_id,$thread_id,$current_qualify,$qualify_user_id);
  1057. $this->assertTrue(is_null($res));
  1058. //var_dump($res);
  1059. }
  1060. /**
  1061. * This public function stores a reply in the forum_post table.
  1062. * It also updates the forum_threads table (thread_replies +1 , thread_last_post, thread_date)
  1063. */
  1064. public function teststore_reply() {
  1065. $values = array('test');
  1066. ob_start();
  1067. $res = store_reply($values);
  1068. ob_end_clean();
  1069. $this->assertTrue(is_null($res));
  1070. //var_dump($res);
  1071. }
  1072. /**
  1073. * @param integer contains the information of user id
  1074. * @param integer contains the information of thread id
  1075. * @param integer contains the information of thread qualify
  1076. * @param integer contains the information of user id of qualifier
  1077. * @param integer contains the information of time
  1078. * @param integer contains the information of session id
  1079. * @return Array() optional
  1080. **/
  1081. public function testSaveThreadScore()
  1082. {
  1083. $user_id = 1;
  1084. $thread_id = 1;
  1085. $qualify_time = 1;
  1086. $res = saveThreadScore(
  1087. $user_id,
  1088. $thread_id,
  1089. $thread_qualify = 0,
  1090. $qualify_user_id = 0,
  1091. $qualify_time,
  1092. $session_id = null
  1093. );
  1094. if (!is_bool($res)) {
  1095. $this->assertTrue(is_array($res));
  1096. } else {
  1097. $this->assertTrue(is_bool($res));
  1098. }
  1099. }
  1100. /**
  1101. * This public function stores a new thread. This is done through an entry in the forum_thread table AND
  1102. * in the forum_post table because. The threads are also stored in the item_property table. (forum posts are not (yet))
  1103. * @param array
  1104. * @return void HTML
  1105. */
  1106. public function teststore_thread() {
  1107. $values = array();
  1108. ob_start();
  1109. $res = store_thread($values);
  1110. ob_end_clean();
  1111. $this->assertTrue(is_null($res));
  1112. //var_dump($res);
  1113. }
  1114. /**
  1115. * The relies counter gets increased every time somebody replies to the thread
  1116. * @param
  1117. * @return void
  1118. */
  1119. public function testupdate_thread() {
  1120. $thread_id = 1;
  1121. $last_post_id = 1;
  1122. $post_date = 1;
  1123. $res = update_thread($thread_id, $last_post_id,$post_date);
  1124. $this->assertTrue(is_null($res));
  1125. //var_dump($res);
  1126. }
  1127. /**
  1128. * This public function is called when the user is not allowed in this forum/thread/...
  1129. * @return bool display message of "not allowed"
  1130. */
  1131. public function testforum_not_allowed_here() {
  1132. ob_start();
  1133. $res = forum_not_allowed_here();
  1134. ob_end_clean();
  1135. $this->assertTrue(is_bool($res));
  1136. //var_dump($res);
  1137. }
  1138. /**
  1139. * Delete the all the attachments from the DB and the file according to the post's id or attach id(optional)
  1140. * @param post id
  1141. * @param attach id (optional)
  1142. * @return void
  1143. */
  1144. public function testdelete_attachment() {
  1145. global $_course;
  1146. $post_id = 1;
  1147. $res = delete_attachment($post_id,$id_attach=0);
  1148. $this->assertTrue(is_null($res));
  1149. //var_dump($res);
  1150. }
  1151. /**
  1152. * This public function deletes a forum or a forum category
  1153. * This public function currently does not delete the forums inside the category, nor the threads and replies inside these forums.
  1154. * For the moment this is the easiest method and it has the advantage that it allows to recover fora that were acidently deleted
  1155. * when the forum category got deleted.
  1156. *
  1157. * @param $content = what we are deleting (a forum or a forum category)
  1158. * @param $id The id of the forum category that has to be deleted.
  1159. * @return void
  1160. * @todo write the code for the cascading deletion of the forums inside a forum category and also the threads and replies inside these forums
  1161. * @todo config setting for recovery or not (see also the documents tool: real delete or not).
  1162. */
  1163. public function testdeleteForumCategoryThread() {
  1164. $content= 'testcontent';
  1165. $id = 1;
  1166. $res = deleteForumCategoryThread($content, $id);
  1167. $this->assertTrue(is_null($res));
  1168. //var_dump($res);
  1169. }
  1170. /**
  1171. * This public function deletes the forum image if exists
  1172. * @param int forum id
  1173. * @return boolean true if success
  1174. */
  1175. public function testdelete_forum_image() {
  1176. $forum_id = 1;
  1177. $res = delete_forum_image($forum_id);
  1178. $this->assertTrue(is_bool($res));
  1179. //var_dump($res);
  1180. }
  1181. /**
  1182. * This public function deletes a forum post. This separate public function is needed because forum posts do not appear in the item_property table (yet)
  1183. * and because deleting a post also has consequence on the posts that have this post as parent_id (they are also deleted).
  1184. * an alternative would be to store the posts also in item_property and mark this post as deleted (visibility = 2).
  1185. * We also have to decrease the number of replies in the thread table
  1186. * @return string language variable
  1187. * @param $post_id the id of the post that will be deleted
  1188. * @todo write recursive public function that deletes all the posts that have this message as parent
  1189. */
  1190. public function testdelete_post() {
  1191. $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
  1192. $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
  1193. $post_id = 1;
  1194. $res = delete_post($post_id);
  1195. $this->assertTrue(is_string($res));
  1196. //var_dump($res);
  1197. }
  1198. public function __destruct() {
  1199. // The destructor acts like a global tearDown for the class
  1200. require_once api_get_path(SYS_TEST_PATH).'teardown.inc.php';
  1201. }
  1202. }
  1203. ?>