forumfunction.inc.test.php 38 KB

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