123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311 |
- <?php
- require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/gradebookitem.class.php';
- require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/abstractlink.class.php';
- require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/evallink.class.php';
- class TestForumFunction extends UnitTestCase {
- public function TestForumFunction() {
- $this->UnitTestCase('Test forum function');
- }
- public function __construct() {
- // The constructor acts like a global setUp for the class
- require_once api_get_path(SYS_TEST_PATH).'setup.inc.php';
- }
- /**
- * This function add a attachment file into forum
- * @param string a comment about file
- * @param int last id from forum_post table
- * @return void
- */
- public function testadd_forum_attachment_file() {
- global $_course;
- $file_comment='testcoment';
- $last_id = 1;
- $res = add_forum_attachment_file($file_comment,$last_id);
- $this->assertTrue(is_null($res));
- //var_dump($res);
- }
- /**
- * This function approves a post = change
- *
- * @param $post_id the id of the post that will be deleted
- * @param $action make the post visible or invisible
- * @return string language variable
- */
- public function testapprove_post() {
- $action= 'invisible';
- $post_id = 1;
- $res = approve_post($post_id, $action);
- $this->assertTrue(is_string($res));
- //var_dump($res);
- }
- /**
- * This function changes the lock status in the database
- *
- * @param $content what is it that we want to (un)lock: forum category, forum, thread, post
- * @param $id the id of the content we want to (un)lock
- * @param $action do we lock (=>locked value in db = 1) or unlock (=> locked value in db = 0)
- * @return string, language variable
- * @todo move to itemmanager
- */
- public function testchange_lock_status() {
- $content = 'testcontent';
- $action= 'invisible';
- $id = 1;
- $res = change_lock_status($content, $id, $action);
- $this->assertTrue(is_string($res));
- //var_dump($res);
- }
- /**
- * This function changes the visibility in the database (item_property)
- *
- * @param $content what is it that we want to make (in)visible: forum category, forum, thread, post
- * @param $id the id of the content we want to make invisible
- * @param $target_visibility what is the current status of the visibility (0 = invisible, 1 = visible)
- * @todo change the get parameter so that it matches the tool constants.
- * @todo check if api_item_property_update returns true or false => returnmessage depends on it.
- * @todo move to itemmanager
- * @return string language variable
- */
- public function testchange_visibility() {
- $content= 'testcontent';
- $target_visibility = 1;
- $id = 1;
- $res = change_visibility($content, $id, $target_visibility);
- $this->assertTrue(is_string($res));
- //var_dump($res);
- }
- /**
- * This function gets the all information of the last (=most recent) post of the thread
- * This can be done by sorting the posts that have the field thread_id=$thread_id and sort them by post_date
- * @param $thread_id the id of the thread we want to know the last post of.
- * @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
- */
- public function testcheck_if_last_post_of_thread() {
- $thread_id = 1;
- $res = check_if_last_post_of_thread($thread_id);
- if(!is_bool($res)) {
- $this->assertTrue(is_array($res));
- }
- //var_dump($res);
- }
- /**
- * This function returns a piece of html code that make the links grey (=invisible for the student)
- * @param boolean 0/1: 0 = invisible, 1 = visible
- * @return string language variable
- */
- public function testclass_visible_invisible() {
- $current_visibility_status = 0;
- $res = class_visible_invisible($current_visibility_status);
- $this->assertTrue(is_string($res));
- //var_dump($res);
- }
- /**
- * This function counts the number of forums inside a given category
- * @param $cat_id the id of the forum category
- * @todo an additional parameter that takes the visibility into account. For instance $countinvisible=0 would return the number
- * of visible forums, $countinvisible=1 would return the number of visible and invisible forums
- * @return int the number of forums inside the given category
- */
- public function testcount_number_of_forums_in_category() {
- $cat_id = 1;
- $res = count_number_of_forums_in_category($cat_id);
- $this->assertTrue(is_numeric($res));
- //var_dump($res);
- }
- /**
- * This function counts the number of post inside a thread user
- * @param int Thread ID
- * @param int User ID
- * @return int the number of post inside a thread user
- */
- public function testcount_number_of_post_for_user_thread() {
- $thread_id = 1;
- $user_id = 1;
- $res = count_number_of_post_for_user_thread($thread_id, $user_id);
- $this->assertTrue(is_numeric($res));
- //var_dump($res);
- }
- /**
- * This function counts the number of post inside a thread
- * @param int Thread ID
- * @return int the number of post inside a thread
- */
- public function testcount_number_of_post_in_thread() {
- $thread_id = 1;
- $res = count_number_of_post_in_thread($thread_id);
- $this->assertTrue(is_numeric($res));
- //var_dump($res);
- }
- /**
- * This function counts the number of user register in course
- * @param int Course ID
- * @return int the number of user register in course
- */
- public function testcount_number_of_user_in_course() {
- global $cidReq;
- $course_id = $cidReq;
- $res = count_number_of_user_in_course($course_id);
- $this->assertTrue(is_numeric($res));
- //var_dump($res);
- }
- /**
- *
- * This function show current thread qualify .
- * @param integer contains the information the current thread id
- * @param integer contains the information the current session id
- * @return array or null if is empty
- */
- public function testcurrent_qualify_of_thread() {
- $thread_id = 1;
- $session_id = 1;
- $res = current_qualify_of_thread($thread_id,$session_id);
- $this->assertTrue(is_null($res));
- //var_dump($res);
- }
- /**
- * Display the search results
- * @return void HTML - display the results
- */
- public function testdisplay_forum_search_results() {
- global $origin;
- $search_term = 'testterm';
- ob_start();
- $res = display_forum_search_results($search_term);
- ob_end_clean();
- $this->assertTrue(is_null($res));
- //var_dump($res);
- }
- /**
- * This function displays the user image from the profile, with a link to the user's details.
- * @param int User's database ID
- * @param str User's name
- * @return string An HTML with the anchor and the image of the user
- */
- public function testdisplay_user_image() {
- $name = 'testcontent';
- $user_id = 1;
- $res = display_user_image($user_id,$name, $origin='');
- $this->assertTrue(is_string($res));
- //var_dump($res);
- }
- /**
- * This function displays the firstname and lastname of the user as a link to the user tool.
- * @param string
- * @return string HTML
- */
- public function testdisplay_user_link() {
- $name = 'testcontent';
- $user_id = 1;
- $res = display_user_link($user_id, $name, $origin='');
- $this->assertTrue(is_string($res));
- //var_dump($res);
- }
- /**
- * This function edit a attachment file into forum
- * @param string a comment about file
- * @param int Post Id
- * @param int attachment file Id
- * @return void
- */
- public function testedit_forum_attachment_file() {
- $file_comment = 'testcontent';
- $id_attach = 1;
- $post_id = 1;
- $res = edit_forum_attachment_file($file_comment,$post_id,$id_attach);
- $this->assertTrue(is_null($res));
- //var_dump($res);
- }
- /**
- * Display the search form for the forum and display the search results
- * @return void display an HTML search results
- */
- public function testforum_search() {
- ob_start();
- $res = forum_search();
- ob_end_clean();
- $this->assertTrue(is_null($res));
- //var_dump($res);
- }
- /** This function gets all the post written by an user
- * @param int user id
- * @param string db course name
- * @return string
- */
- public function testget_all_post_from_user() {
- global $_course;
- $course_db = $_course['dbName'];
- $user_id = 1;
- $res = get_all_post_from_user($user_id, $course_db);
- $this->assertTrue(is_string($res));
- //var_dump($res);
- }
- /**
- * Show a list with all the attachments according to the post's id
- * @param the post's id
- * @return array with the post info
- */
- public function testget_attachment() {
- $post_id = 1;
- $res = get_attachment($post_id);
- $this->assertTrue(is_array($res));
- //var_dump($res);
- }
- /**
- * Retrieve all the information off the forum categories (or one specific) for the current course.
- * The categories are sorted according to their sorting order (cat_order
- * @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.
- * @return an array containing all the information about all the forum categories
- */
- public function testget_forum_categories() {
- $res = get_forum_categories($id='');
- $this->assertTrue(is_array($res));
- //var_dump($res);
- }
- /**
- * This function retrieves all the information of a given forum_id
- * @param $forum_id integer that indicates the forum
- * @return array returns
- * @deprecated this functionality is now moved to get_forums($forum_id)
- */
- /*
- function testget_forum_information() {
- $forum_id = 1;
- $res = get_forum_information($forum_id);
- $this->assertTrue(is_array($res));
- //var_dump($res);
- }*/
- /**
- * This function retrieves all the information of a given forumcategory id
- * @param $forum_id integer that indicates the forum
- * @return array returns if there are category
- * @return bool returns if there aren't category
- */
- public function testget_forumcategory_information() {
- $cat_id = 1;
- $res = get_forumcategory_information($cat_id);
- if(!is_bool($res)){
- $this->assertTrue(is_array($res));
- } else {
- $this->assertTrue(is_bool($res));
- }
- //var_dump($res);
- }
- /**
- * Retrieve all the forums (regardless of their category) or of only one. The forums are sorted according to the forum_order.
- * Since it does not take the forum category into account there probably will be two or more forums that have forum_order=1, ...
- * @return an array containing all the information about the forums (regardless of their category)
- * @todo check $sql4 because this one really looks fishy.
- */
- public function testget_forums() {
- $res = get_forums($id='');
- if(!is_bool($res)){
- $this->assertTrue(is_array($res));
- } else {
- $this->assertTrue(is_bool($res));
- }
- //var_dump($res);
- }
- /**
- * This function retrieves all the fora in a given forum category
- * @param integer $cat_id the id of the forum category
- * @return an array containing all the information about the forums (regardless of their category)
- */
- public function testget_forums_in_category() {
- $cat_id = 1;
- $res = get_forums_in_category($cat_id);
- if(!is_bool($res)){
- $this->assertTrue(is_array($res));
- } else {
- $this->assertTrue(is_bool($res));
- }
- //var_dump($res);
- }
- /**
- * This function gets all the forum information of the all the forum of the group
- * @param integer $group_id the id of the group we need the fora of (see forum.forum_of_group)
- * @return array
- * @todo this is basically the same code as the get_forums function. Consider merging the two.
- */
- public function testget_forums_of_group() {
- $group_id = 1;
- $res = get_forums_of_group($group_id);
- if(!is_null($res)){
- $this->assertTrue(is_array($res));
- } else {
- $this->assertTrue(is_null($res));
- }
- //var_dump($res);
- }
- /**
- *
- * This function get qualify historical.
- * @param integer contains the information the current user id
- * @param integer contains the information the current thread id
- * @param boolean contains the information of option to run
- * @return array()
- */
- public function testGetThreadScoreHistory() {
- $user_id = 1;
- $thread_id = 1;
- $opt = true;
- $res = getThreadScoreHistory($user_id,$thread_id,$opt);
- if(!is_null($res)){
- $this->assertTrue(is_array($res));
- } else {
- $this->assertTrue(is_null($res));
- }
- //var_dump($res);
- }
- /**
- * This functions gets all the last post information of a certain forum
- * @param $forum_id the id of the forum we want to know the last post information of.
- * @param $show_invisibles
- * @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)
- */
- public function testget_last_post_information() {
- $forum_id = 1;
- $res = get_last_post_information($forum_id, $show_invisibles=false);
- if(!is_null($res)){
- $this->assertTrue(is_array($res));
- } else {
- $this->assertTrue(is_null($res));
- }
- //var_dump($res);
- }
- /** This function get the name of an thread by id
- * @param int thread_id
- * @return String
- **/
- public function testget_name_thread_by_id() {
- $thread_id = 1;
- $res = get_name_thread_by_id($thread_id);
- if(!is_null($res)){
- $this->assertTrue(is_string($res));
- } else {
- $this->assertTrue(is_null($res));
- }
- //var_dump($res);
- }
- /** This function get the name of an user by id
- * @param user_id int
- * return String
- */
- public function testget_name_user_by_id() {
- $user_id = 1;
- $res = get_name_user_by_id($user_id);
- if(!is_null($res)){
- $this->assertTrue(is_string($res));
- } else {
- $this->assertTrue(is_null($res));
- }
- //var_dump($res);
- }
- /**
- * This function retrieves all the email adresses of the users who wanted to be notified
- * about a new post in a certain forum or thread
- * @param string $content does the user want to be notified about a forum or about a thread
- * @param integer $id the id of the forum or thread
- * @return array
- */
- public function testget_notifications() {
- $id = 1;
- $content = 'test message notified';
- $res = get_notifications($content,$id);
- if(!is_null($res)){
- $this->assertTrue(is_array($res));
- } else {
- $this->assertTrue(is_null($res));
- }
- //var_dump($res);
- }
- /**
- * Get all the notification subscriptions of the user
- * = which forums and which threads does the user wants to be informed of when a new
- * post is added to this thread
- * @param integer $user_id the user_id of a user (default = 0 => the current user)
- * @param boolean $force force get the notification subscriptions (even if the information is already in the session
- * @return array
- */
- public function testget_notifications_of_user() {
- $res = get_notifications_of_user($user_id = 0, $force = false);
- if(!is_null($res)){
- $this->assertTrue(is_string($res));
- } else {
- $this->assertTrue(is_null($res));
- }
- //var_dump($res);
- }
- /**
- * This function retrieves all the information of a post
- * @param $forum_id integer that indicates the forum
- * @return array returns
- */
- public function testget_post_information() {
- $post_id = 1;
- $res = get_post_information($post_id);
- if(!is_null($res)){
- $this->assertTrue(is_array($res));
- } else {
- $this->assertTrue(is_null($res));
- }
- //var_dump($res);
- }
- /**
- * With this function we find the number of posts and topics in a given forum.
- * @param int
- * @return array
- * @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
- * 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)
- * @todo consider merging both in one query.
- * @deprecated the counting mechanism is now inside the function get_forums
- */
- /*
- function testget_post_topics_of_forum() {
- $forum_id = 1;
- $res = get_post_topics_of_forum($forum_id);
- if(!is_null($res)){
- $this->assertTrue(is_array($res));
- } else {
- $this->assertTrue(is_null($res));
- }
- //var_dump($res);
- }*/
- /**
- * Retrieve all posts of a given thread
- * @param int $thread_id integer that indicates the forum
- * @return an array containing all the information about the posts of a given thread
- */
- public function testget_posts() {
- $thread_id = 1;
- $res = getPosts($thread_id);
- if(!is_null($res)){
- $this->assertTrue(is_array($res));
- } else {
- $this->assertTrue(is_null($res));
- }
- //var_dump($res);
- }
- /**
- * This function retrieves information of statistical
- * @param int Thread ID
- * @param int User ID
- * @param int Course ID
- * @return array the information of statistical
- */
- public function testget_statistical_information() {
- $thread_id = 1;
- $user_id = 1;
- $course_id = 1;
- $res = get_statistical_information($thread_id, $user_id, $course_id);
- if(!is_null($res)){
- $this->assertTrue(is_array($res));
- } else {
- $this->assertTrue(is_null($res));
- }
- //var_dump($res);
- }
- /**
- * This function retrieves all the information of a thread
- * @param $forum_id integer that indicates the forum
- * @return array returns
- */
- function testget_thread_information() {
- $thread_id = 1;
- $res = get_thread_information($thread_id);
- if(!is_bool($res)){
- $this->assertTrue(is_array($res));
- } else {
- $this->assertTrue(is_bool($res));
- }
- //var_dump($res);
- }
- /**
- * This function return the posts inside a thread from a given user
- * @param course code
- * @param int Thread ID
- * @param int User ID
- * @return int the number of post inside a thread
- */
- public function testget_thread_user_post() {
- global $_course;
- $thread_id = 1;
- $course_db = $_course['dbName'];
- $user_id = 1;
- $res = get_thread_user_post($course_db, $thread_id, $user_id );
- if(!is_null($res)){
- $this->assertTrue(is_array($res));
- } else {
- $this->assertTrue(is_null($res));
- }
- //var_dump($res);
- }
- /**
- * @param string
- * @param int
- * @param int
- * @param int
- * @return void
- */
- public function testget_thread_user_post_limit() {
- global $_course;
- $thread_id = 1;
- $course_db = $_course['dbName'];
- $user_id = 1;
- $res = get_thread_user_post_limit($course_db, $thread_id, $user_id, $limit=10);
- if(!is_null($res)){
- $this->assertTrue(is_array($res));
- } else {
- $this->assertTrue(is_null($res));
- }
- //var_dump($res);
- }
- /**
- * This function retrieves forum thread users details
- * @param int Thread ID
- * @param string Course DB name (optional)
- * @return resource Array of type ([user_id=>w,lastname=>x,firstname=>y,thread_id=>z],[])
- */
- public function testget_thread_users_details() {
- $thread_id = 1;
- $res = get_thread_users_details($thread_id);
- if(!is_null($res)){
- $this->assertTrue(is_resource($res));
- } else {
- $this->assertTrue(is_null($res));
- }
- //var_dump($res);
- }
- /**
- * This function retrieves forum thread users not qualify
- * @param int Thread ID
- * @param string Course DB name (optional)
- * @return array Array of type ([user_id=>w,lastname=>x,firstname=>y,thread_id=>z],[])
- */
- public function testget_thread_users_not_qualify() {
- $thread_id = 1;
- $res = get_thread_users_not_qualify($thread_id, $db_name = null);
- if(!is_null($res)){
- $this->assertTrue(is_resource($res));
- } else {
- $this->assertTrue(is_null($res));
- }
- //var_dump($res);
- }
- /**
- * This function retrieves forum thread users qualify
- * @param int Thread ID
- * @param string Course DB name (optional)
- * @return array Array of type ([user_id=>w,lastname=>x,firstname=>y,thread_id=>z],[])
- */
- public function testget_thread_users_qualify() {
- $thread_id = 1;
- $res = get_thread_users_qualify($thread_id, $db_name = null);
- if(!is_bool($res)){
- $this->assertTrue(is_resource($res));
- } else {
- $this->assertTrue(is_bool($res));
- }
- //var_dump($res);
- }
- /**
- * Retrieve all the threads of a given forum
- * @param int forum id
- * @return an array containing all the information about the threads
- */
- public function testget_threads() {
- $forum_id = 1;
- $res = get_threads($forum_id);
- if(!is_bool($res)){
- $this->assertTrue(is_array($res));
- } else {
- $this->assertTrue(is_bool($res));
- }
- //var_dump($res);
- }
- /**
- * This function retrieves all the unapproved messages for a given forum
- * This is needed to display the icon that there are unapproved messages in that thread (only the courseadmin can see this)
- * @param $forum_id the forum where we want to know the unapproved messages of
- * @return array returns
- */
- public function testget_unaproved_messages() {
- $forum_id = 1;
- $res = get_unaproved_messages($forum_id);
- if(!is_bool($res)){
- $this->assertTrue(is_array($res));
- } else {
- $this->assertTrue(is_bool($res));
- }
- //var_dump($res);
- }
- /**
- * This function is used to find all the information about what's new in the forum tool
- * @return void
- */
- public function testget_whats_new() {
- $res = get_whats_new();
- $this->assertTrue(is_null($res));
- //var_dump($res);
- }
- /**
- * This function handles all the forum and forumcategories actions. This is a wrapper for the
- * forum and forum categories. All this code code could go into the section where this function is
- * called but this make the code there cleaner.
- * @return void
- */
- public function testhandle_forum_and_forumcategories() {
- $res = handle_forum_and_forumcategories();
- $this->assertTrue(is_null($res));
- //var_dump($res);
- }
- /**
- * 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
- * to be informed about the new posts by mail.
- * @param string
- * @param int
- * @return string language variable
- */
- public function testhandle_mail_cue() {
- $content = 'test content';
- $id = 1;
- $res = handle_mail_cue($content, $id);
- $this->assertTrue(is_string($res));
- //var_dump($res);
- }
- /**
- * This function return the html syntax for the image
- * @param $image_url The url of the image (absolute or relative)
- * @param $alt The alt text (when the images cannot be displayed). http://www.w3.org/TR/html4/struct/objects.html#adef-alt
- * @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
- * @todo this is the same as the Display::xxx function, so it can be removed => all calls have to be changed also
- * @return string url image
- */
- public function testicon() {
- $image_url = api_get_path(WEB_IMG_PATH).'test.png';
- $res = icon($image_url,$alt='',$title='');
- $this->assertTrue(is_string($res));
- //var_dump($res);
- }
- /**
- * The thread view counter gets increased every time someone looks at the thread
- * @param int
- * @return void
- */
- public function testincrease_thread_view() {
- $thread_id = 1;
- $res = increase_thread_view($thread_id);
- $this->assertTrue(is_null($res));
- //var_dump($res);
- }
- /**
- * This function displays the form for moving a post message to a different (already existing) or a new thread.
- * @return void HTML
- */
- public function testmove_post_form() {
- ob_start();
- $res = move_post_form();
- ob_end_clean();
- $this->assertTrue(is_null($res));
- //var_dump($res);
- }
- /**
- * This function displays the form for moving a thread to a different (already existing) forum
- * @return void HTML
- */
- public function testmove_thread_form() {
- ob_start();
- $res = move_thread_form();
- ob_end_clean();
- $this->assertTrue(is_null($res));
- //var_dump($res);
- }
- /**
- * This function moves a forum or a forum category up or down
- * @param $content what is it that we want to make (in)visible: forum category, forum, thread, post
- * @param $direction do we want to move it up or down.
- * @param $id the id of the content we want to make invisible
- * @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
- * the item_property table but does have one in the forum table.
- * @return string language variable
- */
- public function testmove_up_down() {
- $content = 'test content';
- $direction = 'test direction';
- $id = 1;
- $res = move_up_down($content, $direction, $id);
- $this->assertTrue(is_string($res));
- //var_dump($res);
- }
- /**
- * Prepares a string or an array of strings for display by stripping slashes
- * @param mixed String or array of strings
- * @return mixed String or array of strings
- */
- public function testprepare4display() {
- $res = prepare4display($input='');
- $this->assertTrue(is_string($res));
- //var_dump($res);
- }
- /**
- * Return the link to the forum search page
- */
- public function testsearch_link() {
- $res = search_link();
- $this->assertTrue(is_string($res));
- //var_dump($res);
- }
- /**
- * This function sends the mails for the mail notification
- * @param array
- * @param array
- * @return void
- */
- public function testsend_mail() {
- $res = send_mail($user_info=array(), $thread_information=array());
- $this->assertTrue(is_null($res));
- //var_dump($res);
- }
- /**
- * This function sends the notification mails to everybody who stated that they wanted to be informed when a new post
- * was added to a given thread.
- * @param int id thread
- * @param array reply information
- * @return void
- */
- public function testsend_notification_mails() {
- $thread_id = 1;
- $reply_info = array('test');
- $res = send_notification_mails($thread_id, $reply_info);
- $this->assertTrue(is_null($res));
- //var_dump($res);
- }
- /**
- * Get all the users who need to receive a notification of a new post (those subscribed to
- * the forum or the thread)
- * @param integer $forum_id the id of the forum
- * @param integer $thread_id the id of the thread
- * @param integer $post_id the id of the post
- * @return bool
- */
- public function testsend_notifications() {
- $res = send_notifications($forum_id=0, $thread_id=0, $post_id=0);
- $this->assertTrue(is_bool($res));
- //var_dump($res);
- }
- /**
- * This function stores which users have to be notified of which forums or threads
- * @param string $content does the user want to be notified about a forum or about a thread
- * @param integer $id the id of the forum or thread
- * @return string language variable
- */
- public function testset_notification() {
- $content = 'test content';
- $id = 1;
- $res = set_notification($content,$id, $add_only = false);
- $this->assertTrue(is_string($res));
- //var_dump($res);
- }
- /**
- * This public function displays the form that is used to add a forum category.
- * @param array
- * @return void HTML
- */
- public function testshow_add_forum_form() {
- ob_start();
- $res = show_add_forum_form($inputvalues=array());
- ob_end_clean();
- $this->assertTrue(is_null($res));
- //var_dump($res);
- }
- /**
- * This public function displays the form that is used to add a forum category.
- * @param array input values
- * @return void HTML
- */
- public function testshow_add_forumcategory_form() {
- ob_start();
- $res = show_add_forumcategory_form($inputvalues=array());
- ob_end_clean();
- $this->assertTrue(is_null($res));
- //var_dump($res);
- }
- /**
- * This public function displays the form that is used to add a post. This can be a new thread or a reply.
- * @param $action is the parameter that determines if we are
- * 1. newthread: adding a new thread (both empty) => No I-frame
- * 2. replythread: Replying to a thread ($action = replythread) => I-frame with the complete thread (if enabled)
- * 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)
- * 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)
- * @return void HTML
- */
- public function testshow_add_post_form() {
- ob_start();
- $res = show_add_post_form($action='', $id='', $form_values='');
- ob_end_clean();
- $this->assertTrue(is_null($res));
- //var_dump($res);
- }
- /**
- * This public function displays the form that is used to edit a forum category.
- * This is more or less a copy from the show_add_forumcategory_form public function with the only difference that is uses
- * some default values. I tried to have both in one public function but this gave problems with the handle_forum_and_forumcategories public function
- * (storing was done twice)
- * @param array
- * @return void HTML
- */
- public function testshow_edit_forumcategory_form() {
- ob_start();
- $res = show_edit_forumcategory_form($inputvalues=array());
- ob_end_clean();
- $this->assertTrue(is_null($res));
- //var_dump($res);
- }
- /**
- * This public function displays the form that is used to edit a post. This can be a new thread or a reply.
- * @param array contains all the information about the current post
- * @param array contains all the information about the current thread
- * @param array contains all info about the current forum (to check if attachments are allowed)
- * @param array contains the default values to fill the form
- * @return void
- */
- public function testshow_edit_post_form() {
- ob_start();
- $current_post = array('test');
- $current_thread = array('test2');
- $current_forum = array('test3');
- $res = show_edit_post_form($current_post, $current_thread, $current_forum, $form_values='',$id_attach=0);
- ob_end_clean();
- $this->assertTrue(is_null($res));
- //var_dump($res);
- }
- /**
- * This public function show qualify.
- * @param string contains the information of option to run
- * @param string contains the information the current course id
- * @param integer contains the information the current forum id
- * @param integer contains the information the current user id
- * @param integer contains the information the current thread id
- * @return integer qualify
- * @example $option=1 obtained the qualification of the current thread
- */
- public function testShowQualify() {
- $option = 1;
- $user_id = 1;
- $thread_id = 1;
- $res = showQualify($option, $user_id, $thread_id);
- if(!is_numeric($res)){
- $this->assertTrue(is_null($res));
- } else {
- $this->assertTrue(is_numeric($res));
- }
- //var_dump($res);
- }
- /**
- * This function builds an array of all the posts in a given thread where the key of the array is the post_id
- * 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
- * @return an array containing all the information on the posts of a thread
- */
- public function testcalculate_children() {
- $rows = array();
- $res = calculate_children($rows);
- $this->assertTrue(is_array($res));
- //var_dump($res);
- }
- public function test_forum_recursive_sort() {
- $rows = array();
- $res = forumRecursiveSort($rows, &$threads, $seed=0, $indent=0);
- $this->assertTrue(is_null($res));
- //var_dump($res);
- }
- /**
- * This public function stores the edit of a post in the forum_post table.
- * @param array
- * @return void HTML
- */
- public function teststore_edit_post() {
- $values = array('test');
- ob_start();
- $res = store_edit_post($values);
- ob_end_clean();
- $this->assertTrue(is_null($res));
- //var_dump($res);
- }
- /**
- * This public function stores the forum in the database. The new forum is added to the end.
- * @param array
- * @return string language variable
- */
- public function teststore_forum() {
- $values = array('test');
- ob_start();
- $res = store_forum($values);
- ob_end_clean();
- $this->assertTrue(is_string($res));
- //var_dump($res);
- }
- /**
- * This public function stores the forum category in the database. The new category is added to the end.
- * @param array
- * @return void HMTL language variable
- */
- public function teststore_forumcategory() {
- $values = array('test');
- ob_start();
- $res = store_forumcategory($values);
- ob_end_clean();
- $this->assertTrue(is_null($res));
- //var_dump($res);
- }
- /**
- *
- * @param array
- * @return string HTML language variable
- */
- public function teststore_move_post() {
- $values = array('test');
- ob_start();
- $res = store_move_post($values);
- ob_end_clean();
- $this->assertTrue(is_string($res));
- //var_dump($res);
- }
- /**
- * @param array
- * @return string HTML language variable
- */
- public function teststore_move_thread() {
- $values = array('test');
- ob_start();
- $res = store_move_thread($values);
- ob_end_clean();
- $this->assertTrue(is_string($res));
- //var_dump($res);
- }
- /**
- *
- * This public function store qualify historical.
- * @param boolean contains the information of option to run
- * @param string contains the information the current course id
- * @param integer contains the information the current forum id
- * @param integer contains the information the current user id
- * @param integer contains the information the current thread id
- * @param integer contains the information the current qualify
- * @return void
- * @example $option=1 obtained the qualification of the current thread
- */
- public function testSaveThreadScoreHistory() {
- $option = 1;
- $couser_id = 1;
- $forum_id = 1;
- $user_id = 1;
- $thread_id = 1;
- $current_qualify = 1;
- $qualify_user_id = 1;
- $res = saveThreadScoreHistory($option,$couser_id,$forum_id,$user_id,$thread_id,$current_qualify,$qualify_user_id);
- $this->assertTrue(is_null($res));
- //var_dump($res);
- }
- /**
- * This public function stores a reply in the forum_post table.
- * It also updates the forum_threads table (thread_replies +1 , thread_last_post, thread_date)
- */
- public function teststore_reply() {
- $values = array('test');
- ob_start();
- $res = store_reply($values);
- ob_end_clean();
- $this->assertTrue(is_null($res));
- //var_dump($res);
- }
- /**
- * @param integer contains the information of user id
- * @param integer contains the information of thread id
- * @param integer contains the information of thread qualify
- * @param integer contains the information of user id of qualifier
- * @param integer contains the information of time
- * @param integer contains the information of session id
- * @return Array() optional
- **/
- public function testSaveThreadScore()
- {
- $user_id = 1;
- $thread_id = 1;
- $qualify_time = 1;
- $res = saveThreadScore(
- $user_id,
- $thread_id,
- $thread_qualify = 0,
- $qualify_user_id = 0,
- $qualify_time,
- $session_id = null
- );
- if (!is_bool($res)) {
- $this->assertTrue(is_array($res));
- } else {
- $this->assertTrue(is_bool($res));
- }
- }
- /**
- * This public function stores a new thread. This is done through an entry in the forum_thread table AND
- * in the forum_post table because. The threads are also stored in the item_property table. (forum posts are not (yet))
- * @param array
- * @return void HTML
- */
- public function teststore_thread() {
- $values = array();
- ob_start();
- $res = store_thread($values);
- ob_end_clean();
- $this->assertTrue(is_null($res));
- //var_dump($res);
- }
- /**
- * The relies counter gets increased every time somebody replies to the thread
- * @param
- * @return void
- */
- public function testupdate_thread() {
- $thread_id = 1;
- $last_post_id = 1;
- $post_date = 1;
- $res = update_thread($thread_id, $last_post_id,$post_date);
- $this->assertTrue(is_null($res));
- //var_dump($res);
- }
- /**
- * This public function is called when the user is not allowed in this forum/thread/...
- * @return bool display message of "not allowed"
- */
- public function testforum_not_allowed_here() {
- ob_start();
- $res = forum_not_allowed_here();
- ob_end_clean();
- $this->assertTrue(is_bool($res));
- //var_dump($res);
- }
- /**
- * Delete the all the attachments from the DB and the file according to the post's id or attach id(optional)
- * @param post id
- * @param attach id (optional)
- * @return void
- */
- public function testdelete_attachment() {
- global $_course;
- $post_id = 1;
- $res = delete_attachment($post_id,$id_attach=0);
- $this->assertTrue(is_null($res));
- //var_dump($res);
- }
- /**
- * This public function deletes a forum or a forum category
- * This public function currently does not delete the forums inside the category, nor the threads and replies inside these forums.
- * For the moment this is the easiest method and it has the advantage that it allows to recover fora that were acidently deleted
- * when the forum category got deleted.
- *
- * @param $content = what we are deleting (a forum or a forum category)
- * @param $id The id of the forum category that has to be deleted.
- * @return void
- * @todo write the code for the cascading deletion of the forums inside a forum category and also the threads and replies inside these forums
- * @todo config setting for recovery or not (see also the documents tool: real delete or not).
- */
- public function testdeleteForumCategoryThread() {
- $content= 'testcontent';
- $id = 1;
- $res = deleteForumCategoryThread($content, $id);
- $this->assertTrue(is_null($res));
- //var_dump($res);
- }
- /**
- * This public function deletes the forum image if exists
- * @param int forum id
- * @return boolean true if success
- */
- public function testdelete_forum_image() {
- $forum_id = 1;
- $res = delete_forum_image($forum_id);
- $this->assertTrue(is_bool($res));
- //var_dump($res);
- }
- /**
- * 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)
- * and because deleting a post also has consequence on the posts that have this post as parent_id (they are also deleted).
- * an alternative would be to store the posts also in item_property and mark this post as deleted (visibility = 2).
- * We also have to decrease the number of replies in the thread table
- * @return string language variable
- * @param $post_id the id of the post that will be deleted
- * @todo write recursive public function that deletes all the posts that have this message as parent
- */
- public function testdelete_post() {
- $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
- $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
- $post_id = 1;
- $res = delete_post($post_id);
- $this->assertTrue(is_string($res));
- //var_dump($res);
- }
- public function __destruct() {
- // The destructor acts like a global tearDown for the class
- require_once api_get_path(SYS_TEST_PATH).'teardown.inc.php';
- }
- }
- ?>
|