skala
Julio Montoya 16 years ago
commit 53cb3130df
  1. 37
      main/admin/user_list.php
  2. 19
      main/inc/lib/blog.lib.php
  3. 1
      main/inc/lib/fckeditor/editor/plugins/youtube/youtube.js
  4. 106
      main/newscorm/scorm_api.php
  5. 174
      main/survey/survey.lib.php
  6. 24
      main/user/userInfoLib.php
  7. 19
      tests/all.test2.php
  8. 67
      tests/load_global.php
  9. 360
      tests/main/inc/lib/blog.lib.test.php
  10. 598
      tests/main/survey/survey.lib.test.php
  11. 21
      tests/main/user/userInfoLib.test.php

@ -469,43 +469,6 @@ function get_user_data($from, $number_of_items, $column, $direction)
$res = Database::query($sql, __FILE__, __LINE__);
$users = array ();
$t = time();
while ($user = Database::fetch_row($res)) {
$image_path = UserManager::get_user_picture_path_by_id($user[0], 'web', false, true);
$user_profile = UserManager::get_picture_user($user[0], $image_path['file'], 22, USER_IMAGE_SIZE_SMALL, ' width="22" height="22" ');
if (!api_is_anonymous()) {
$photo = '<center><a href="'.api_get_path(WEB_PATH).'whoisonline.php?origin=user_list&id='.$user[0].'" title="'.get_lang('Info').'" ><img src="'.$user_profile['file'].'" '.$user_profile['style'].' alt="'.api_get_person_name($user[2],$user[3]).'" title="'.api_get_person_name($user[2], $user[3]).'" /></a></center>';
} else {
$photo = '<center><img src="'.$user_profile['file'].'" '.$user_profile['style'].' alt="'.api_get_person_name($user[2], $user[3]).'" title="'.api_get_person_name($user[2], $user[3]).'" /></center>';
}
if ($user[7] == 1 && $user[9] != '0000-00-00 00:00:00') {
// check expiration date
$expiration_time = convert_mysql_date($user[9]);
// if expiration date is passed, store a special value for active field
if ($expiration_time < $t) {
$user[7] = '-1';
}
}
// forget about the expiration date field
$users[] = array($user[0],$photo,$user[1],$user[2],$user[3],$user[4],$user[5],$user[6],$user[7],$user[8]);
}
return $users;
if (!in_array($direction, array('ASC','DESC'))) {
$direction = 'ASC';
}
$column = intval($column);
$from = intval($from);
$number_of_items = intval($number_of_items);
$sql .= " ORDER BY col$column $direction ";
$sql .= " LIMIT $from,$number_of_items";
echo $sql;
$res = Database::query($sql, __FILE__, __LINE__);
$users = array ();
$t = time();
while ($user = Database::fetch_row($res)) {

@ -224,8 +224,8 @@ class Blog {
public static function create_post ($title, $full_text, $file_comment, $blog_id) {
global $_user;
global $_course;
global $blog_table_attachment;
$blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
$upload_ok=true;
$has_attachment=false;
$current_date=date('Y-m-d H:i:s',time());
@ -2878,14 +2878,13 @@ class Blog {
*/
function get_blog_attachment($blog_id, $post_id=null,$comment_id=null)
{
global $blog_table_attachment;
$blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
$blog_id = Database::escape_string($blog_id);
$comment_id = Database::escape_string($comment_id);
$post_id = Database::escape_string($post_id);
$row=array();
$where='';
if (!empty ($post_id) && is_numeric($post_id))
{
$where.=' AND post_id ="'.$post_id.'" ';
@ -2899,9 +2898,9 @@ function get_blog_attachment($blog_id, $post_id=null,$comment_id=null)
}
$where.=' comment_id ="'.$comment_id.'" ';
}
$sql = 'SELECT path, filename, comment FROM '. $blog_table_attachment.' WHERE blog_id ="'.intval($blog_id).'" '.$where;
$result=Database::query($sql, __FILE__, __LINE__);
if (Database::num_rows($result)!=0)
{
@ -2921,9 +2920,9 @@ function get_blog_attachment($blog_id, $post_id=null,$comment_id=null)
function delete_all_blog_attachment($blog_id,$post_id=null,$comment_id=null)
{
global $blog_table_attachment;
global $_course;
global $_course;
$blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
$blog_id = Database::escape_string($blog_id);
$comment_id = Database::escape_string($comment_id);
$post_id = Database::escape_string($post_id);

@ -152,6 +152,7 @@ function UpdateEmbed( e )
SetAttribute( e, 'type', 'application/x-shockwave-flash' ) ;
SetAttribute( e, 'pluginspage', 'http://www.macromedia.com/go/getflashplayer' ) ;
SetAttribute( e, 'allowfullscreen', 'true' ) ;
SetAttribute( e, 'wmode', 'transparent' ) ;
if ( GetE( 'radioHigh' ).checked )
{
SetAttribute( e, 'src', YoutubeSite + YoutubeId + HighQualityString ) ;

@ -180,7 +180,7 @@ olms.lms_item_credit = '<?php echo $oItem->get_credit();?>';
olms.lms_item_lesson_mode = '<?php echo $oItem->get_lesson_mode();?>';
olms.lms_item_launch_data = '<?php echo $oItem->get_launch_data();?>';
olms.lms_item_core_exit = '<?php echo $oItem->get_core_exit();?>';
<?php echo $oLP->get_items_details_as_js('olms.lms_item_types')?>
<?php echo $oLP->get_items_details_as_js('olms.lms_item_types');?>
olms.asset_timer = 0;
@ -197,13 +197,13 @@ olms.execute_stats=false;
// Initialize stuff when the page is loaded
$(document).ready( function() {
$(document).ready( function() {
//
olms.info_lms_item[0]='<?php echo $oItem->get_id();?>';
olms.info_lms_item[1]='<?php echo $oItem->get_id();?>';
$("#content_id").load( function(){
olms.info_lms_item[0]=olms.info_lms_item[1];
$("#content_id").load( function(){
olms.info_lms_item[0]=olms.info_lms_item[1];
if (olms.lms_item_types['i'+olms.info_lms_item[1]] != 'sco') {
LMSInitialize();
}
@ -228,7 +228,7 @@ function LMSInitialize() { //this is the initialize function of all APIobjects
*/
olms.G_LastError = G_NoError ;
olms.G_LastErrorMessage = 'No error';
olms.lms_initialized=0;
@ -272,19 +272,19 @@ function LMSInitialize() { //this is the initialize function of all APIobjects
+ '<br />lms_user_id: '+olms.lms_user_id
+ '<br />lms_view_id: '+olms.lms_view_id
;
logit_scorm('LMSInitialize()'+log,0);
olms.lms_initialized=1;
<?php if (api_get_setting('show_glossary_in_documents') == 'ismanual') { ?>
if (olms.lms_item_type == 'sco') {
attach_glossary_into_scorm('automatic');
attach_glossary_into_scorm('automatic');
} else {
attach_glossary_into_scorm('manual');
}
attach_glossary_into_scorm('manual');
}
<?php } elseif (api_get_setting('show_glossary_in_documents') == 'isautomatic') { ?>
attach_glossary_into_scorm('automatic');
<? } ?>
attach_glossary_into_scorm('automatic');
<?php } ?>
return('true');
}
}
@ -820,10 +820,10 @@ function savedata(origin) {
olms.variable_to_send=new Array();
}
/**
* Send the Commit signal to the LMS (save the data for this element without
* Send the Commit signal to the LMS (save the data for this element without
* closing the current process)
* From SCORM 1.2 RTE: If the API Adapter is caching values received from the
* SCO via an LMSSetValue(), this call requires that any values not yet
* From SCORM 1.2 RTE: If the API Adapter is caching values received from the
* SCO via an LMSSetValue(), this call requires that any values not yet
* persisted by the LMS be persisted.
* @param string Must be empty string for conformance with SCORM 1.2
*/
@ -844,12 +844,12 @@ function Commit(val) {
}
/**
* Send the closure signal to the LMS. This saves the data and closes the current SCO.
* From SCORM 1.2 RTE: The SCO must call this when it has determined that it no
* longer needs to communicate with the LMS, if it successfully called
* From SCORM 1.2 RTE: The SCO must call this when it has determined that it no
* longer needs to communicate with the LMS, if it successfully called
* LMSInitialize at any previous point. This call signifies two things:
* 1.The SCO can be assured that any data set using LMSSetValue() calls has been persisted by the LMS.
* 2.The SCO has finished communicating with the LMS.
* @param string
* @param string
*/
function LMSFinish(val) {
olms.G_LastError = G_NoError ;
@ -925,7 +925,7 @@ function GetDiagnostic(errCode){
* Acts as a "commit"
* This function is not standard SCORM 1.2 and is probably deprecated in all
* meanings of the term.
* @return string 'true' or 'false', depening on whether the LMS has initialized the SCORM process or not
* @return string 'true' or 'false', depening on whether the LMS has initialized the SCORM process or not
*/
function Terminate()
{
@ -1277,7 +1277,7 @@ function switch_item(current_item, next_item){
var orig_lesson_status = olms.lesson_status;
var orig_item_type = olms.lms_item_types['i'+current_item];
var next_item_type = olms.lms_item_types['i'+next_item];
/*
There are four "cases" for switching items:
(1) asset switching to asset
@ -1286,34 +1286,34 @@ function switch_item(current_item, next_item){
We need to save, switching not necessary (LMSInitialize does the job)
(3) sco switching to asset
We need to switch the document in the content frame, but we cannot
switch the item details, otherwise the LMSFinish() call (that *must*
switch the item details, otherwise the LMSFinish() call (that *must*
be triggered by the SCO when it unloads) will use bad values. However,
we need to load the new asset's context once the SCO has unloaded
(4) sco switching to sco
We don't neet to switch nor commit, LMSFinish() on unload and
We don't neet to switch nor commit, LMSFinish() on unload and
LMSInitialize on load will do the job
In any case, we need to change the current document frame.
These cases, although clear here, are however very difficult to implement
*/
logit_lms('Called switch_item with params '+olms.lms_item_id+' and '+next_item+'',0);
if (orig_item_type != 'sco') {
if (next_item_type != 'sco' ) {
//case 1
xajax_save_item(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, olms.lms_item_id, olms.score, olms.max, olms.min, olms.lesson_status, olms.asset_timer, olms.suspend_data, olms.lesson_location,olms.interactions, olms.lms_item_core_exit);
xajax_switch_item_details(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,olms.lms_item_id,next_item);
xajax_switch_item_details(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,olms.lms_item_id,next_item);
} else {
//case 2
xajax_save_item(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, olms.lms_item_id, olms.score, olms.max, olms.min, olms.lesson_status, olms.asset_timer, olms.suspend_data, olms.lesson_location,olms.interactions, olms.lms_item_core_exit);
xajax_switch_item_details(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,olms.lms_item_id,next_item);
xajax_switch_item_details(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,olms.lms_item_id,next_item);
}
} else {
if (next_item_type != 'sco') {
//case 3
xajax_save_item_scorm(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, olms.lms_item_id);
reinit_updatable_vars_list();
xajax_switch_item_toc(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,olms.lms_item_id,next_item);
xajax_switch_item_toc(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,olms.lms_item_id,next_item);
} else {
//case 4
xajax_save_item_scorm(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, olms.lms_item_id);
@ -1324,8 +1324,8 @@ function switch_item(current_item, next_item){
xajax_save_objectives(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,olms.lms_item_id,olms.item_objectives);
}
}
/*
/*
//(1) save the current item
if (olms.lms_lp_type==1 || olms.lms_item_type=='asset' || olms.session_time == '0' || olms.session_time == '0:00:00') {
if (olms.lms_lp_type==1) {
@ -1337,7 +1337,7 @@ function switch_item(current_item, next_item){
xajax_save_objectives(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,olms.lms_item_id,olms.item_objectives);
}
}else{
*/
*/
/**
* Because of SCORM 1.2's special rule about unsent commits and the fact
* that a SCO should be SET TO 'completed' IF NO STATUS WAS SENT (and
@ -1372,7 +1372,7 @@ function switch_item(current_item, next_item){
*/
olms.execute_stats=false;
// Considering info_lms_item[0] is initially the oldest and info_lms_item[1]
// is the newest item, and considering we are done switching the items now,
// we need to update these markers so that the new item is loaded when
@ -1446,7 +1446,7 @@ function switch_item(current_item, next_item){
}
/**
* Save a specific item (with its interactions, if any) into the LMS through
* an AJAX call to lp_ajax_save_item.php.
* an AJAX call to lp_ajax_save_item.php.
* Because of the need to pass an array, we have to build the parameters
* manually into GET[].
* This function has a twin sister for SCO elements (xajax_save_item_scorm)
@ -1486,7 +1486,7 @@ function xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score
}
}
/**
* Save a SCORM item's variables, getting its SCORM values from
* Save a SCORM item's variables, getting its SCORM values from
* updatable_vars_list. Takes interactions into account and considers whether
* variables have been modified or not.
* @param int ID of the learning path
@ -1685,21 +1685,21 @@ if(olms.lms_lp_type==1 || olms.lms_item_type=='asset'){
* @param string automatic or manual values are allowed
*/
function attach_glossary_into_scorm(type) {
var f = $('#content_id')[0];
//logit_lms('attach_glossary_into_scorm', 0);
var doc = f.contentWindow ? f.contentWindow.document :
f.contentDocument ? f.contentDocument : f.document;
f.contentDocument ? f.contentDocument : f.document;
var $frame_content = $('body',doc);
var my_text=$frame_content.html();
my_protocol = location.protocol;
my_pathname=location.pathname;
work_path = my_pathname.substr(0,my_pathname.indexOf('/courses/'));
if (type == 'automatic') {
$.ajax({
contentType: "application/x-www-form-urlencoded",
beforeSend: function(object) {
@ -1711,20 +1711,20 @@ function attach_glossary_into_scorm(type) {
if (datas.length==0) {
return false;
}
// glossary terms
// glossary terms
data_terms=datas.split("[|.|_|.|-|.|]");
var complex_array = new Array();
var cp_complex_array = new Array();
for(i=0;i<data_terms.length;i++) {
specific_terms=data_terms[i].split("__|__|");
var real_term = specific_terms[1]; // glossary term
var real_term = specific_terms[1]; // glossary term
var real_code = specific_terms[0]; // glossary id
complex_array[real_code] = real_term;
cp_complex_array[real_code] = real_term;
}
complex_array.reverse();
for (var my_index in complex_array) {
n = complex_array[my_index];
if (n == null) {
@ -1742,12 +1742,12 @@ function attach_glossary_into_scorm(type) {
}
//alert(n + ' ' + my_index);
$("iframe").contents().find('body').removeHighlight().highlight(n,my_index)
//logit_lms(n+ ' - '+my_index, 0);
}
//logit_lms(n+ ' - '+my_index, 0);
}
}
var complex_array = new Array();
//mouse over event
$("iframe").contents().find("body .glossary-ajax").mouseover(function(){
random_id=Math.round(Math.random()*100);
@ -1758,7 +1758,7 @@ function attach_glossary_into_scorm(type) {
$("iframe").contents().find("div#"+div_content_id).attr("style","background-color:#F2F2F2;color:#0B3861;margin-left:8px;margin-right:8px;margin-top:5px;margin-bottom:5px;");
notebook_id=$(this).attr("name");
data_notebook=notebook_id.split("link");
my_glossary_id=data_notebook[1];
$.ajax({
contentType: "application/x-www-form-urlencoded",
@ -1772,7 +1772,7 @@ function attach_glossary_into_scorm(type) {
}
});
});
//mouse out event
$("iframe").contents().find("body .glossary-ajax").mouseout(function(){
var current_element,
@ -1780,12 +1780,12 @@ function attach_glossary_into_scorm(type) {
div_show_id=current_element.find("div").attr("id");
$("iframe").contents().find("div#"+div_show_id).remove();
});
}
});
} else {
if ('manual') {
$("iframe").contents().find("body .glossary").mouseover(function(){
is_glossary_name=$(this).html();
random_id=Math.round(Math.random()*100);
@ -1794,7 +1794,7 @@ function attach_glossary_into_scorm(type) {
$(this).append("<div id="+div_show_id+" ><div id="+div_content_id+">&nbsp;</div></div>");
$("iframe").contents().find("div#"+div_show_id).attr("style","display:inline;float:left;position:absolute;background-color:#F2F2F2;border-bottom: 1px solid #2E2E2E;border-right: 1px solid #2E2E2E;border-left: 1px solid #2E2E2E;border-top: 1px solid #2E2E2E;color:#305582;margin-left:5px;margin-right:5px;");
$("iframe").contents().find("div#"+div_content_id).attr("style","background-color:#F2F2F2;color:#0B3861;margin-left:8px;margin-right:8px;margin-top:5px;margin-bottom:5px;");
$.ajax({
contentType: "application/x-www-form-urlencoded",
beforeSend: function(objeto) {
@ -1811,7 +1811,7 @@ function attach_glossary_into_scorm(type) {
current_element=$(this);
div_show_id=current_element.find("div").attr("id");
$("iframe").contents().find("div#"+div_show_id).remove();
});
});
}
}
}

@ -1686,23 +1686,26 @@ class yesno extends question
*/
function render_question($form_content, $answers=array())
{
foreach ($form_content['options'] as $key=>$value)
{
$this->html .= '<label><input name="question'.$form_content['question_id'].'" type="radio" value="'.$key.'"';
if (is_array($answers))
if (is_array($form_content['options'])) { // check if data is correct
foreach ($form_content['options'] as $key=>$value)
{
if (in_array($key,$answers))
$this->html .= '<label><input name="question'.$form_content['question_id'].'" type="radio" value="'.$key.'"';
if (is_array($answers))
{
$this->html .= 'checked="checked"';
if (in_array($key,$answers))
{
$this->html .= 'checked="checked"';
}
}
}
if (substr_count($value,"<p>")==1) {
$this->html .= '/>'.substr($value,3,(strlen($value)-7)).'</label>';
if ($form_content['display'] == 'vertical') {
$this->html .= '<br />';
if (substr_count($value,"<p>")==1) {
$this->html .= '/>'.substr($value,3,(strlen($value)-7)).'</label>';
if ($form_content['display'] == 'vertical') {
$this->html .= '<br />';
}
} else {
$this->html .= '/>'.$value.'</label>';
}
} else {
$this->html .= '/>'.$value.'</label>';
}
}
echo '<div class="survey_question_wrapper">';
@ -1755,24 +1758,26 @@ class multiplechoice extends question
$this->html .= ' </div>';
$this->html .= ' <div class="formw">';
$total_number_of_answers = count($form_content['answers']);
$this->html .= ' <table>';
foreach ($form_content['answers'] as $key=>$value) {
$this->html .= ' <tr>';
$this->html .= ' <td align="right"><label for="answers['.$key.']">'.($key+1).'</label></td>';
//$this->html .= ' <td><input type="text" name="answers['.$key.']" id="answers['.$key.']" value="'.$form_content['answers'][$key].'" /></td>';
$this->html .= ' <td width="550">'.api_return_html_area('answers['.$key.']', api_html_entity_decode(stripslashes($form_content['answers'][$key]), ENT_QUOTES, $charset), '', '', null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120')).'</td>';
$this->html .= ' <td>';
if ($key<$total_number_of_answers-1) {
$this->html .= ' <input type="image" src="../img/down.gif" value="move_down['.$key.']" name="move_down['.$key.']"/>';
}
if ($key>0) {
$this->html .= ' <input type="image" src="../img/up.gif" value="move_up['.$key.']" name="move_up['.$key.']"/>';
}
if ($total_number_of_answers> 2) {
$this->html .= ' <input type="image" src="../img/delete.gif" value="delete_answer['.$key.']" name="delete_answer['.$key.']"/>';
$this->html .= ' <table>';
if (is_array($form_content['answers'])) { // check if data is correct
foreach ($form_content['answers'] as $key=>$value) {
$this->html .= ' <tr>';
$this->html .= ' <td align="right"><label for="answers['.$key.']">'.($key+1).'</label></td>';
//$this->html .= ' <td><input type="text" name="answers['.$key.']" id="answers['.$key.']" value="'.$form_content['answers'][$key].'" /></td>';
$this->html .= ' <td width="550">'.api_return_html_area('answers['.$key.']', api_html_entity_decode(stripslashes($form_content['answers'][$key]), ENT_QUOTES, $charset), '', '', null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120')).'</td>';
$this->html .= ' <td>';
if ($key<$total_number_of_answers-1) {
$this->html .= ' <input type="image" src="../img/down.gif" value="move_down['.$key.']" name="move_down['.$key.']"/>';
}
if ($key>0) {
$this->html .= ' <input type="image" src="../img/up.gif" value="move_up['.$key.']" name="move_up['.$key.']"/>';
}
if ($total_number_of_answers> 2) {
$this->html .= ' <input type="image" src="../img/delete.gif" value="delete_answer['.$key.']" name="delete_answer['.$key.']"/>';
}
$this->html .= ' </td>';
$this->html .= ' </tr>';
}
$this->html .= ' </td>';
$this->html .= ' </tr>';
}
// The buttons for adding or removing
$this->html .= ' </table>';
@ -1847,45 +1852,44 @@ class personality extends question
$question_values=array();
// values of question options
foreach ($form_content['values'] as $key=>$value)
{
$question_values [] = '<input size="3" type="text" id="values['.$key.']" name="values['.$key.']" value="'.$value.'" />';
}
$count=0;
foreach ($form_content['answers'] as $key=>$value)
{
$this->html .= ' <tr>';
$this->html .= ' <td align="right"><label for="answers['.$key.']">'.($key+1).'</label></td>';
//$this->html .= ' <td><input type="text" name="answers['.$key.']" id="answers['.$key.']" value="'.$form_content['answers'][$key].'" /></td>';
$this->html .= ' <td width="550">'.api_return_html_area('answers['.$key.']', api_html_entity_decode(stripslashes($form_content['answers'][$key])), '', '', null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120')).'</td>';
$this->html .= ' <td>';
if ($total_number_of_answers> 2)
{
$this->html .=$question_values[$count];
}
if ($key<$total_number_of_answers-1)
{
$this->html .= ' <input type="image" src="../img/down.gif" value="move_down['.$key.']" name="move_down['.$key.']"/>';
}
if ($key>0)
{
$this->html .= ' <input type="image" src="../img/up.gif" value="move_up['.$key.']" name="move_up['.$key.']"/>';
}
if ($total_number_of_answers> 2)
{
$this->html .= ' <input type="image" src="../img/delete.gif" value="delete_answer['.$key.']" name="delete_answer['.$key.']"/>';
if(is_array($form_content['values'])) { // check if data is correct
foreach ($form_content['values'] as $key=>$value) {
$question_values [] = '<input size="3" type="text" id="values['.$key.']" name="values['.$key.']" value="'.$value.'" />';
}
}
$count=0;
if(is_array($form_content['answers'])) {
foreach ($form_content['answers'] as $key=>$value) {
$this->html .= ' <tr>';
$this->html .= ' <td align="right"><label for="answers['.$key.']">'.($key+1).'</label></td>';
//$this->html .= ' <td><input type="text" name="answers['.$key.']" id="answers['.$key.']" value="'.$form_content['answers'][$key].'" /></td>';
$this->html .= ' <td width="550">'.api_return_html_area('answers['.$key.']', api_html_entity_decode(stripslashes($form_content['answers'][$key])), '', '', null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120')).'</td>';
$this->html .= ' <td>';
if ($total_number_of_answers> 2)
{
$this->html .=$question_values[$count];
}
if ($key<$total_number_of_answers-1)
{
$this->html .= ' <input type="image" src="../img/down.gif" value="move_down['.$key.']" name="move_down['.$key.']"/>';
}
if ($key>0)
{
$this->html .= ' <input type="image" src="../img/up.gif" value="move_up['.$key.']" name="move_up['.$key.']"/>';
}
if ($total_number_of_answers> 2)
{
$this->html .= ' <input type="image" src="../img/delete.gif" value="delete_answer['.$key.']" name="delete_answer['.$key.']"/>';
}
$this->html .= ' </td>';
$this->html .= ' </tr>';
$count++;
}
$this->html .= ' </td>';
$this->html .= ' </tr>';
$count++;
}
// The buttons for adding or removing
//$this->html .= parent :: add_remove_buttons($form_content);
}
@ -1949,25 +1953,27 @@ class multipleresponse extends question
$this->html .= ' <div class="formw">';
$total_number_of_answers = count($form_content['answers']);
$this->html .= ' <table>';
foreach ($form_content['answers'] as $key=>$value) {
$this->html .= ' <tr>';
$this->html .= ' <td align="right"><label for="answers['.$key.']">'.($key+1).'</label></td>';
//$this->html .= ' <td><input type="text" name="answers['.$key.']" id="answers['.$key.']" value="'.$form_content['answers'][$key].'" /></td>';
$this->html .= ' <td width="550">'.api_return_html_area('answers['.$key.']', api_html_entity_decode(stripslashes($form_content['answers'][$key]), ENT_QUOTES, $charset), '', '', null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120')).'</td>';
$this->html .= ' <td>';
if ($key<$total_number_of_answers-1) {
$this->html .= ' <input type="image" src="../img/down.gif" value="move_down['.$key.']" name="move_down['.$key.']"/>';
}
if ($key>0) {
$this->html .= ' <input type="image" src="../img/up.gif" value="move_up['.$key.']" name="move_up['.$key.']"/>';
}
if ($total_number_of_answers> 2) {
$this->html .= ' <input type="image" src="../img/delete.gif" value="delete_answer['.$key.']" name="delete_answer['.$key.']"/>';
if(is_array($form_content['answers'])) { // values of question options
foreach ($form_content['answers'] as $key=>$value) {
$this->html .= ' <tr>';
$this->html .= ' <td align="right"><label for="answers['.$key.']">'.($key+1).'</label></td>';
//$this->html .= ' <td><input type="text" name="answers['.$key.']" id="answers['.$key.']" value="'.$form_content['answers'][$key].'" /></td>';
$this->html .= ' <td width="550">'.api_return_html_area('answers['.$key.']', api_html_entity_decode(stripslashes($form_content['answers'][$key]), ENT_QUOTES, $charset), '', '', null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120')).'</td>';
$this->html .= ' <td>';
if ($key<$total_number_of_answers-1) {
$this->html .= ' <input type="image" src="../img/down.gif" value="move_down['.$key.']" name="move_down['.$key.']"/>';
}
if ($key>0) {
$this->html .= ' <input type="image" src="../img/up.gif" value="move_up['.$key.']" name="move_up['.$key.']"/>';
}
if ($total_number_of_answers> 2) {
$this->html .= ' <input type="image" src="../img/delete.gif" value="delete_answer['.$key.']" name="delete_answer['.$key.']"/>';
}
$this->html .= ' </td>';
$this->html .= ' </tr>';
}
$this->html .= ' </td>';
$this->html .= ' </tr>';
}
// The buttons for adding or removing
$this->html .= ' </table>';

@ -125,7 +125,9 @@ function edit_cat_def($id, $title, $comment, $nbline)
function remove_cat_def($id, $force = false)
{
global $TBL_USERINFO_CONTENT, $TBL_USERINFO_DEF;
$TBL_USERINFO_DEF = Database :: get_course_table(TABLE_USER_INFO);
$TBL_USERINFO_CONTENT = Database :: get_course_table(TABLE_USER_INFO_CONTENT);
$id = strval(intval($id));
if ( (0 == (int) $id || $id == "ALL") || ! is_bool($force))
@ -163,7 +165,7 @@ function remove_cat_def($id, $force = false)
function move_cat_rank($id, $direction) // up & down.
{
global $TBL_USERINFO_DEF;
$TBL_USERINFO_DEF = Database :: get_course_table(TABLE_USER_INFO);
$id = strval(intval($id));
if ( 0 == (int) $id || ! ($direction == "up" || $direction == "down") )
@ -200,7 +202,7 @@ function move_cat_rank($id, $direction) // up & down.
function move_cat_rank_by_rank($rank, $direction) // up & down.
{
global $TBL_USERINFO_DEF;
$TBL_USERINFO_DEF = Database :: get_course_table(TABLE_USER_INFO);
if ( 0 == (int) $rank || ! ($direction == "up" || $direction == "down") )
{
@ -443,7 +445,8 @@ function cleanout_cat_content($user_id, $definition_id)
function get_course_user_info($user_id)
{
global $TBL_USERINFO_CONTENT, $TBL_USERINFO_DEF;
$TBL_USERINFO_DEF = Database :: get_course_table(TABLE_USER_INFO);
$TBL_USERINFO_CONTENT = Database :: get_course_table(TABLE_USER_INFO_CONTENT);
$sql = "SELECT cat.id catId, cat.title,
cat.comment , content.content
@ -524,8 +527,9 @@ function get_main_user_info($user_id, $courseCode)
function get_cat_content($userId, $catId)
{
global $TBL_USERINFO_CONTENT, $TBL_USERINFO_DEF;
$TBL_USERINFO_DEF = Database :: get_course_table(TABLE_USER_INFO);
$TBL_USERINFO_CONTENT = Database :: get_course_table(TABLE_USER_INFO_CONTENT);
$userId = strval(intval($userId));
$catId = strval(intval($catId));
$sql = "SELECT cat.id catId, cat.title,
@ -558,8 +562,8 @@ function get_cat_content($userId, $catId)
*/
function get_cat_def($catId)
{
global $TBL_USERINFO_DEF;
$TBL_USERINFO_DEF = Database :: get_course_table(TABLE_USER_INFO);
$catId = strval(intval($catId));
$sql = "SELECT id, title, comment, line_count, rank FROM ".$TBL_USERINFO_DEF." WHERE id = '$catId'";
@ -587,8 +591,8 @@ function get_cat_def($catId)
*/
function get_cat_def_list()
{
global $TBL_USERINFO_DEF;
$TBL_USERINFO_DEF = Database :: get_course_table(TABLE_USER_INFO);
$sql = "SELECT id catId, title, comment , line_count
FROM ".$TBL_USERINFO_DEF."
ORDER BY rank";

@ -8,6 +8,7 @@ require_once('simpletest/unit_tester.php');
require_once('simpletest/web_tester.php');
require_once('simpletest/mock_objects.php');
require_once('simpletest/autorun.php');
require_once ('load_global.php');
require_once(dirname(__FILE__).'/../main/inc/global.inc.php');
require_once(api_get_path(SYS_CODE_PATH).'admin/calendar.lib.php');
require_once(api_get_path(SYS_CODE_PATH).'admin/statistics/statistics.lib.php');
@ -15,26 +16,24 @@ require_once(api_get_path(LIBRARY_PATH).'usermanager.lib.php');
require_once(api_get_path(SYS_CODE_PATH).'/survey/survey.lib.php');
require_once(api_get_path(SYS_CODE_PATH).'/install/install_upgrade.lib.php');
$_SESSION['_user']['user_id'] = 1;
$_user= 1;
class AllTests2 extends TestSuite {
function AllTests2() {
$this->TestSuite('All tests2');
$this->addTestFile(dirname(__FILE__).'/main/admin/calendar.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/admin/statistics/statistics.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/auth/lost_password.lib.test.php');
$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/admin/calendar.lib.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/admin/statistics/statistics.lib.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/auth/lost_password.lib.test.php');
//$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/newscorm/scorm.lib.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/install/install_upgrade.lib.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/survey/survey.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/work/work.lib.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/install/install_upgrade.lib.test.php');
/*
$this->addTestFile(dirname(__FILE__).'/main/admin/calendar.lib.test.php');

@ -0,0 +1,67 @@
<?php
require_once(dirname(__FILE__).'/../main/inc/global.inc.php');
require_once(api_get_path(LIBRARY_PATH).'add_course.lib.inc.php');
$cidReq = 'COURSEX';
// 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, __FILE__, __LINE__);
$row = Database::fetch_row($rs);
if (empty($row[0])) {
// create a course
$course_datos = array(
'wanted_code'=> 'COURSEX',
'title'=>'COURSEX',
'tutor_name'=>'John Doe',
'category_code'=>'LANG',
'course_language'=>'spanish',
'course_admin_id'=>'001',
'db_prefix'=> $_configuration['db_prefix'],
'firstExpirationDelay'=>'999'
);
$res = create_course($course_datos['wanted_code'], $course_datos['title'],
$course_datos['tutor_name'], $course_datos['category_code'],
$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
FROM $course_table
LEFT JOIN $course_cat_table
ON course.category_code = course_category.code
WHERE course.code = '$cidReq'";
$result = Database::query($sql,__FILE__,__LINE__);
if (Database::num_rows($result)>0) {
$cData = Database::fetch_array($result);
$_cid = $cData['code' ];
$_course = array();
$_course['id' ] = $cData['code' ]; //auto-assigned integer
$_course['name' ] = $cData['title' ];
$_course['official_code'] = $cData['visual_code' ]; // use in echo
$_course['sysCode' ] = $cData['code' ]; // use as key in db
$_course['path' ] = $cData['directory' ]; // use as key in path
$_course['dbName' ] = $cData['db_name' ]; // use as key in db list
$_course['dbNameGlu' ] = $_configuration['table_prefix'] . $cData['db_name'] . $_configuration['db_glue']; // use in all queries
$_course['titular' ] = $cData['tutor_name' ];
$_course['language' ] = $cData['course_language' ];
$_course['extLink' ]['url' ] = $cData['department_url' ];
$_course['extLink' ]['name'] = $cData['department_name'];
$_course['categoryCode'] = $cData['faCode' ];
$_course['categoryName'] = $cData['faName' ];
$_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['is_courseAdmin'] = 1;
?>

@ -2,10 +2,10 @@
require_once(api_get_path(LIBRARY_PATH).'blog.lib.php');
ob_start();
require_once (api_get_path(INCLUDE_PATH).'lib/fckeditor/fckeditor.php');
require_once(api_get_path(LIBRARY_PATH).'course.lib.php');
//require_once(api_get_path(SYS_CODE_PATH).'permissions/blog_permissions.inc.php');
ob_end_clean();
class TestBlog extends UnitTestCase
{
@ -21,11 +21,50 @@ class TestBlog extends UnitTestCase
public function setUp()
{
$this-> oblog = new Blog();
global $_configuration;
$course_code = 'COURSEX';
// check if course exists
$table_course = Database::get_main_table(TABLE_MAIN_COURSE);
$sql = "SELECT code FROM $table_course WHERE code = '$course_code' ";
$rs = Database::query($sql, __FILE__, __LINE__);
$row = Database::fetch_row($rs);
require_once api_get_path(SYS_PATH).'tests/main/inc/lib/add_course.lib.inc.test.php';
if (empty($row[0])) {
// create a course
$course_datos = array(
'wanted_code'=> 'COURSEX',
'title'=>'COURSEX',
'tutor_name'=>'John Doe',
'category_code'=>'LANG',
'course_language'=>'spanish',
'course_admin_id'=>'001',
'db_prefix'=> $_configuration['db_prefix'],
'firstExpirationDelay'=>'999'
);
$res = create_course($course_datos['wanted_code'], $course_datos['title'],
$course_datos['tutor_name'], $course_datos['category_code'],
$course_datos['course_language'],$course_datos['course_admin_id'],
$course_datos['db_prefix'], $course_datos['firstExpirationDelay']);
}
}
public function tearDown()
{
$this->oblog = null;
$res1 = CourseManager::delete_course('COURSEX');
$path = api_get_path(SYS_PATH).'archive';
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if (strpos($file,'COURSEX')!==false) {
if (is_dir($path.'/'.$file)) {
rmdirr($path.'/'.$file);
}
}
}
closedir($handle);
}
}
/*
@ -80,68 +119,65 @@ class TestBlog extends UnitTestCase
/**
* Test about get Title to a Blog
*/
// EXCEPTION
public function testGetBlogTitle(){
$res = $this->oblog->get_Blog_title(11);
$this->assertFalse($this->oblog->get_Blog_title(11)===String);
$this->assertTrue(is_String($res));
}
// EXCEPTION
public function testGetBlogSubtitle(){
$res = $this->oblog->get_Blog_subtitle(0);
$this->assertFalse($this->oblog->get_Blog_subtitle(0)=== null);
$this->assertTrue(is_String($res));
$this->assertNotNull($res);
}
// EXCEPTION
public function testGetBlogUsers(){
$res = $this->oblog->get_Blog_users(11);
$this->assertTrue($this->oblog->get_Blog_users(1110)===array());
$this->assertTrue(is_array($res));
}
// EXCEPTION
public function testCreateBlog(){
global $_user;
$res = $this->oblog->create_Blog('testingBlog','pass');
$this->assertTrue(is_null($res));
$this->assertNull($res);
$this->assertFalse($res);
}
// EXCEPTION
public function testEditBlog(){
global $_user;
$_user = array('Blog_id'=>1,'title'=>'TestBlog','subtitle'=>'testing');
$res = $this->oblog->edit_Blog($_user);
$blog_id = 1;
$title = 'titulo1';
$subtitle = 'subtitulo1';
$res = $this->oblog->edit_Blog($blog_id, $title, $subtitle);
$this->assertNull($res);
$this->assertTrue($this->oblog->edit_Blog($_user)=== $res);
$this->assertTrue($this->oblog->edit_Blog($blog_id, $title, $subtitle)=== $res);
$this->assertFalse($res);
}
// EXCEPTION
public function testDeleteBlog(){
$res = $this->oblog->delete_Blog(1);
$blog_id = 1;
$res = $this->oblog->delete_Blog($blog_id);
$this->assertTrue(is_null($res));
$this->assertNotNull($this->oblog->edit_Blog(1)===null);
$this->assertFalse(is_array($res));
}
// EXCEPTION
public function testCreatePost(){
global $_user, $_course, $Blog_table_attachment;
$Blog_table_attachment = array('title' => 'xxxxtestxxxx',
'full_text'=>'xxxxx',
'file_comment'=>'xxxxx',
'Blog_id'=>11
);
$res = $this->oblog->create_post($Blog_table_attachment);
$this->assertTrue($this->oblog->create_post($Blog_table_attachment)=== null);
global $_user, $_course;
$title = 'xxxxtestxxxx';
$full_text = 'xxxxx';
$file_comment = 'xxxxx';
$blog_id = 1;
$res = $this->oblog->create_post($title, $full_text, $file_comment, $blog_id);
$this->assertTrue($this->oblog->create_post($title, $full_text, $file_comment, $blog_id)=== null);
$this->assertNotNull(is_null,$res);
$this->assertFalse($res);
}
// EXCEPTION
public function testEditPost(){
ob_start();
$post_id =3;
@ -155,7 +191,7 @@ class TestBlog extends UnitTestCase
$this->assertTrue(is_null($res));
//var_dump($res);
}
// EXCEPTION
public function testDeletePost(){
$Blog_id = 11;
$post_id = 21;
@ -172,9 +208,8 @@ class TestBlog extends UnitTestCase
$this->assertNotNull($this->oblog->create_comment('tesingBlog','xxxxxxx','xxx',12,1,null)===null);
$this->assertTrue(is_null($res));
$this->assertFalse($res);
}
// EXCEPTION
public function testDeleteComment(){
$res = $this->oblog->delete_comment(11,12,2);
$this->assertNotNull($this->oblog->delete_comment(11,12,2)===null);
@ -187,87 +222,100 @@ class TestBlog extends UnitTestCase
$this->assertTrue(is_null($res));
$this->assertFalse($res);
$this->assertFalse(null,$res);
}
// EXCEPTION
public function testEditTask() {
$res = $this->oblog->edit_task();
$blog_id = 1;
$task_id = 2;
$title = 'xxxxxx';
$description = 'xx';
$articleDelete = 'aaa';
$articleEdit = 'axa';
$commentsDelete = 'xax';
$color = 'red';
$res = $this->oblog->edit_task($blog_id, $task_id, $title, $description, $articleDelete, $articleEdit, $commentsDelete, $color);
//$res = Blog::edit_task();
$this->assertTrue($this->oblog->edit_task()===null);
$this->assertTrue($this->oblog->edit_task($blog_id, $task_id, $title, $description, $articleDelete, $articleEdit, $commentsDelete, $color)===null);
$this->assertTrue(is_null($res));
$this->assertFalse(is_string($res));
$this->assertNull($res);
}
// EXCEPTION
public function testDeleteTask(){
$res = $this->oblog->delete_task();
$this->assertTrue($this->oblog->delete_task()===null);
$blog_id = 1;
$task_id = 2;
$res = $this->oblog->delete_task($blog_id, $task_id);
$this->assertTrue($this->oblog->delete_task($blog_id, $task_id)===null);
$this->assertTrue(is_null($res));
}
public function testDeleteAssignedTask(){
$res = $this->oblog->delete_assigned_task();
$this->assertTrue($this->oblog->delete_assigned_task()===null);
$blog_id = 1;
$task_id = 2;
$user_id = 1;
$res = $this->oblog->delete_assigned_task($blog_id, $task_id,$user_id);
$this->assertTrue($this->oblog->delete_assigned_task($blog_id, $task_id,$user_id)===null);
$this->assertNotNull(is_null($res));
$this->assertFalse($res);
}
public function testGetPersonalTaskList(){
global $_user;
ob_start();
$res = Blog::get_personal_task_list('a');
$this->assertEqual($this->oblog->get_personal_task_list(1)===1);
$this->assertFalse($res);
ob_end_clean();
}
public function testChangeBlogVisibility(){
$res = $this->oblog->change_blog_visibility();
$this->assertTrue($this->oblog->change_blog_visibility()=== null);
$blog_id = 1;
$res = $this->oblog->change_blog_visibility($blog_id);
$this->assertTrue($this->oblog->change_blog_visibility($blog_id)=== null);
$this->assertTrue(is_null($res));
}
public function testDisplayBlogPosts(){
ob_start();
$res = $this->oblog->display_blog_posts(10,null,null);
$this->assertTrue($this->oblog->display_blog_posts(10,null,null)=== null);
$blog_id = 1;
$filter = '1=1';
$max_number_of_posts = 20;
$res = BLog::display_blog_posts($blog_id, $filter, $max_number_of_posts);
$this->assertTrue($this->oblog->display_blog_posts($blog_id, $filter, $max_number_of_posts)=== null);
ob_end_clean();
$this->assertNull($res);
$this->assertTrue(is_null($res));
$this->assertFalse(null, $res);
ob_end_clean();
}
public function testDisplaySearchResults(){
ob_start();
$res = $this->oblog->display_search_results(11,null);
$this->assertTrue($this->oblog->display_search_results(11,null)===null);
$blog_id = 1;
$query_string = '"SELECT post.*, user.lastname, user.firstname FROM $tbl_blogs_posts"';
$res = $this->oblog->display_search_results($blog_id, $query_string);
ob_end_clean();
$this->assertTrue(is_null($res));
$this->assertNull($res);
}
public function testDisplayDayResults(){
ob_start();
$res = $this->oblog->display_day_results(12,null);
$this->assertTrue($this->oblog->display_day_results(12,null)===null);
$blog_id = 1;
$query_string = '01-01-2010';
$res = $this->oblog->display_day_results($blog_id, $query_string);
ob_end_clean();
$this->assertTrue(is_null($res));
$this->assertFalse($res);
$this->assertNull(null,$res);
ob_end_clean();
}
public function testDisplayPost(){
ob_start();
$res = $this->oblog->display_post(12,11);
$this->assertTrue($this->oblog->display_post(12,11)===null);
$this->assertFalse($res);
$this->assertTrue(is_null($res));
$blog_id = 1;
$post_id = 2;
$res = $this->oblog->display_post($blog_id, $post_id);
ob_end_clean();
$this->assertTrue(is_null($res));
$this->assertFalse($res);
}
public function testAddRating(){
@ -276,7 +324,6 @@ class TestBlog extends UnitTestCase
$this->assertFalse($this->oblog->add_rating(null,11,2,5)=== bool);
$this->assertTrue(is_bool($res));
$this->assertFalse(null,$res);
}
public function testDisplayRating(){
@ -286,7 +333,6 @@ class TestBlog extends UnitTestCase
$this->assertTrue(is_numeric($res));
$this->assertFalse($res);
ob_end_clean();
}
public function testDisplayRatingForm(){
@ -295,43 +341,40 @@ class TestBlog extends UnitTestCase
$this->assertFalse($this->oblog->display_rating_form('xxx',11,1,null)===null);
$this->assertTrue(is_string($res));
$this->assertNotNull($res,null);
}
public function testGetThreadedComments(){
ob_start();
$current = 0;
$current_level = 0;
$blog_id = 1;
$post_id = 2;
$task_id = 0;
global $charset, $dataFormatLong;
$res = $this->oblog->get_threaded_comments(null,null,11,2,null);
$this->assertFalse($res);
$this->assertTrue($this->oblog->get_threaded_comments(null,null,11,2,null)===null);
$res = $this->oblog->get_threaded_comments($current, $current_level, $blog_id, $post_id, $task_id);
ob_end_clean();
$this->assertFalse($res);
$this->assertTrue(is_null($res));
}
/**
* this function have will be testing with mocks
*/ /* usando mock */
/* public function testDisplayFormNewPost(){
// $mock = new Mock('FCKeditor');
ob_start();
$res = $this->oblog->display_form_new_post(12);
//$res = ob_get_contents();
// $mock->expectOnce('FCKeditor','post_full_text');
$this->assertTrue($this->oblog->display_form_new_post(12));
$this->assertTrue(is_string($res));
$this->assertNotNull($res);
ob_end_clean();
public function testDisplayFormNewPost(){
ob_start();
$blog_id = 1;
$res = Blog::display_form_new_post($blog_id);
$this->assertTrue(is_null($res));
$this->assertNull($res);
ob_end_clean();
}
/* usando mock */
public function testDisplayFormEditPost(){
ob_start();
$res = $this->oblog->display_form_edit_post(null);
$blog_id = 1;
$post_id = 2;
$res = $this->oblog->display_form_edit_post($blog_id, $post_id);
$this->assertNotNull(is_null($res));
$this->assertFalse($res);
ob_end_clean();
//var_dump($res);
}
public function testDisplayTaskList(){
@ -339,9 +382,8 @@ class TestBlog extends UnitTestCase
$res = $this->oblog->display_task_list(11);
$this->assertTrue($this->oblog->display_task_list(11)===null);
ob_end_clean();
}
// exceptions
public function testDisplayAssignedTaskList(){
ob_start();
global $charset, $color2;
@ -349,7 +391,6 @@ class TestBlog extends UnitTestCase
$this->assertTrue($this->oblog->display_assigned_task_list(11)===null);
$this->assertFalse($res);
ob_end_clean();
}
public function testDisplayNewTaskForm(){
@ -360,7 +401,7 @@ class TestBlog extends UnitTestCase
ob_end_clean();
}
// exceptions /*
public function testDisplayEditTaskForm(){
ob_start();
$res = $this->oblog->display_edit_task_form(11,12);
@ -370,7 +411,7 @@ class TestBlog extends UnitTestCase
$this->assertFalse($res);
}
// exceptions
public function testDisplayAssignTaskForm(){
ob_start();
$res = $this->oblog->display_assign_task_form(11);
@ -379,7 +420,7 @@ class TestBlog extends UnitTestCase
$this->assertTrue(is_null($res));
ob_end_clean();
}
// exceptions
public function testDisplayEditAssignedTaskForm(){
global $MonthsLong;
ob_start();
@ -389,7 +430,7 @@ class TestBlog extends UnitTestCase
$this->assertFalse($res);
}
// excetions
public function testAssignTask(){
ob_start();
$res = $this->oblog->assign_task(11,1,12,null);
@ -397,9 +438,8 @@ class TestBlog extends UnitTestCase
$this->assertFalse(is_numeric($res));
$this->assertNull(null,$res);
ob_end_clean();
}
// exceptions
public function testEditAssignedTask(){
$task = array('blog_id'=>11,
'user_id'=>1,
@ -409,12 +449,11 @@ class TestBlog extends UnitTestCase
'old_task_id'=>11,
'old_target_date'=>'xxxzxxx'
);
$res = $this->oblog->edit_assigned_task();
$this->assertTrue($this->oblog->edit_assigned_task()===null);
$res = $this->oblog->edit_assigned_task($task['blog_id'],$task['user_id'], $task['task_id'], $task['target_date'], $task['old_user_id'], $task['old_task_id'], $task['old_target_date']);
$this->assertNull($res);
$this->assertTrue(is_null($res));
}
// EXCEPTIONS
public function testDisplaySelectTaskPost(){
ob_start();
$res = $this->oblog->display_select_task_post(11,12);
@ -422,25 +461,22 @@ class TestBlog extends UnitTestCase
$this->assertTrue(is_null($res));
$this->assertFalse($res);
ob_end_clean();
}
}
public function testSetUserSubscribed(){
$res = $this->oblog->set_user_subscribed(11,12);
$this->assertTrue($this->oblog->set_user_subscribed(11,12)===null);
$this->assertFalse($res);
$this->assertTrue(is_null($res));
}
}
public function testUserUnsubscribed(){
$res = $this->oblog->set_user_unsubscribed(11,12);
$this->assertTrue($this->oblog->set_user_unsubscribed(11,12)===null);
$this->assertFalse($res);
$this->assertTrue(is_null($res));
}
// exception
public function testDisplayFormUserSubscribe(){
ob_start();
$res = $this->oblog->display_form_user_subscribe(12);
@ -448,31 +484,24 @@ class TestBlog extends UnitTestCase
$this->assertNotNull(is_null($res));
$this->assertFalse($res);
ob_end_clean();
}
/**
* this function have been tested modified the function
* display_form_user_unsubscribe in the blog.lib.php
* main_table and course_table.
*
*/ /* usando mocks *//* ERROR
*/public function testDisplayFormUserUnsubscribe(){
/**
* this function have been tested modified the function
* display_form_user_unsubscribe in the blog.lib.php
* main_table and course_table.
*
*/
public function testDisplayFormUserUnsubscribe(){
global $_user;
ob_start();
$blog_id = '1';
$res = Blog::display_form_user_unsubscribe($blog_id);
$this->assertTrue(($res)===false);
$this->assertTrue(is_bool($res));
$this->assertTrue(is_null($res));
$this->assertNull($res);
ob_end_clean();
var_dump($res);
//$this->assertFalse($this->oblog->display_form_user_unsubscribe($blog_id,$course_id)==='0001');
//$this->assertFalse($res);
//$this->assertTrue(is_null($res));
//$this->assertTrue(is_array($res));
}
public function testDisplayFormUserRights(){
@ -482,31 +511,30 @@ class TestBlog extends UnitTestCase
$this->assertFalse($res);
ob_end_clean();
}
/* usando mocks ERROR */
public function testDisplayNewCommentForm(){
$blog_id = '12';
$post_id='1';
$title='test';
ob_start();
$res =$this->oblog->display_new_comment_form($blog_id,$post_id,$title);
//$res = ob_get_contents();
//$this->assertTrue($this->oblog->display_new_comment_form(12,1,'comment_text')===null);
$this->assertFalse($res);
$this->assertNotNull(is_null($res));
ob_end_clean();
//var_dump($res);
}
// exception
public function testDisplayMinimonthcalendar(){
global $_user,$DaysShort, $MonthsLong;
ob_start();
$res = $this->oblog->display_minimonthcalendar();
$this->assertTrue($this->oblog->display_minimonthcalendar()=== null);
$month = 12;
$year = 2010;
$blog_id = 1;
$res = $this->oblog->display_minimonthcalendar($month, $year, $blog_id);
$this->assertTrue($this->oblog->display_minimonthcalendar($month, $year, $blog_id)=== null);
$this->assertTrue(is_null($res));
ob_end_clean();
}
public function testDisplayNewBlogForm(){
ob_start();
$res = $this->oblog->display_new_blog_form();
@ -514,16 +542,14 @@ class TestBlog extends UnitTestCase
$this->assertTrue(is_null($res));
$this->assertTrue($this->oblog->display_new_blog_form()===null);
ob_end_clean();
}
// exception
public function testDisplayEditBlogForm(){
ob_start();
$res = $this->oblog->display_edit_blog_form(12);
$this->assertTrue($this->oblog->display_edit_blog_form(12)===null);
$this->assertTrue(is_null($res));
ob_end_clean();
}
public function testDisplayBlogList(){
@ -533,37 +559,65 @@ class TestBlog extends UnitTestCase
$this->assertTrue(is_null($res));
ob_end_clean();
}
// EXCEPTION
public function testGetBlogAttachment(){
ob_start();
global $blog_table_attachment;
$oblog_table_attachment = array('blog_id'=>12);
$res=get_blog_attachment();
ob_end_clean();
global $_configuration;
$blog_id = '0';
$post_id = null;
$comment_id = null;
$res = get_blog_attachment($blog_id, $post_id,$comment_id);
$this->assertFalse($res);
$this->assertTrue(is_array($res));
ob_end_clean();
}
// EXCEPTION
public function testDeleteAllBlogAttachment(){
global $blog_table_attachment, $_course;
$res = delete_all_blog_attachment(12,null,null);
global $_course,$_configuration;
$blog_id = 1;
$post_id=null;
$comment_id=null;
$res = delete_all_blog_attachment($blog_id,$post_id,$comment_id);
$this->assertFalse($res);
$this->assertNull($res);
}
// EXCEPTION
}
public function testGetBlogPostFromUser(){
$res = get_blog_post_from_user('mate',2);
global $_configuration;
$res = get_blog_post_from_user('chamilo_COURSEX',1);
$this->assertFalse($res);
$this->assertTrue(is_string($res));
}
// EXCEPTION
public function testGetBlogCOmmentFromUser(){
$res = get_blog_comment_from_user('mate',2);
public function testGetBlogCommentFromUser(){
global $_configuration;
$course_datos['wanted_code'] = 'chamilo_COURSEX';
$user_id = 1;
$res = get_blog_comment_from_user($course_datos['wanted_code'],1);
$this->assertFalse($res);
$this->assertTrue(is_string($res));
$path = api_get_path(SYS_PATH).'archive';
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if (strpos($file,'COURSEX')!==false) {
if (is_dir($path.'/'.$file)) {
rmdirr($path.'/'.$file);
}
}
}
closedir($handle);
}
}
public function testDeleteCourse() {
global $cidReq;
$resu = CourseManager::delete_course($cidReq);
}
}
?>
}
?>

@ -1,9 +1,5 @@
<?php
Mock::generate('Database');
Mock::generate('Display');
$config['survey']['debug'] = false;
require_once(api_get_path(LIBRARY_PATH).'add_course.lib.inc.php');
require_once(api_get_path(LIBRARY_PATH).'course.lib.php');
class TestSurvey extends UnitTestCase {
@ -18,152 +14,169 @@ class TestSurvey extends UnitTestCase {
$this->UnitTestCase('');
}
public function setUp() {
public function setUp() {
$this->smanager = new survey_manager();
$this->squestion = new question();
$this->syesno = new yesno();
$this->smultiplechoice = new multiplechoice();
$this->spersonality = new personality();
$this->smultipleresponse = new multipleresponse();
$this->smultipleresponse = new multipleresponse();
}
public function tearDown() {
public function tearDown() {
$this-> smanager = null;
$this-> squestion = null;
$this-> syesno = null;
$this->smultiplechoice = null;
$this->personality = null;
$this->multipleresponse = null;
$this->multipleresponse = null;
}
public function testGetSurvey() {
$instans = new MockDatabase();
global $_course;
$survey_id=1;
$shared=1;
$my_course_id=$_GET['course'];
$res = $this->smanager->get_survey($survey_id,$shared);
$my_course_info=api_get_course_info($my_course_id);
$table_survey = Database :: get_course_table(TABLE_SURVEY, $my_course_info['dbName']);
$sql = "SELECT * FROM $table_survey WHERE survey_id='".Database::escape_string($survey_id)."'";
$result = Database::query($sql, __FILE__, __LINE__);
$instans->expectCallCount($table_survey);
$this->assertTrue(is_array($res));
$this->assertFalse($result);
//var_dump($table_survey);
//var_dump($result);
//var_dump($res);
}
public function testStoreSurvey(){
$instans = new MockDatabase();
global $_user;
$values=array('002','003','003');
$table_survey=Database::get_course_table(TABLE_SURVEY);
$shared_survey_id=0;
$instans->expectCallCount($table_survey);
//if(!$values['survey_id'] OR !is_numeric($values['survey_id']))
public function testStoreSurvey() {
global $_user,$cidReq;
$values = array(
'survey_code' => 'Survey1',
'survey_title' => '<p>Survey</p>',
'survey_subtitle' => '',
'survey_language' => 'spanish',
'start_date' => '2010-01-19',
'end_date' => '2010-01-29',
'survey_introduction' => '',
'survey_thanks' => '',
'survey_type' => '0',
'parent_id' => '0',
'submit_survey' => ''
);
$res = $this->smanager->store_survey($values);
$this->assertTrue($res);
$this->assertTrue(is_array($res));
$this->assertTrue($res);
$this->assertTrue($table_survey);
//var_dump($res);
//var_dump($table_survey);
$this->assertTrue(is_array($res));
}
public function testStoreSharedSurvey($values){
$instans = new MockDatabase();
$values=array('');
global $_user;
global $_course;
$table_survey=Database::get_main_table(TABLE_MAIN_SHARED_SURVEY);
$instans->expectCallCount(Database::get_main_table(TABLE_MAIN_SHARED_SURVEY));
if(!$values['survey_id'] OR !is_numeric($values['survey_id']) OR $values['survey_share']['survey_share'] == 'true') {
$sql = "INSERT INTO $table_survey (code, title, subtitle, author, lang, template, intro, surveythanks, creation_date, course_code)";
$result = Database::query($sql, __FILE__, __LINE__);
$return = Database::insert_id();
}else{
$sql = "UPDATE $table_survey SET";
$result = Database::query($sql, __FILE__, __LINE__);
$return = $values['survey_share']['survey_share'];
}
public function testGetSurvey() {
$course_code = 'COURSEX';
$survey_id=1;
$res3 = $this->smanager->get_survey($survey_id,0,$course_code);
$this->assertTrue(is_array($res3));
}
public function testStoreSharedSurvey() {
global $_user,$cidReq;
$values = array(
'survey_code' => 'Survey1',
'survey_title' => '<p>Survey</p>',
'survey_subtitle' => 'Survey subtitle',
'survey_language' => 'spanish',
'start_date' => '2010-01-19',
'end_date' => '2010-01-29',
'survey_introduction' => 'introduction',
'survey_thanks' => '',
'survey_type' => '1',
'parent_id' => '1',
'submit_survey' => ''
);
$res = $this->smanager->store_shared_survey($values);
$this->assertTrue($res);
//var_dump($res);
//var_dump($table_survey);
//var_dump($table_survey);
}
public function testDeleteSurvey(){
$instans = new MockDatabase();
$survey_id=1;
$shared=false;
$course_code=001;
$table_survey= Database :: get_course_table(TABLE_SURVEY,$course_code);
$table_survey_question_group = Database :: get_course_table(TABLE_SURVEY_QUESTION_GROUP,$course_code);
$instans->expectOnce($table_survey);
$res = $this->smanager->delete_survey($survey_id, $shared, $course_code);
$this->assertTrue($res);
//Build the form
public function testQuestionCreateForm() {
global $charset;
global $survey_data;
$form_content = array();
$res = $this->squestion->create_form($form_content);
$this->assertTrue(is_string($res));
$this->assertTrue($table_survey);
//var_dump($table_survey_question_group);
}
public function testQuestionRenderForm() {
ob_start();
$this->squestion->render_form();
ob_end_clean();
$this->assertNotNull($this->squestion->html);
//var_dump($res);
}
public function testYesNoCreateForm() {
$form_content=array();
$res1 = $this->syesno->create_form($form_content);
$this->assertNull($res1);
}
public function testCopySurvey(){
$instans = new MockDatabase();
$parent_survey=null;
$new_survey_id=null;
$instans->expectCallCount(Database::get_course_table(TABLE_SURVEY));
$sql = "SELECT * from $table_survey_question_group " .
"WHERE survey_id='".$parent_survey."'";
$result = Database::query($sql, __FILE__, __LINE__);
$res = $this->smanager->copy_survey($parent_survey,$new_survey_id);
$this->assertTrue(is_bool($res));
$this->assertTrue($res);
$this->assertTrue($instans);
public function testMultipleChoiceCreateForm() {
$form_content=array();
$res2 = $this->smultiplechoice->create_form($form_content);
$this->assertNull($res2);
}
public function testPersonalityCreateForm() {
$form_content=array();
$this->spersonality->create_form($form_content);
$this->assertNotNull($this->spersonality->html);
$this->assertTrue($this->spersonality->html);
}
public function testMultipleResponseCreateForm() {
$form_content=array();
$this->smultipleresponse->create_form($form_content);
$this->assertNotNull($this->smultipleresponse->html);
$this->assertTrue($this->smultipleresponse->html);
}
public function testQuestionRenderQuestion() {
$form_content=array();
$res = $this->squestion->render_question($form_content);
$this->assertNull($res);
$this->assertTrue(is_null($res));
//var_dump($res);
//var_dump($result);
}
public function testMultipleChoiseRenderQuestion() {
$form_content=array();
$answers=array();
$this->smultiplechoice->render_question($form_content,$answers);
$this->assertNull($this->smultiplechoice->html);
}
public function testYesNoRenderQuestion() {
$form_content=array();
$answers=array();
$this->syesno->render_question($form_content,$answers);
$this->assertNull($this->syesno->html);
}
public function testEmpty_survey(){
$instans = new MockDatabase();
$table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION);
$table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER);
$table_survey = Database :: get_course_table(TABLE_SURVEY);
$survey_id=null;
$instans->expectOnce($table_survey);
$instans->expectCallCount(count($table_survey));
$instans->expectCallCount($table_survey);
$res = $this->smanager->empty_survey($survey_id);
public function testPersonalityRenderQuestion() {
$form_content=array();
$answers=array();
$this->spersonality->render_question($form_content,$answers);
$this->assertNull($this->spersonality->html);
$this->assertFalse($this->spersonality->html);
}
public function testAddRemoveButtons() {
$form_content = array();
$res = $this->squestion->add_remove_buttons($form_content);
$this->assertTrue($res);
$this->assertTrue(is_object($instans));
//var_dump($res);
//var_dump($table_survey);
}
public function testUpdateSurveyAnswered(){
$instans = new MockDatabase();
global $_course;
$survey_id=1;
$user=001;
$survey_code=001;
$table_survey= Database :: get_course_table(TABLE_SURVEY, $_course['db_name']);
$table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION, $_course['db_name']);
$instans->expectCallCount($table_survey);
$instans->expectCallCount(count($table_survey_invitation));
$sql = "UPDATE $table_survey_invitation SET answered='1' WHERE session_id='".api_get_session_id()."' AND user='".Database::escape_string($user)."' AND survey_code='".Database::escape_string($survey_code)."'";
$res = Database::query($sql, __FILE__, __LINE__);
$result = $this->smanager->update_survey_answered($survey_id, $user, $survey_code);
//save the survey
public function testCopySurvey() {
$parent_survey = Database::escape_string($parent_survey);
$new_survey_id = '1';
$res = $this->smanager->copy_survey($parent_survey,$new_survey_id);
$this->assertTrue(is_bool($res));
$this->assertTrue($res === false);
//var_dump($result);
$this->assertTrue($res);
//var_dump($res);
}
public function testGetCompleteSurveyStructure(){
public function testGetCompleteSurveyStructure() {
$survey_id='';
$shared=0;
$res = $this->smanager->get_complete_survey_structure($survey_id, $shared);
@ -172,7 +185,7 @@ class TestSurvey extends UnitTestCase {
//var_dump($res);
}
public function testIconQuestion(){
public function testIconQuestion() {
$type='open';
$res = $this->smanager->icon_question($type);
if(is_bool($res)) {
@ -184,342 +197,179 @@ class TestSurvey extends UnitTestCase {
}
//var_dump($res);
}
public function testSaveQuestion() {
$form_content=array();
$res = $this->smanager->save_question($form_content);
$this->assertTrue($res);
$this->assertTrue(is_string($res));
//var_dump($res);
}
public function testGetQuestion(){
$instans = new MockDatabase();
$question_id=01;
$shared=false;
$tbl_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
$table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
$sql = "SELECT * FROM $tbl_survey_question WHERE question_id='".Database::escape_string($question_id)."' ORDER BY `sort`";
$result = Database::query($sql, __FILE__, __LINE__);
$row = Database::fetch_array($result,'ASSOC');
$res = $this->smanager->get_question($question_id,$shared);
public function testSaveSharedQuestion() {
$form_content=array('');
$survey_data=array('survey_share');
$res = $this->smanager->save_shared_question($form_content,$survey_data);
$this->assertTrue($res);
$instans->expectOnce(count($res));
//var_dump($res);
//var_dump($result);
}
public function testGetQuestions(){
$get_questions = new MockDatabase();
$survey_id =1;
$tbl_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
$table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
$sql = "SELECT * FROM $tbl_survey_question WHERE survey_id='".Database::escape_string($survey_id)."'";
$result = Database::query($sql, __FILE__, __LINE__);
$row = Database::fetch_array($result,'ASSOC');
$res= $this->smanager->get_questions($survey_id);
$get_questions->expectCallCount($result);
$this->assertNull($res);
public function testSaveQuestionOptions() {
$form_content=array();
$survey_data=array('survey_share');
$res = $this->smanager->save_question_options($form_content,$survey_data);
$this->assertTrue(is_null($res));
//var_dump($res);
//var_dump($row);
//var_dump($get_questions);
}
public function testSaveQuestion(){
global $survey_data;
global $_course;
$form_content=array('question'=>'121212');
$res = $this->smanager->save_question($form_content['question']);
$this->assertTrue($res);
$this->assertTrue(is_string($res));
public function testSaveSharedQuestionOptions() {
$form_content=array();
$survey_data=array();
$res = $this->smanager->save_shared_question_options($form_content,$survey_data);
$this->assertTrue(is_null($res));
$this->assertNull($res);
//var_dump($res);
}
//get the survey
public function testGetPeopleWhoFilledSurvey() {
$survey_id=1;
$all_user_info=false;
$survey_data = survey_manager::get_survey($survey_id);
$result = $this->smanager->get_people_who_filled_survey($survey_id,false);
$this->assertTrue(is_array($result));
//var_dump($result);
}
public function testSaveSharedQuestion(){
$instans = new MockDatabase();
global $_course;
$form_content=array('');
$survey_data=array('');
$tbl_survey_question= Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION);
$res = $this->smanager->save_shared_question($form_content,$survey_data);
$instans->expectOnce($tbl_survey_question);
public function testGetQuestion() {
$question_id=1;
$res = $this->smanager->get_question($question_id,false);
$this->assertTrue($res);
$this->assertTrue($instans);
//var_dump($res);
//var_dump($instans);
//var_dump($result);
}
public function testMoveSurveyQuestion(){
$instans = new MockDatabase();
$table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
public function testGetQuestions() {
$survey_id =1;
$res= $this->smanager->get_questions($survey_id);
$this->assertNull($res);
//var_dump($res);
}
//move the survey
public function testMoveSurveyQuestion() {
$direction='moveup';
$survey_question_id=01;
$survey_question_id=1;
$survey_id=1;
/*$sql = "SELECT * FROM $table_survey_question WHERE survey_id='".Database::escape_string($survey_id)."' ORDER BY sort $sort";
$result = Database::query($sql, __FILE__, __LINE__);
*/
$res = $this->smanager->move_survey_question($direction,$survey_question_id,$survey_id);
$this->assertTrue(is_null($res));
//var_dump($res);
}
public function testDeleteAllSurveyQuestions(){
$instans = new MockDatabase();
$table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
//epmty the survey
public function testEmpty_survey() {
$survey_id=null;
$res = $this->smanager->empty_survey($survey_id);
$this->assertTrue($res);
//var_dump($res);
}
//functions delete
public function testHandleAction() {
$form_content = array('');
$res = $this->squestion->handle_action($form_content);
$this->assertTrue(is_array($res));
//var_dump($res);
}
public function testDeleteAllSurveyQuestions() {
$survey_id=1;
$shared=false;
$sql = "DELETE from $table_survey_question WHERE survey_id='".Database::escape_string($survey_id)."'";
$res = Database::query($sql, __FILE__, __LINE__);
$result = $this->smanager->delete_all_survey_questions($survey_id,$shared);
$instans->expectOnce($res);
$this->assertTrue(is_null($result));
$this->assertTrue(is_bool($res));
$this->assertTrue($res === true || $res === false);
//var_dump($result);
//var_dump($res);
}
public function testDeleteSurveyQuestion(){
$instans = new MockDatabase();
$table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
public function testDeleteSurveyQuestion() {
$survey_id =1;
$question_id=01;
$shared=false;
$sql = "DELETE from $table_survey_question WHERE survey_id='".Database::escape_string($survey_id)."' AND question_id='".Database::escape_string($question_id)."'";
$res = Database::query($sql, __FILE__, __LINE__);
$instans->expectOnce($res);
$result = $this->smanager->delete_survey_question($survey_id,$question_id);
$this->assertTrue(is_null($result));
$this->assertTrue(is_object($instans));
$this->assertFalse($res);
//var_dump($result);
//var_dump($res);
}
public function testDeleteSharedSurveyQuestion(){
$instans = new MockDatabase();
public function testDeleteSharedSurveyQuestion() {
$survey_id=1;
$question_id=01;
$table_survey_question = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION);
$table_survey_question_option = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION_OPTION);
$res = $this->smanager->delete_shared_survey_question($survey_id,$question_id);
$instans->expectOnce($table_survey_question);
$this->assertTrue(is_null($res));
$this->assertTrue(is_object($instans));
//var_dump($res);
}
public function testSaveQuestionOptions(){
$instans = new MockDatabase();
$form_content=array('percentage');
$survey_data=array('survey_share');
$table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
$instans->expectOnce($table_survey_question_option);
$res = $this->smanager->save_question_options($form_content,$survey_data);
$this->assertTrue(is_null($res));
$this->assertTrue(is_object($instans));
//var_dump($res);
//var_dump($table_survey_question_option);
}
public function testSaveSharedQuestionOptions(){
$instans = new MockDatabase();
$form_content=array('answers');
$survey_data=array('');
$table_survey_question_option = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION_OPTION);
$sql = "DELETE FROM $table_survey_question_option WHERE question_id = '".Database::escape_string($form_content['shared_question_id'])."'";
$result = Database::query($sql, __FILE__, __LINE__);
$instans->expectCallCount($result);
$res = $this->smanager->save_shared_question_options($form_content,$survey_data);
$this->assertTrue(is_bool($result));
$this->assertTrue($result === true || $result === false);
$this->assertTrue(is_null($res));
$this->assertNull($res);
public function testDeleteSurvey() {
$survey_id=1;
$shared=false;
$course_code=001;
$res = $this->smanager->delete_survey($survey_id, $shared, $course_code);
$this->assertTrue($res);
//var_dump($res);
//var_dump($result);
}
public function testDeleteAllSurveyQuestionsOptions(){
$instans = new MockDatabase();
$table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
public function testDeleteAllSurveyQuestionsOptions() {
$survey_id=1;
$shared=false;
$sql = "DELETE from $table_survey_question_option WHERE survey_id='".Database::escape_string($survey_id)."'";
$res = Database::query($sql, __FILE__, __LINE__);
$result = $this->smanager->delete_all_survey_questions_options($survey_id,$shared);
$instans->expectCallCount($res);
$this->assertTrue($result);
$this->assertFalse($res);
$this->assertTrue(is_bool($res));
//var_dump($result);
//var_dump($res);
}
public function testDeleteSurveyQuestionOption(){
$instans = new MockDatabase();
public function testDeleteSurveyQuestionOption() {
$survey_id=1;
$question_id=01;
$shared=false;
$table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
$sql = "DELETE from $table_survey_question_option WHERE survey_id='".Database::escape_string($survey_id)."' AND question_id='".Database::escape_string($question_id)."'";
$res = Database::query($sql, __FILE__, __LINE__);
$instans->expectOnce($res);
$instans->expectCallCount($res);
$result = $this->smanager->delete_survey_question_option($survey_id,$question_id,$shared);
if(is_bool($result))
$this->assertTrue(is_bool($result));
$this->assertTrue($result === true || $result===false);
$this->assertTrue($result);
if(is_bool($res))
$this->assertTrue(is_bool($res));
$this->assertTrue($res === true || $res===false);
$this->assertFalse($res);
$this->assertTrue($result);
//var_dump($result);
//var_dump($res);
}
public function testDeleteAllSurveyAnswers(){
$instans = new MockDatabase();
public function testDeleteAllSurveyAnswers() {
$survey_id=1;
$table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER);
$instans->expectCallCount($table_survey_answer);
$res = $this->smanager->delete_all_survey_answers($survey_id);
$this->assertTrue(is_bool($res));
$this->assertTrue($res);
$this->assertTrue($res === true || $res === false);
$this->assertTrue($table_survey_answer);
//var_dump($res);
//var_dump($table_survey_answer);
}
public function testGetPeopleWhoFilledSurvey(){
$instans = new MockDatabase();
$survey_id=1;
$all_user_info=false;
global $_course;
$table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER, $_course['db_name']);
$table_user = Database :: get_main_table('user');
$survey_data = survey_manager::get_survey($survey_id);
$sql = "SELECT DISTINCT user FROM $table_survey_answer WHERE survey_id= '".Database::escape_string($survey_data['survey_id'])."'";
$res = Database::query($sql, __FILE__, __LINE__);
$instans->expectCallCount($table_user);
$result = $this->smanager->get_people_who_filled_survey($survey_id,$all_user_info);
$this->assertTrue(is_array($result));
$this->assertNotNull($res);
$this->assertFalse($res);
$this->assertTrue(is_bool($res));
$this->assertTrue($res=== true || $res === false);
$this->assertTrue($sql);
//var_dump($res);
//Contest the answer
public function testUpdateSurveyAnswered() {
global $user;
$survey_code = 'Survey1';
$survey_id = '1';
$result = $this->smanager->update_survey_answered($survey_id, $user, $survey_code);
$this->assertTrue(is_null($result));
//var_dump($result);
//var_dump($sql);
}
public function testCreateForm(){
$instans = new MockDisplay();
global $charset;
global $survey_data;
$tool_name = 'AddQuestion';
$tool_name = Display::return_icon(survey_manager::icon_question(Security::remove_XSS($_GET['type'])),get_lang(ucfirst(Security::remove_XSS($_GET['type']))),array('align'=>'middle', 'height'=>'22px')).' ';
$form_content=array('');
$res = $this->squestion->create_form($form_content);
$instans->expectCallCount($tool_name);
$this->assertTrue($res);
$this->assertTrue($tool_name);
//var_dump($res);
//var_dump($tool_name);
}
public function testRenderForm(){
ob_start();
$this->squestion->render_form();
ob_end_clean();
$this->assertNotNull($this->squestion->html);
//var_dump($res);
}
public function testHandleAction(){
global $config;
$form_content['answers']=array('');
$message = 'PleaseEnterAQuestion';
$max_answer = count($form_content['answers']);
foreach ($_POST['delete_answer'] as $key=>$value) {
$delete = $key;
}
$res = $this->squestion->handle_action($form_content);
$this->assertTrue(is_array($res));
$this->assertTrue(isset($form_content['answers'][$max_answer-1]));
//var_dump($res);
}
public function testAddRemoveButtons(){
$form_content['answers'] =array();
$res = $this->squestion->add_remove_buttons($form_content);
$this->assertTrue($res);
//var_dump($res);
}
public function testRenderQuestion(){
$form_content=array('');
$res = $this->squestion->render_question($form_content);
$this->assertNull($res);
$this->assertTrue(is_null($res));
//var_dump($res);
}
public function testCreateForm1(){
$form_content=array('');
$this->syesno->create_form($form_content);
$this->assertNotNull($this->syesno->html);
}
public function testRenderQuestion1(){
ob_start();
$form_content['options']=array('');
$answers=array();
$this->syesno->render_question($form_content,$answers);
ob_end_clean();
$this->assertNotNull($this->syesno->html);
}
public function testCreateForm2(){
global $charset;
$form_content=array('');
$this->smultiplechoice->create_form($form_content);
$this->assertNotNull($this->smultiplechoice->html);
$this->assertTrue(!is_null(html));
}
/**
* @todo it would make more sense to consider yesno as a
* special case of multiplechoice and not the other way
* around
*/
public function testRenderQuestion2(){
$form_content= array('');
$answers=array('');
$this->smultiplechoice->render_question($form_content, $answers);
$this->assertNull($this->smultiplechoice->html);
}
public function testCreateForm3(){
$form_content['answers']=array();
$count= 0;
$this->spersonality;
$this->spersonality->create_form($form_content);
$this->assertNotNull($this->spersonality->html);
$this->assertTrue($this->spersonality->html);
}
public function testRenderQuestion3(){
$form_content=array();
$answers=array();
$this->spersonality->render_question($form_content,$answers);
$this->assertNull($this->spersonality->html);
$this->assertFalse($this->spersonality->html);
}
public function testCreateForm4(){
global $charset;
$form_content=array();
$this->smultipleresponse->create_form($form_content);
$this->assertNotNull($this->smultipleresponse->html);
$this->assertTrue($this->smultipleresponse->html);
}
/**
* This functon only is added to the end of the test and the end of the files in the all test.
*/
/* public function testDeleteCourse() {
global $cidReq;
$resu = CourseManager::delete_course($cidReq);
}*/
}
?>

@ -1,5 +1,6 @@
<?php
require_once(api_get_path(SYS_CODE_PATH).'user/userInfoLib.php');
require_once(api_get_path(LIBRARY_PATH).'course.lib.php');
class TestUserInfoLib extends UnitTestCase {
@ -71,20 +72,14 @@ class TestUserInfoLib extends UnitTestCase {
*/
function testget_cat_content() {
global $TBL_USERINFO_CONTENT, $TBL_USERINFO_DEF;
$userId=1;
$catId=1;
$sql = "SELECT 1";
$result = Database::query($sql,__FILE__,__LINE__);
$catContent = Database::fetch_array($result);
$res=get_cat_content($userId, $catId);
$this->assertTrue(is_array($catContent));
$this->assertTrue(is_bool($res));
//var_dump($res);
}
function testget_cat_def() {
global $TBL_USERINFO_DEF;
$catId=1;
$res=get_cat_def($catId);
$this->assertTrue(is_bool($res));
@ -92,14 +87,12 @@ class TestUserInfoLib extends UnitTestCase {
}
function testget_cat_def_list() {
global $TBL_USERINFO_DEF;
$res=get_cat_def_list();
$this->assertTrue(is_bool($res));
//var_dump($res);
}
function testget_course_user_info() {
global $TBL_USERINFO_CONTENT, $TBL_USERINFO_DEF;
$user_id=1;
$res=get_course_user_info($user_id);
$this->assertTrue(is_bool($res));
@ -115,7 +108,6 @@ class TestUserInfoLib extends UnitTestCase {
}
function testhtmlize() {
global $charset;
$phrase='test';
$res=htmlize($phrase);
$this->assertTrue(is_string($res));
@ -123,7 +115,6 @@ class TestUserInfoLib extends UnitTestCase {
}
function testmove_cat_rank() {
global $TBL_USERINFO_DEF;
$id=1;
$direction='up';
$res=move_cat_rank($id, $direction);
@ -132,7 +123,6 @@ class TestUserInfoLib extends UnitTestCase {
}
function testmove_cat_rank_by_rank() {
global $TBL_USERINFO_DEF;
$rank=5;
$direction='up';
$res=move_cat_rank_by_rank($rank, $direction);
@ -151,7 +141,6 @@ class TestUserInfoLib extends UnitTestCase {
* @return - bollean - TRUE if succeed, ELSE otherwise
*/
function testremove_cat_def() {
global $TBL_USERINFO_CONTENT, $TBL_USERINFO_DEF;
$id=1;
$res=remove_cat_def($id, $force = false);
if(!is_null($res))$this->assertTrue(is_bool($res));
@ -173,5 +162,13 @@ class TestUserInfoLib extends UnitTestCase {
$this->assertTrue(is_bool($res));
//var_dump($res);
}
/**
* This functon only is added to the end of the test and the end of the files in the all test.
*/
/*public function testDeleteCourse() {
global $cidReq;
$resu = CourseManager::delete_course($cidReq);
}*/
}
?>
Loading…
Cancel
Save