skala
aportugal 15 years ago
commit ac54358e8f
  1. 4
      main/dropbox/dropbox_functions.inc.php
  2. 2
      main/dropbox/index.php
  3. 20
      main/forum/editpost.php
  4. 83
      main/forum/forumfunction.inc.php
  5. 5
      main/forum/forumqualify.php
  6. 5
      main/forum/iframe_thread.php
  7. 20
      main/forum/newthread.php
  8. 15
      main/forum/reply.php
  9. 5
      main/forum/viewforum.php
  10. 5
      main/forum/viewforumcategory.php
  11. 5
      main/forum/viewpost.php
  12. 5
      main/forum/viewthread.php
  13. 434
      tests/main/forum/forumfunction.inc.test.php
  14. 91
      tests/test_suite.php

@ -1073,7 +1073,7 @@ function store_add_dropbox()
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version march 2006
*/
function display_user_link($user_id, $name='')
function display_user_link_work($user_id, $name='')
{
global $_otherusers;
@ -1129,7 +1129,7 @@ function feedback($array)
*/
function format_feedback($feedback)
{
$output.=display_user_link($feedback['author_user_id']);
$output.=display_user_link_work($feedback['author_user_id']);
$output.='&nbsp;&nbsp;['.$feedback['feedback_date'].']<br />';
$output.='<div style="padding-top:6px">'.nl2br($feedback['feedback']).'</div><hr size="1" noshade/><br />';
return $output;

@ -613,7 +613,7 @@ if (!$_GET['view'] OR $_GET['view']=='sent' OR $dropbox_cnf['sent_received_tabs'
$dropbox_file_data[]='<a href="dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'&amp;action=download">'.Display::return_icon('filesave.gif',get_lang('Save'), array('style'=>'float:right;')).'</a><a href="dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'">'.$dropbox_file->title.'</a><br>'.$dropbox_file->description;
$dropbox_file_data[]=ceil(($dropbox_file->filesize)/1024).' '.get_lang('kB');
foreach ($dropbox_file->recipients as $recipient) {
$receivers_celldata=display_user_link($recipient['user_id'], $recipient['name']).', '.$receivers_celldata;
$receivers_celldata=display_user_link_work($recipient['user_id'], $recipient['name']).', '.$receivers_celldata;
}
$receivers_celldata = trim(trim($receivers_celldata), ','); // Removing the trailing comma.
$dropbox_file_data[]=$receivers_celldata;

@ -179,16 +179,28 @@ if ($origin=='learnpath') {
// I have split this is several pieces for clarity.
//if (!api_is_allowed_to_edit() AND (($current_forum_category['visibility']==0 OR $current_forum['visibility']==0) OR ($current_forum_category['locked']<>0 OR $current_forum['locked']<>0 OR $current_thread['locked']<>0)))
if (!api_is_allowed_to_edit(null,true) AND (($current_forum_category['visibility']==0 OR $current_forum['visibility']==0))) {
forum_not_allowed_here();
$forum_allow = forum_not_allowed_here();
if ($forum_allow === false) {
exit;
}
}
if (!api_is_allowed_to_edit(null,true) AND ($current_forum_category['locked']<>0 OR $current_forum['locked']<>0 OR $current_thread['locked']<>0)) {
forum_not_allowed_here();
$forum_allow = forum_not_allowed_here();
if ($forum_allow === false) {
exit;
}
}
if (!$_user['user_id'] AND $current_forum['allow_anonymous']==0) {
forum_not_allowed_here();
$forum_allow = forum_not_allowed_here();
if ($forum_allow === false) {
exit;
}
}
if (!api_is_allowed_to_edit(null,true) AND $current_forum['allow_edit']==0) {
forum_not_allowed_here();
$forum_allow = forum_not_allowed_here();
if ($forum_allow === false) {
exit;
}
}

@ -639,7 +639,7 @@ function store_forum($values) {
*
* @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).
*
* @return void
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version february 2006, dokeos 1.8
*/
@ -706,8 +706,8 @@ function delete_forum_forumcategory_thread($content, $id) {
* @version february 2006
*/
function delete_post($post_id) {
global $table_posts;
global $table_threads;
$table_posts = Database :: get_course_table(TABLE_FORUM_POST);
$table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
$post_id = intval($post_id);
// get parent_post_id of deleted post
@ -755,8 +755,7 @@ function delete_post($post_id) {
* @version february 2006, dokeos 1.8
*/
function check_if_last_post_of_thread($thread_id) {
global $table_posts;
$table_posts = Database :: get_course_table(TABLE_FORUM_POST);
$sql="SELECT * FROM $table_posts WHERE thread_id='".Database::escape_string($thread_id)."' ORDER BY post_date DESC";
$result=Database::query($sql);
if ( Database::num_rows($result)>0 ) {
@ -899,7 +898,7 @@ function display_up_down_icon($content, $id, $list) {
* @todo check if api_item_property_update returns true or false => returnmessage depends on it.
* @todo move to itemmanager
*
* @return
* @return string language variable
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version february 2006, dokeos 1.8
@ -929,10 +928,10 @@ function change_visibility($content, $id, $target_visibility) {
* @version february 2006, dokeos 1.8
*/
function change_lock_status($content, $id, $action) {
global $table_categories;
global $table_forums;
global $table_threads;
global $table_posts;
$table_categories = Database :: get_course_table(TABLE_FORUM_CATEGORY);
$table_forums = Database :: get_course_table(TABLE_FORUM);
$table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
$table_posts = Database :: get_course_table(TABLE_FORUM_POST);
// Determine the relevant table
if ($content=='forumcategory') {
@ -1062,7 +1061,7 @@ function move_up_down($content, $direction, $id) {
* 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
* @return string language variable
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version february 2006, dokeos 1.8
@ -1168,11 +1167,11 @@ function get_forums_in_category($cat_id)
* @version february 2006, dokeos 1.8
*/
function get_forums($id='') {
global $table_forums;
global $table_threads;
global $table_posts;
global $table_item_property;
global $table_users;
$table_forums = Database :: get_course_table(TABLE_FORUM);
$table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
$table_posts = Database :: get_course_table(TABLE_FORUM_POST);
$table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
$table_users = Database :: get_main_table(TABLE_MAIN_USER);
// **************** GETTING ALL THE FORUMS ************************* //
@ -1328,11 +1327,11 @@ function get_forums($id='') {
* @version february 2006, dokeos 1.8
*/
function get_last_post_information($forum_id, $show_invisibles=false) {
global $table_forums;
global $table_threads;
global $table_posts;
global $table_item_property;
global $table_users;
$table_forums = Database :: get_course_table(TABLE_FORUM);
$table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
$table_posts = Database :: get_course_table(TABLE_FORUM_POST);
$table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
$table_users = Database :: get_main_table(TABLE_MAIN_USER);
$sql="SELECT post.post_id, post.forum_id, post.poster_id, post.poster_name, post.post_date, users.lastname, users.firstname, post.visible, thread_properties.visibility AS thread_visibility, forum_properties.visibility AS forum_visibility
FROM $table_posts post, $table_users users, $table_item_property thread_properties, $table_item_property forum_properties
@ -1506,9 +1505,8 @@ function icon($image_url,$alt='',$title='') {
* @version february 2006, dokeos 1.8
*/
function get_post_information($post_id) {
global $table_posts;
global $table_users;
$table_posts = Database :: get_course_table(TABLE_FORUM_POST);
$table_users = Database :: get_main_table(TABLE_MAIN_USER);
$sql="SELECT * FROM ".$table_posts."posts, ".$table_users." users WHERE posts.poster_id=users.user_id AND posts.post_id='".Database::escape_string($post_id)."'";
$result=Database::query($sql);
$row=Database::fetch_array($result);
@ -1697,8 +1695,7 @@ function get_forumcategory_information($cat_id) {
* @version february 2006, dokeos 1.8
*/
function count_number_of_forums_in_category($cat_id) {
global $table_forums;
$table_forums = Database :: get_course_table(TABLE_FORUM);
$sql="SELECT count(*) AS number_of_forums FROM ".$table_forums." WHERE forum_category='".Database::escape_string($cat_id)."'";
$result=Database::query($sql);
$row=Database::fetch_array($result);
@ -2522,8 +2519,8 @@ function store_edit_post($values) {
/**
* This function displays the firstname and lastname of the user as a link to the user tool.
*
* @param
* @return
* @param string names
* @return string HTML
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version february 2006, dokeos 1.8
@ -2608,7 +2605,7 @@ function update_thread($thread_id, $last_post_id,$post_date) {
function forum_not_allowed_here() {
Display :: display_error_message(get_lang('NotAllowedHere'));
Display :: display_footer();
exit;
return false;
}
/**
@ -2731,14 +2728,13 @@ function get_post_topics_of_forum($forum_id) {
*
* @param $post_id the id of the post that will be deleted
* @param $action make the post visible or invisible
* @return
* @return string language variable
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version february 2006, dokeos 1.8
*/
function approve_post($post_id, $action) {
global $table_posts;
$table_posts = Database :: get_course_table(TABLE_FORUM_POST);
if ($action=='invisible') {
$visibility_value=0;
}
@ -3172,7 +3168,7 @@ function prepare4display($input='') {
/**
* Display the search form for the forum and display the search results
*
* @return void display an HTML search results
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
* @version march 2008, dokeos 1.8.5
*/
@ -3205,12 +3201,17 @@ function forum_search() {
}
/**
* Display the search results
*
* @param string
* @return void display the results
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
* @version march 2008, dokeos 1.8.5
*/
function display_forum_search_results($search_term) {
global $table_categories, $table_forums, $table_threads, $table_posts;
$table_categories = Database :: get_course_table(TABLE_FORUM_CATEGORY);
$table_forums = Database :: get_course_table(TABLE_FORUM);
$table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
$table_posts = Database :: get_course_table(TABLE_FORUM_POST);
global $origin;
$gradebook=Security::remove_XSS($_GET['gradebook']);
// defining the search strings as an array
@ -3228,12 +3229,11 @@ function display_forum_search_results($search_term) {
$sql = "SELECT * FROM $table_posts posts
WHERE ".implode(' AND ',$search_restriction)."
/*AND posts.thread_id = threads.thread_id*/
GROUP BY posts.post_id";
// getting all the information of the forum categories
$forum_categories_list=get_forum_categories();
// getting all the information of the forums
$forum_list=get_forums();
@ -3359,7 +3359,8 @@ function add_forum_attachment_file($file_comment,$last_id) {
* This function edit a attachment file into forum
* @param string a comment about file
* @param int Post Id
* @param int attachment file Id
* @param int attachment file Id
* @return void
*/
function edit_forum_attachment_file($file_comment,$post_id,$id_attach) {
@ -3661,7 +3662,7 @@ function get_notifications($content,$id) {
* @since May 2008, dokeos 1.8.5
*/
function send_notifications($forum_id=0, $thread_id=0, $post_id=0) {
global $_course;
global $_course,$_user;
// the content of the mail
$email_subject = get_lang('NewForumPost')." - ".$_course['official_code'];
@ -3750,7 +3751,7 @@ function get_notifications_of_user($user_id = 0, $force = false) {
* @version octubre 2008, dokeos 1.8
*/
function count_number_of_post_in_thread($thread_id) {
global $table_posts;
$table_posts = Database :: get_course_table(TABLE_FORUM_POST);
$sql = "SELECT * FROM $table_posts WHERE thread_id='".Database::escape_string($thread_id)."' ";
$result = Database::query($sql);
return count(Database::store_result($result));
@ -3765,7 +3766,7 @@ function count_number_of_post_in_thread($thread_id) {
* @version octubre 2008, dokeos 1.8
*/
function count_number_of_post_for_user_thread($thread_id, $user_id) {
global $table_posts;
$table_posts = Database :: get_course_table(TABLE_FORUM_POST);
$sql = "SELECT * FROM $table_posts WHERE thread_id='".Database::escape_string($thread_id)."'
AND poster_id = '".Database::escape_string($user_id)."' ";
$result = Database::query($sql);

@ -145,7 +145,10 @@ if ($origin=='learnpath') {
// if the user is not a course administrator and the forum is hidden
// then the user is not allowed here.
if (!api_is_allowed_to_edit(false,true) AND ($current_forum['visibility']==0 OR $current_thread['visibility']==0)) {
forum_not_allowed_here();
$forum_allow = forum_not_allowed_here();
if ($forum_allow === false) {
exit;
}
}

@ -125,7 +125,10 @@ $current_forum_category=get_forumcategory_information($current_forum['forum_cate
// if the user is not a course administrator and the forum is hidden
// then the user is not allowed here.
if (!api_is_allowed_to_edit(false,true) AND ($current_forum['visibility']==0 OR $current_thread['visibility']==0)) {
forum_not_allowed_here();
$forum_allow = forum_not_allowed_here();
if ($forum_allow === false) {
exit;
}
}
/*

@ -154,19 +154,31 @@ if($origin=='learnpath') {
// I have split this is several pieces for clarity.
if (!api_is_allowed_to_edit(false,true) && (($current_forum_category['visibility']==0 || $current_forum['visibility']==0))) {
forum_not_allowed_here();
$forum_allow = forum_not_allowed_here();
if ($forum_allow === false) {
exit;
}
}
// 2. the forumcategory or forum is locked (locked <>0) and the user is not a course manager
if (!api_is_allowed_to_edit(false,true) AND ($current_forum_category['locked']<>0 OR $current_forum['locked']<>0)) {
forum_not_allowed_here();
$forum_allow = forum_not_allowed_here();
if ($forum_allow === false) {
exit;
}
}
// 3. new threads are not allowed and the user is not a course manager
if (!api_is_allowed_to_edit(false,true) AND $current_forum['allow_new_threads']<>1) {
forum_not_allowed_here();
$forum_allow = forum_not_allowed_here();
if ($forum_allow === false) {
exit;
}
}
// 4. anonymous posts are not allowed and the user is not logged in
if (!$_user['user_id'] AND $current_forum['allow_anonymous']<>1) {
forum_not_allowed_here();
$forum_allow = forum_not_allowed_here();
if ($forum_allow === false) {
exit;
}
}
/*

@ -174,13 +174,22 @@ if($origin=='learnpath') {
// I have split this is several pieces for clarity.
//if (!api_is_allowed_to_edit() AND (($current_forum_category['visibility']==0 OR $current_forum['visibility']==0) OR ($current_forum_category['locked']<>0 OR $current_forum['locked']<>0 OR $current_thread['locked']<>0)))
if (!api_is_allowed_to_edit(false,true) AND (($current_forum_category['visibility']==0 OR $current_forum['visibility']==0))) {
forum_not_allowed_here();
$forum_allow = forum_not_allowed_here();
if ($forum_allow === false) {
exit;
}
}
if (!api_is_allowed_to_edit(false,true) AND ($current_forum_category['locked']<>0 OR $current_forum['locked']<>0 OR $current_thread['locked']<>0)) {
forum_not_allowed_here();
$forum_allow = forum_not_allowed_here();
if ($forum_allow === false) {
exit;
}
}
if (!$_user['user_id'] AND $current_forum['allow_anonymous']==0) {
forum_not_allowed_here();
$forum_allow = forum_not_allowed_here();
if ($forum_allow === false) {
exit;
}
}
/*
-----------------------------------------------------------

@ -289,7 +289,10 @@ if ($my_action == 'liststd' AND isset($_GET['content']) AND isset($_GET['id']) A
// if the user is not a course administrator and the forum is hidden
// then the user is not allowed here.
if (!api_is_allowed_to_edit(false,true) AND ($current_forum_category['visibility']==0 OR $current_forum['visibility']==0)) {
forum_not_allowed_here();
$forum_allow = forum_not_allowed_here();
if ($forum_allow === false) {
exit;
}
}
if ($origin == 'learnpath') {

@ -153,7 +153,10 @@ $whatsnew_post_info=$_SESSION['whatsnew_post_info'];
// if the user is not a course administrator and the forum is hidden
// then the user is not allowed here.
if (!api_is_allowed_to_edit(false,true) AND $current_forum_category['visibility']==0) {
forum_not_allowed_here();
$forum_allow = forum_not_allowed_here();
if ($forum_allow === false) {
exit;
}
}
/*

@ -109,7 +109,10 @@ if ($origin=='learnpath') {
// if the user is not a course administrator and the forum is hidden
// then the user is not allowed here.
if (!api_is_allowed_to_edit(false,true) AND ($current_forum['visibility']==0 OR $current_thread['visibility']==0)) {
forum_not_allowed_here();
$forum_allow = forum_not_allowed_here();
if ($forum_allow === false) {
exit;
}
}
/*

@ -148,7 +148,10 @@ if (!empty($_SESSION['toolgroup'])) {
// if the user is not a course administrator and the forum is hidden
// then the user is not allowed here.
if (!api_is_allowed_to_edit(false,true) AND ($current_forum['visibility']==0 OR $current_thread['visibility']==0)) {
forum_not_allowed_here();
$forum_allow = forum_not_allowed_here();
if ($forum_allow === false) {
exit;
}
}
/*

@ -0,0 +1,434 @@
<?php
class TestForumFunction extends UnitTestCase {
/**
* This function add a attachment file into forum
* @param string a comment about file
* @param int last id from forum_post table
* @return void
*/
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
*/
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
*/
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
*/
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 array if there is a last post found, false if there is no post entry linked to that thread => thread will be deleted
*/
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
*/
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
*/
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
*/
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
*/
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
*/
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 void
*/
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);
}
/**
* 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
*/
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 function deletes a forum or a forum category
* This 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).
*/
function testdelete_forum_forumcategory_thread() {
$content= 'testcontent';
$id = 1;
$res = delete_forum_forumcategory_thread($content, $id);
$this->assertTrue(is_null($res));
//var_dump($res);
}
/**
* This function deletes the forum image if exists
* @param int forum id
* @return boolean true if success
*/
function testdelete_forum_image() {
$forum_id = 1;
$res = delete_forum_image($forum_id);
$this->assertTrue(is_bool($res));
//var_dump($res);
}
/**
* This function deletes a forum post. This separate 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 function that deletes all the posts that have this message as parent
*/
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);
}
/**
* Display the search results
* @return void HTML
*/
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 takes care of the display of the lock icon
* @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 $current_visibility_status what is the current status of the visibility (0 = invisible, 1 = visible)
* @return void display the lock HTML.
*/
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));
//var_dump($res);
}
/**
* This function takes care of the display of the up and down icon
* @param $content what is it that we want to make (in)visible: forum category, forum, thread, post
* @param $id is the id of the item we want to display the icons for
* @param $list is an array of all the items. All items in this list should have an up and down icon except for the first (no up icon) and the last (no down icon)
* The key of this $list array is the id of the item.
* @return void HTML
*/
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));
//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
*/
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
*/
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 takes care of the display of the visibility icon
* @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 $current_visibility_status what is the current status of the visibility (0 = invisible, 1 = visible)
* @return void string HTML
*/
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));
//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
*/
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);
}
/**
* This function is called when the user is not allowed in this forum/thread/...
* @return bool display message of "not allowed"
*/
function testforum_not_allowed_here() {
ob_start();
$res = forum_not_allowed_here();
ob_end_clean();
$this->assertTrue(is_bool($res));
//var_dump($res);
}
/**
* Display the search form for the forum and display the search results
* @return void display an HTML search results
*/
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
*/
}
?>

@ -8,7 +8,7 @@ $maindir = dirname(__FILE__).'/../main/';
$incdir = dirname(__FILE__).'/../main/inc/';
$libdir = dirname(__FILE__).'/../main/inc/lib/';
//Need the ob start and clean else will show the objects
//Need the ob start and clean else will show the objects
require_once $incdir.'global.inc.php';
//List of files than need the tests
@ -28,7 +28,7 @@ require_once $libdir.'xmd.lib.php';
require_once $libdir.'formvalidator/FormValidator.class.php';
//Need the ob start and clean else will show the objects
//Need the ob start and clean else will show the objects
ob_start();
require_once $libdir.'main_api.lib.php';
require_once $libdir.'course_document.lib.php';
@ -53,22 +53,26 @@ require_once $maindir.'exercice/exercise_result.class.php';
require_once $libdir.'exercise_show_functions.lib.php';
require_once $maindir.'exercice/answer.class.php';
require_once $maindir.'exercice/exercise.class.php';
//require_once $maindir.'exercice/exercise.lib.php';
require_once $maindir.'exercice/fill_blanks.class.php';
require_once $maindir.'exercice/freeanswer.class.php';
require_once $maindir.'forum/forumfunction.inc.php';
require_once $libdir.'fileManage.lib.php';
class TestsSuite extends TestSuite {
function setUp() {
global $_configuration, $_user, $_course, $cidReq;
$cidReq = 'COURSETEST';
// check if course exists
// check if course exists
$table_course = Database::get_main_table(TABLE_MAIN_COURSE);
$sql = "SELECT code FROM $table_course WHERE code = '$cidReq' ";
$rs = Database::query($sql);
$rs = Database::query($sql, __FILE__, __LINE__);
$row = Database::fetch_row($rs);
if (empty($row[0])) {
// create a course
$course_datos = array(
'wanted_code'=> $cidReq,
@ -85,7 +89,7 @@ class TestsSuite extends TestSuite {
$course_datos['course_language'],$course_datos['course_admin_id'],
$course_datos['db_prefix'], $course_datos['firstExpirationDelay']);
}
$course_table = Database::get_main_table(TABLE_MAIN_COURSE);
$course_cat_table = Database::get_main_table(TABLE_MAIN_CATEGORY);
$sql = "SELECT course.*, course_category.code faCode, course_category.name faName
@ -93,10 +97,10 @@ class TestsSuite extends TestSuite {
LEFT JOIN $course_cat_table
ON course.category_code = course_category.code
WHERE course.code = '$cidReq'";
$result = Database::query($sql);
$result = Database::query($sql,__FILE__,__LINE__);
//create the session
if (Database::num_rows($result)>0) {
$cData = Database::fetch_array($result);
$_cid = $cData['code' ];
@ -117,16 +121,16 @@ class TestsSuite extends TestSuite {
$_course['visibility' ] = $cData['visibility'];
$_course['subscribe_allowed'] = $cData['subscribe'];
$_course['unubscribe_allowed'] = $cData['unsubscribe'];
api_session_register('_cid');
api_session_register('_course');
}
$_SESSION['_user']['user_id'] = 1;
$_SESSION['_user']['user_id'] = 1;
$_user['user_id'] = $_SESSION['_user']['user_id'];
$_SESSION['is_courseAdmin'] = 1;
$_SESSION['show'] = showall;
}
function TestsSuite() {
$this->setUp();
@ -143,13 +147,13 @@ class TestsSuite extends TestSuite {
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/classmanager.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/export.lib.inc.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/legal.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/mail.lib.inc.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/mail.lib.inc.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/message.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/online.inc.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/online.inc.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/security.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/specific_fields_manager.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/specific_fields_manager.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/social.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/sortabletable.class.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/sortabletable.class.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/statsUtils.lib.inc.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/tablesort.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/text.lib.test.php');
@ -178,15 +182,15 @@ class TestsSuite extends TestSuite {
$this->addTestFile(dirname(__FILE__).'/main/auth/openid/xrds.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/chat/chat_functions.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/conference/get_translation.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/exercice/hotpotatoes.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/exercice/hotpotatoes.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/newscorm/scorm.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/survey/survey.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/user/userInfoLib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/webservices/user_import/import.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/user/userInfoLib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/webservices/user_import/import.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/work/work.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/glossary.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/notebook.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/permissions/permissions_functions.inc.test.php');
$this->addTestFile(dirname(__FILE__).'/main/permissions/permissions_functions.inc.test.php');
$this->addTestFile(dirname(__FILE__).'/main/resourcelinker/resourcelinker.inc.test.php');
$this->addTestFile(dirname(__FILE__).'/main/survey/survey.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/dropbox/dropbox_class.inc.test.php');
@ -194,17 +198,17 @@ class TestsSuite extends TestSuite {
$this->addTestFile(dirname(__FILE__).'/main/search/search_suggestions.test.php');
$this->addTestFile(dirname(__FILE__).'/main/exercice/export/qti2/qti2_classes.test.php');
$this->addTestFile(dirname(__FILE__).'/main/exercice/export/scorm/scorm_classes.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/usermanager.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/groupmanager.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/image.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/usermanager.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/groupmanager.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/image.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/import.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/internationalization.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/internationalization.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/system_announcements.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/fileUpload.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/main_api.lib.test.php');//this file delete the course
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/main_api.lib.test.php');//this file delete the course
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/debug.lib.inc.test.php');//this file need be to the finish of the tests
*/
*/
//This files has metadata, are deprecated, are not implemented and is not available for the test.
//$this->addTestFile(dirname(__FILE__).'/main/inc/lib/xht.lib.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/inc/lib/xmd.lib.test.php');
@ -212,18 +216,25 @@ class TestsSuite extends TestSuite {
//$this->addTestFile(dirname(__FILE__).'/main/exercice/export/qti2/qti2_export.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/exercice/export/exercise_import.inc.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/exercice/export/scorm/scorm_export.test.php');
/**EJERCICIOS**/
$this->addTestFile(dirname(__FILE__).'/main/exercice/answer.class.test.php');
$this->addTestFile(dirname(__FILE__).'/main/exercice/exercise_result.class.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/exercise_show_functions.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/exercice/exercise.class.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/main_api.lib.test.php');//this file delete the course
//$this->addTestFile(dirname(__FILE__).'/main/exercice/answer.class.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/exercice/exercise_result.class.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/inc/lib/exercise_show_functions.lib.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/exercice/exercise.class.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/exercice/exercise.lib.test.php');falta
//$this->addTestFile(dirname(__FILE__).'/main/exercice/fill_blanks.class.test.php');falta
//$this->addTestFile(dirname(__FILE__).'/main/exercice/freeanswer.class.test.php');falta
/**FORUM*/
$this->addTestFile(dirname(__FILE__).'/main/forum/forumfunction.inc.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/main_api.lib.test.php');//this file delete the course,session and the use of api_allow
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/debug.lib.inc.test.php');//this file need be to the finish of the tests
}
}
$test = &new TestsSuite();

Loading…
Cancel
Save