123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368 |
- <?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() {
-
- require_once api_get_path(SYS_TEST_PATH).'setup.inc.php';
- }
-
- 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));
-
- }
-
- public function testapprove_post() {
- $action= 'invisible';
- $post_id = 1;
- $res = approve_post($post_id, $action);
- $this->assertTrue(is_string($res));
-
- }
-
- public function testchange_lock_status() {
- $content = 'testcontent';
- $action= 'invisible';
- $id = 1;
- $res = change_lock_status($content, $id, $action);
- $this->assertTrue(is_string($res));
-
- }
-
- public function testchange_visibility() {
- $content= 'testcontent';
- $target_visibility = 1;
- $id = 1;
- $res = change_visibility($content, $id, $target_visibility);
- $this->assertTrue(is_string($res));
-
- }
-
- 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));
- }
-
- }
-
- public function testclass_visible_invisible() {
- $current_visibility_status = 0;
- $res = class_visible_invisible($current_visibility_status);
- $this->assertTrue(is_string($res));
-
- }
-
- 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));
-
- }
-
- 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));
-
- }
-
- 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));
-
- }
-
- 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));
-
- }
-
- 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));
-
- }
-
- 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));
-
- }
-
- function testdisplay_lock_unlock_icon() {
- $content = 'testterm';
- $id = 1;
- $current_lock_status = 0;
- ob_start();
- $res = display_lock_unlock_icon($content, $id, $current_lock_status, $additional_url_parameters='');
- ob_end_clean();
- $this->assertTrue(is_null($res));
-
- }
-
- public function testdisplay_up_down_icon() {
- $content = 'testcontent';
- $id = 1;
- $list = array('test');
- ob_start();
- $res = display_up_down_icon($content, $id, $list);
- ob_end_clean();
- $this->assertTrue(is_null($res));
-
- }
-
- public function testdisplay_user_image() {
- $name = 'testcontent';
- $user_id = 1;
- $res = display_user_image($user_id,$name, $origin='');
- $this->assertTrue(is_string($res));
-
- }
-
- public function testdisplay_user_link() {
- $name = 'testcontent';
- $user_id = 1;
- $res = display_user_link($user_id, $name, $origin='');
- $this->assertTrue(is_string($res));
-
- }
-
- public function testdisplay_visible_invisible_icon() {
- $content = 'testcontent';
- $current_visibility_status = 0;
- $id = 1;
- ob_start();
- $res = display_visible_invisible_icon($content, $id, $current_visibility_status, $additional_url_parameters='');
- ob_end_clean();
- $this->assertTrue(is_null($res));
-
- }
-
- 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));
-
- }
-
- public function testforum_search() {
- ob_start();
- $res = forum_search();
- ob_end_clean();
- $this->assertTrue(is_null($res));
-
- }
-
- 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));
-
- }
-
- public function testget_attachment() {
- $post_id = 1;
- $res = get_attachment($post_id);
- $this->assertTrue(is_array($res));
-
- }
-
- public function testget_forum_categories() {
- $res = get_forum_categories($id='');
- $this->assertTrue(is_array($res));
-
- }
-
-
-
- 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));
- }
-
- }
-
- public function testget_forums() {
- $res = get_forums($id='');
- if(!is_bool($res)){
- $this->assertTrue(is_array($res));
- } else {
- $this->assertTrue(is_bool($res));
- }
-
- }
-
- 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));
- }
-
- }
-
- 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));
- }
-
- }
-
- 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));
- }
-
- }
-
- 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));
- }
-
- }
-
- 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));
- }
-
- }
-
- 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));
- }
-
- }
-
- 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));
- }
-
- }
-
- 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));
- }
-
- }
-
- 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));
- }
-
- }
-
-
-
- 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));
- }
-
- }
-
- 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));
- }
-
- }
-
- 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));
- }
-
- }
-
- 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));
- }
-
- }
-
- 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));
- }
-
- }
-
- 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));
- }
-
- }
-
- 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));
- }
-
- }
-
- 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));
- }
-
- }
-
- 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));
- }
-
- }
-
- 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));
- }
-
- }
-
- public function testget_whats_new() {
- $res = get_whats_new();
- $this->assertTrue(is_null($res));
-
- }
-
- public function testhandle_forum_and_forumcategories() {
- $res = handle_forum_and_forumcategories();
- $this->assertTrue(is_null($res));
-
- }
-
- public function testhandle_mail_cue() {
- $content = 'test content';
- $id = 1;
- $res = handle_mail_cue($content, $id);
- $this->assertTrue(is_string($res));
-
- }
-
- public function testicon() {
- $image_url = api_get_path(WEB_IMG_PATH).'test.png';
- $res = icon($image_url,$alt='',$title='');
- $this->assertTrue(is_string($res));
-
- }
-
- public function testincrease_thread_view() {
- $thread_id = 1;
- $res = increase_thread_view($thread_id);
- $this->assertTrue(is_null($res));
-
- }
-
- public function testmove_post_form() {
- ob_start();
- $res = move_post_form();
- ob_end_clean();
- $this->assertTrue(is_null($res));
-
- }
-
- public function testmove_thread_form() {
- ob_start();
- $res = move_thread_form();
- ob_end_clean();
- $this->assertTrue(is_null($res));
-
- }
-
- 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));
-
- }
-
- public function testprepare4display() {
- $res = prepare4display($input='');
- $this->assertTrue(is_string($res));
-
- }
-
- public function testsearch_link() {
- $res = search_link();
- $this->assertTrue(is_string($res));
-
- }
-
- public function testsend_mail() {
- $res = send_mail($user_info=array(), $thread_information=array());
- $this->assertTrue(is_null($res));
-
- }
-
- 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));
-
- }
-
- public function testsend_notifications() {
- $res = send_notifications($forum_id=0, $thread_id=0, $post_id=0);
- $this->assertTrue(is_bool($res));
-
- }
-
- public function testset_notification() {
- $content = 'test content';
- $id = 1;
- $res = set_notification($content,$id, $add_only = false);
- $this->assertTrue(is_string($res));
-
- }
-
- public function testshow_add_forum_form() {
- ob_start();
- $res = show_add_forum_form($inputvalues=array());
- ob_end_clean();
- $this->assertTrue(is_null($res));
-
- }
-
- public function testshow_add_forumcategory_form() {
- ob_start();
- $res = show_add_forumcategory_form($inputvalues=array());
- ob_end_clean();
- $this->assertTrue(is_null($res));
-
- }
-
- 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));
-
- }
-
- public function testshow_edit_forumcategory_form() {
- ob_start();
- $res = show_edit_forumcategory_form($inputvalues=array());
- ob_end_clean();
- $this->assertTrue(is_null($res));
-
- }
-
- 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));
-
- }
-
- 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));
- }
-
- }
-
- public function testcalculate_children() {
- $rows = array();
- $res = calculate_children($rows);
- $this->assertTrue(is_array($res));
-
- }
- public function test_forum_recursive_sort() {
- $rows = array();
- $res = forumRecursiveSort($rows, &$threads, $seed=0, $indent=0);
- $this->assertTrue(is_null($res));
-
- }
-
- public function teststore_edit_post() {
- $values = array('test');
- ob_start();
- $res = store_edit_post($values);
- ob_end_clean();
- $this->assertTrue(is_null($res));
-
- }
-
- public function teststore_forum() {
- $values = array('test');
- ob_start();
- $res = store_forum($values);
- ob_end_clean();
- $this->assertTrue(is_string($res));
-
- }
-
- public function teststore_forumcategory() {
- $values = array('test');
- ob_start();
- $res = store_forumcategory($values);
- ob_end_clean();
- $this->assertTrue(is_null($res));
-
- }
-
- public function teststore_move_post() {
- $values = array('test');
- ob_start();
- $res = store_move_post($values);
- ob_end_clean();
- $this->assertTrue(is_string($res));
-
- }
-
- public function teststore_move_thread() {
- $values = array('test');
- ob_start();
- $res = store_move_thread($values);
- ob_end_clean();
- $this->assertTrue(is_string($res));
-
- }
-
- 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));
-
- }
-
- public function teststore_reply() {
- $values = array('test');
- ob_start();
- $res = store_reply($values);
- ob_end_clean();
- $this->assertTrue(is_null($res));
-
- }
-
- 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));
- }
- }
-
- public function teststore_thread() {
- $values = array();
- ob_start();
- $res = store_thread($values);
- ob_end_clean();
- $this->assertTrue(is_null($res));
-
- }
-
- 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));
-
- }
-
- public function testforum_not_allowed_here() {
- ob_start();
- $res = forum_not_allowed_here();
- ob_end_clean();
- $this->assertTrue(is_bool($res));
-
- }
-
- public function testdelete_attachment() {
- global $_course;
- $post_id = 1;
- $res = delete_attachment($post_id,$id_attach=0);
- $this->assertTrue(is_null($res));
-
- }
-
- public function testdeleteForumCategoryThread() {
- $content= 'testcontent';
- $id = 1;
- $res = deleteForumCategoryThread($content, $id);
- $this->assertTrue(is_null($res));
-
- }
-
- public function testdelete_forum_image() {
- $forum_id = 1;
- $res = delete_forum_image($forum_id);
- $this->assertTrue(is_bool($res));
-
- }
-
- 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));
-
- }
- public function __destruct() {
-
- require_once api_get_path(SYS_TEST_PATH).'teardown.inc.php';
- }
- }
- ?>
|