forumfunction.inc.test.php 36 KB

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