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__); $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 (); $users = array ();
$t = time(); $t = time();
while ($user = Database::fetch_row($res)) { while ($user = Database::fetch_row($res)) {

@ -224,8 +224,8 @@ class Blog {
public static function create_post ($title, $full_text, $file_comment, $blog_id) { public static function create_post ($title, $full_text, $file_comment, $blog_id) {
global $_user; global $_user;
global $_course; global $_course;
global $blog_table_attachment;
$blog_table_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
$upload_ok=true; $upload_ok=true;
$has_attachment=false; $has_attachment=false;
$current_date=date('Y-m-d H:i:s',time()); $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) 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); $blog_id = Database::escape_string($blog_id);
$comment_id = Database::escape_string($comment_id); $comment_id = Database::escape_string($comment_id);
$post_id = Database::escape_string($post_id); $post_id = Database::escape_string($post_id);
$row=array(); $row=array();
$where=''; $where='';
if (!empty ($post_id) && is_numeric($post_id)) if (!empty ($post_id) && is_numeric($post_id))
{ {
$where.=' AND post_id ="'.$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.'" '; $where.=' comment_id ="'.$comment_id.'" ';
} }
$sql = 'SELECT path, filename, comment FROM '. $blog_table_attachment.' WHERE blog_id ="'.intval($blog_id).'" '.$where; $sql = 'SELECT path, filename, comment FROM '. $blog_table_attachment.' WHERE blog_id ="'.intval($blog_id).'" '.$where;
$result=Database::query($sql, __FILE__, __LINE__); $result=Database::query($sql, __FILE__, __LINE__);
if (Database::num_rows($result)!=0) 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) 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); $blog_id = Database::escape_string($blog_id);
$comment_id = Database::escape_string($comment_id); $comment_id = Database::escape_string($comment_id);
$post_id = Database::escape_string($post_id); $post_id = Database::escape_string($post_id);

@ -152,6 +152,7 @@ function UpdateEmbed( e )
SetAttribute( e, 'type', 'application/x-shockwave-flash' ) ; SetAttribute( e, 'type', 'application/x-shockwave-flash' ) ;
SetAttribute( e, 'pluginspage', 'http://www.macromedia.com/go/getflashplayer' ) ; SetAttribute( e, 'pluginspage', 'http://www.macromedia.com/go/getflashplayer' ) ;
SetAttribute( e, 'allowfullscreen', 'true' ) ; SetAttribute( e, 'allowfullscreen', 'true' ) ;
SetAttribute( e, 'wmode', 'transparent' ) ;
if ( GetE( 'radioHigh' ).checked ) if ( GetE( 'radioHigh' ).checked )
{ {
SetAttribute( e, 'src', YoutubeSite + YoutubeId + HighQualityString ) ; 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_lesson_mode = '<?php echo $oItem->get_lesson_mode();?>';
olms.lms_item_launch_data = '<?php echo $oItem->get_launch_data();?>'; olms.lms_item_launch_data = '<?php echo $oItem->get_launch_data();?>';
olms.lms_item_core_exit = '<?php echo $oItem->get_core_exit();?>'; 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; olms.asset_timer = 0;
@ -197,13 +197,13 @@ olms.execute_stats=false;
// Initialize stuff when the page is loaded // 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[0]='<?php echo $oItem->get_id();?>';
olms.info_lms_item[1]='<?php echo $oItem->get_id();?>'; olms.info_lms_item[1]='<?php echo $oItem->get_id();?>';
$("#content_id").load( function(){ $("#content_id").load( function(){
olms.info_lms_item[0]=olms.info_lms_item[1]; olms.info_lms_item[0]=olms.info_lms_item[1];
if (olms.lms_item_types['i'+olms.info_lms_item[1]] != 'sco') { if (olms.lms_item_types['i'+olms.info_lms_item[1]] != 'sco') {
LMSInitialize(); LMSInitialize();
} }
@ -228,7 +228,7 @@ function LMSInitialize() { //this is the initialize function of all APIobjects
*/ */
olms.G_LastError = G_NoError ; olms.G_LastError = G_NoError ;
olms.G_LastErrorMessage = 'No error'; olms.G_LastErrorMessage = 'No error';
olms.lms_initialized=0; 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_user_id: '+olms.lms_user_id
+ '<br />lms_view_id: '+olms.lms_view_id + '<br />lms_view_id: '+olms.lms_view_id
; ;
logit_scorm('LMSInitialize()'+log,0); logit_scorm('LMSInitialize()'+log,0);
olms.lms_initialized=1; olms.lms_initialized=1;
<?php if (api_get_setting('show_glossary_in_documents') == 'ismanual') { ?> <?php if (api_get_setting('show_glossary_in_documents') == 'ismanual') { ?>
if (olms.lms_item_type == 'sco') { if (olms.lms_item_type == 'sco') {
attach_glossary_into_scorm('automatic'); attach_glossary_into_scorm('automatic');
} else { } else {
attach_glossary_into_scorm('manual'); attach_glossary_into_scorm('manual');
} }
<?php } elseif (api_get_setting('show_glossary_in_documents') == 'isautomatic') { ?> <?php } elseif (api_get_setting('show_glossary_in_documents') == 'isautomatic') { ?>
attach_glossary_into_scorm('automatic'); attach_glossary_into_scorm('automatic');
<? } ?> <?php } ?>
return('true'); return('true');
} }
} }
@ -820,10 +820,10 @@ function savedata(origin) {
olms.variable_to_send=new Array(); 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) * closing the current process)
* From SCORM 1.2 RTE: If the API Adapter is caching values received from the * 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 * SCO via an LMSSetValue(), this call requires that any values not yet
* persisted by the LMS be persisted. * persisted by the LMS be persisted.
* @param string Must be empty string for conformance with SCORM 1.2 * @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. * 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 * 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 * longer needs to communicate with the LMS, if it successfully called
* LMSInitialize at any previous point. This call signifies two things: * 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. * 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. * 2.The SCO has finished communicating with the LMS.
* @param string * @param string
*/ */
function LMSFinish(val) { function LMSFinish(val) {
olms.G_LastError = G_NoError ; olms.G_LastError = G_NoError ;
@ -925,7 +925,7 @@ function GetDiagnostic(errCode){
* Acts as a "commit" * Acts as a "commit"
* This function is not standard SCORM 1.2 and is probably deprecated in all * This function is not standard SCORM 1.2 and is probably deprecated in all
* meanings of the term. * 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() function Terminate()
{ {
@ -1277,7 +1277,7 @@ function switch_item(current_item, next_item){
var orig_lesson_status = olms.lesson_status; var orig_lesson_status = olms.lesson_status;
var orig_item_type = olms.lms_item_types['i'+current_item]; var orig_item_type = olms.lms_item_types['i'+current_item];
var next_item_type = olms.lms_item_types['i'+next_item]; var next_item_type = olms.lms_item_types['i'+next_item];
/* /*
There are four "cases" for switching items: There are four "cases" for switching items:
(1) asset switching to asset (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) We need to save, switching not necessary (LMSInitialize does the job)
(3) sco switching to asset (3) sco switching to asset
We need to switch the document in the content frame, but we cannot 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, 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 we need to load the new asset's context once the SCO has unloaded
(4) sco switching to sco (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 LMSInitialize on load will do the job
In any case, we need to change the current document frame. In any case, we need to change the current document frame.
These cases, although clear here, are however very difficult to implement 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); logit_lms('Called switch_item with params '+olms.lms_item_id+' and '+next_item+'',0);
if (orig_item_type != 'sco') { if (orig_item_type != 'sco') {
if (next_item_type != 'sco' ) { if (next_item_type != 'sco' ) {
//case 1 //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_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 { } else {
//case 2 //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_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 { } else {
if (next_item_type != 'sco') { if (next_item_type != 'sco') {
//case 3 //case 3
xajax_save_item_scorm(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, olms.lms_item_id); xajax_save_item_scorm(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, olms.lms_item_id);
reinit_updatable_vars_list(); 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 { } else {
//case 4 //case 4
xajax_save_item_scorm(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, olms.lms_item_id); 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); 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 //(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 || olms.lms_item_type=='asset' || olms.session_time == '0' || olms.session_time == '0:00:00') {
if (olms.lms_lp_type==1) { 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); xajax_save_objectives(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,olms.lms_item_id,olms.item_objectives);
} }
}else{ }else{
*/ */
/** /**
* Because of SCORM 1.2's special rule about unsent commits and the fact * 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 * 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; olms.execute_stats=false;
// Considering info_lms_item[0] is initially the oldest and info_lms_item[1] // 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, // 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 // 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 * 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 * Because of the need to pass an array, we have to build the parameters
* manually into GET[]. * manually into GET[].
* This function has a twin sister for SCO elements (xajax_save_item_scorm) * 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 * updatable_vars_list. Takes interactions into account and considers whether
* variables have been modified or not. * variables have been modified or not.
* @param int ID of the learning path * @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 * @param string automatic or manual values are allowed
*/ */
function attach_glossary_into_scorm(type) { function attach_glossary_into_scorm(type) {
var f = $('#content_id')[0]; var f = $('#content_id')[0];
//logit_lms('attach_glossary_into_scorm', 0); //logit_lms('attach_glossary_into_scorm', 0);
var doc = f.contentWindow ? f.contentWindow.document : 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 $frame_content = $('body',doc);
var my_text=$frame_content.html(); var my_text=$frame_content.html();
my_protocol = location.protocol; my_protocol = location.protocol;
my_pathname=location.pathname; my_pathname=location.pathname;
work_path = my_pathname.substr(0,my_pathname.indexOf('/courses/')); work_path = my_pathname.substr(0,my_pathname.indexOf('/courses/'));
if (type == 'automatic') { if (type == 'automatic') {
$.ajax({ $.ajax({
contentType: "application/x-www-form-urlencoded", contentType: "application/x-www-form-urlencoded",
beforeSend: function(object) { beforeSend: function(object) {
@ -1711,20 +1711,20 @@ function attach_glossary_into_scorm(type) {
if (datas.length==0) { if (datas.length==0) {
return false; return false;
} }
// glossary terms // glossary terms
data_terms=datas.split("[|.|_|.|-|.|]"); data_terms=datas.split("[|.|_|.|-|.|]");
var complex_array = new Array(); var complex_array = new Array();
var cp_complex_array = new Array(); var cp_complex_array = new Array();
for(i=0;i<data_terms.length;i++) { for(i=0;i<data_terms.length;i++) {
specific_terms=data_terms[i].split("__|__|"); 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 var real_code = specific_terms[0]; // glossary id
complex_array[real_code] = real_term; complex_array[real_code] = real_term;
cp_complex_array[real_code] = real_term; cp_complex_array[real_code] = real_term;
} }
complex_array.reverse(); complex_array.reverse();
for (var my_index in complex_array) { for (var my_index in complex_array) {
n = complex_array[my_index]; n = complex_array[my_index];
if (n == null) { if (n == null) {
@ -1742,12 +1742,12 @@ function attach_glossary_into_scorm(type) {
} }
//alert(n + ' ' + my_index); //alert(n + ' ' + my_index);
$("iframe").contents().find('body').removeHighlight().highlight(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(); var complex_array = new Array();
//mouse over event //mouse over event
$("iframe").contents().find("body .glossary-ajax").mouseover(function(){ $("iframe").contents().find("body .glossary-ajax").mouseover(function(){
random_id=Math.round(Math.random()*100); 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;"); $("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"); notebook_id=$(this).attr("name");
data_notebook=notebook_id.split("link"); data_notebook=notebook_id.split("link");
my_glossary_id=data_notebook[1]; my_glossary_id=data_notebook[1];
$.ajax({ $.ajax({
contentType: "application/x-www-form-urlencoded", contentType: "application/x-www-form-urlencoded",
@ -1772,7 +1772,7 @@ function attach_glossary_into_scorm(type) {
} }
}); });
}); });
//mouse out event //mouse out event
$("iframe").contents().find("body .glossary-ajax").mouseout(function(){ $("iframe").contents().find("body .glossary-ajax").mouseout(function(){
var current_element, var current_element,
@ -1780,12 +1780,12 @@ function attach_glossary_into_scorm(type) {
div_show_id=current_element.find("div").attr("id"); div_show_id=current_element.find("div").attr("id");
$("iframe").contents().find("div#"+div_show_id).remove(); $("iframe").contents().find("div#"+div_show_id).remove();
}); });
} }
}); });
} else { } else {
if ('manual') { if ('manual') {
$("iframe").contents().find("body .glossary").mouseover(function(){ $("iframe").contents().find("body .glossary").mouseover(function(){
is_glossary_name=$(this).html(); is_glossary_name=$(this).html();
random_id=Math.round(Math.random()*100); 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>"); $(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_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;"); $("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({ $.ajax({
contentType: "application/x-www-form-urlencoded", contentType: "application/x-www-form-urlencoded",
beforeSend: function(objeto) { beforeSend: function(objeto) {
@ -1811,7 +1811,7 @@ function attach_glossary_into_scorm(type) {
current_element=$(this); current_element=$(this);
div_show_id=current_element.find("div").attr("id"); div_show_id=current_element.find("div").attr("id");
$("iframe").contents().find("div#"+div_show_id).remove(); $("iframe").contents().find("div#"+div_show_id).remove();
}); });
} }
} }
} }

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

@ -125,7 +125,9 @@ function edit_cat_def($id, $title, $comment, $nbline)
function remove_cat_def($id, $force = false) 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)); $id = strval(intval($id));
if ( (0 == (int) $id || $id == "ALL") || ! is_bool($force)) 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. 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)); $id = strval(intval($id));
if ( 0 == (int) $id || ! ($direction == "up" || $direction == "down") ) 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. 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") ) 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) 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, $sql = "SELECT cat.id catId, cat.title,
cat.comment , content.content cat.comment , content.content
@ -524,8 +527,9 @@ function get_main_user_info($user_id, $courseCode)
function get_cat_content($userId, $catId) 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)); $userId = strval(intval($userId));
$catId = strval(intval($catId)); $catId = strval(intval($catId));
$sql = "SELECT cat.id catId, cat.title, $sql = "SELECT cat.id catId, cat.title,
@ -558,8 +562,8 @@ function get_cat_content($userId, $catId)
*/ */
function get_cat_def($catId) function get_cat_def($catId)
{ {
global $TBL_USERINFO_DEF; $TBL_USERINFO_DEF = Database :: get_course_table(TABLE_USER_INFO);
$catId = strval(intval($catId)); $catId = strval(intval($catId));
$sql = "SELECT id, title, comment, line_count, rank FROM ".$TBL_USERINFO_DEF." WHERE id = '$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() 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 $sql = "SELECT id catId, title, comment , line_count
FROM ".$TBL_USERINFO_DEF." FROM ".$TBL_USERINFO_DEF."
ORDER BY rank"; ORDER BY rank";

@ -8,6 +8,7 @@ require_once('simpletest/unit_tester.php');
require_once('simpletest/web_tester.php'); require_once('simpletest/web_tester.php');
require_once('simpletest/mock_objects.php'); require_once('simpletest/mock_objects.php');
require_once('simpletest/autorun.php'); require_once('simpletest/autorun.php');
require_once ('load_global.php');
require_once(dirname(__FILE__).'/../main/inc/global.inc.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/calendar.lib.php');
require_once(api_get_path(SYS_CODE_PATH).'admin/statistics/statistics.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).'/survey/survey.lib.php');
require_once(api_get_path(SYS_CODE_PATH).'/install/install_upgrade.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 { class AllTests2 extends TestSuite {
function AllTests2() { function AllTests2() {
$this->TestSuite('All tests2'); $this->TestSuite('All tests2');
$this->addTestFile(dirname(__FILE__).'/main/admin/calendar.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/admin/statistics/statistics.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/auth/lost_password.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/auth/openid/xrds.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/chat/chat_functions.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/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/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/user/userInfoLib.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/webservices/user_import/import.lib.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/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'); $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'); require_once(api_get_path(LIBRARY_PATH).'blog.lib.php');
ob_start(); ob_start();
require_once (api_get_path(INCLUDE_PATH).'lib/fckeditor/fckeditor.php'); 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'); //require_once(api_get_path(SYS_CODE_PATH).'permissions/blog_permissions.inc.php');
ob_end_clean(); ob_end_clean();
class TestBlog extends UnitTestCase class TestBlog extends UnitTestCase
{ {
@ -21,11 +21,50 @@ class TestBlog extends UnitTestCase
public function setUp() public function setUp()
{ {
$this-> oblog = new Blog(); $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() public function tearDown()
{ {
$this->oblog = null; $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 * Test about get Title to a Blog
*/ */
// EXCEPTION
public function testGetBlogTitle(){ public function testGetBlogTitle(){
$res = $this->oblog->get_Blog_title(11); $res = $this->oblog->get_Blog_title(11);
$this->assertFalse($this->oblog->get_Blog_title(11)===String); $this->assertFalse($this->oblog->get_Blog_title(11)===String);
$this->assertTrue(is_String($res)); $this->assertTrue(is_String($res));
} }
// EXCEPTION
public function testGetBlogSubtitle(){ public function testGetBlogSubtitle(){
$res = $this->oblog->get_Blog_subtitle(0); $res = $this->oblog->get_Blog_subtitle(0);
$this->assertFalse($this->oblog->get_Blog_subtitle(0)=== null); $this->assertFalse($this->oblog->get_Blog_subtitle(0)=== null);
$this->assertTrue(is_String($res)); $this->assertTrue(is_String($res));
$this->assertNotNull($res); $this->assertNotNull($res);
} }
// EXCEPTION
public function testGetBlogUsers(){ public function testGetBlogUsers(){
$res = $this->oblog->get_Blog_users(11); $res = $this->oblog->get_Blog_users(11);
$this->assertTrue($this->oblog->get_Blog_users(1110)===array()); $this->assertTrue($this->oblog->get_Blog_users(1110)===array());
$this->assertTrue(is_array($res)); $this->assertTrue(is_array($res));
} }
// EXCEPTION
public function testCreateBlog(){ public function testCreateBlog(){
global $_user; global $_user;
$res = $this->oblog->create_Blog('testingBlog','pass'); $res = $this->oblog->create_Blog('testingBlog','pass');
$this->assertTrue(is_null($res)); $this->assertTrue(is_null($res));
$this->assertNull($res); $this->assertNull($res);
$this->assertFalse($res); $this->assertFalse($res);
} }
// EXCEPTION
public function testEditBlog(){ public function testEditBlog(){
global $_user; global $_user;
$_user = array('Blog_id'=>1,'title'=>'TestBlog','subtitle'=>'testing'); $blog_id = 1;
$res = $this->oblog->edit_Blog($_user); $title = 'titulo1';
$subtitle = 'subtitulo1';
$res = $this->oblog->edit_Blog($blog_id, $title, $subtitle);
$this->assertNull($res); $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); $this->assertFalse($res);
} }
// EXCEPTION
public function testDeleteBlog(){ 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->assertTrue(is_null($res));
$this->assertNotNull($this->oblog->edit_Blog(1)===null);
$this->assertFalse(is_array($res)); $this->assertFalse(is_array($res));
} }
// EXCEPTION
public function testCreatePost(){ public function testCreatePost(){
global $_user, $_course, $Blog_table_attachment; global $_user, $_course;
$Blog_table_attachment = array('title' => 'xxxxtestxxxx', $title = 'xxxxtestxxxx';
'full_text'=>'xxxxx', $full_text = 'xxxxx';
'file_comment'=>'xxxxx', $file_comment = 'xxxxx';
'Blog_id'=>11 $blog_id = 1;
); $res = $this->oblog->create_post($title, $full_text, $file_comment, $blog_id);
$res = $this->oblog->create_post($Blog_table_attachment); $this->assertTrue($this->oblog->create_post($title, $full_text, $file_comment, $blog_id)=== null);
$this->assertTrue($this->oblog->create_post($Blog_table_attachment)=== null);
$this->assertNotNull(is_null,$res); $this->assertNotNull(is_null,$res);
$this->assertFalse($res); $this->assertFalse($res);
} }
// EXCEPTION
public function testEditPost(){ public function testEditPost(){
ob_start(); ob_start();
$post_id =3; $post_id =3;
@ -155,7 +191,7 @@ class TestBlog extends UnitTestCase
$this->assertTrue(is_null($res)); $this->assertTrue(is_null($res));
//var_dump($res); //var_dump($res);
} }
// EXCEPTION
public function testDeletePost(){ public function testDeletePost(){
$Blog_id = 11; $Blog_id = 11;
$post_id = 21; $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->assertNotNull($this->oblog->create_comment('tesingBlog','xxxxxxx','xxx',12,1,null)===null);
$this->assertTrue(is_null($res)); $this->assertTrue(is_null($res));
$this->assertFalse($res); $this->assertFalse($res);
} }
// EXCEPTION
public function testDeleteComment(){ public function testDeleteComment(){
$res = $this->oblog->delete_comment(11,12,2); $res = $this->oblog->delete_comment(11,12,2);
$this->assertNotNull($this->oblog->delete_comment(11,12,2)===null); $this->assertNotNull($this->oblog->delete_comment(11,12,2)===null);
@ -187,87 +222,100 @@ class TestBlog extends UnitTestCase
$this->assertTrue(is_null($res)); $this->assertTrue(is_null($res));
$this->assertFalse($res); $this->assertFalse($res);
$this->assertFalse(null,$res); $this->assertFalse(null,$res);
} }
// EXCEPTION
public function testEditTask() { 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(); //$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->assertTrue(is_null($res));
$this->assertFalse(is_string($res)); $this->assertFalse(is_string($res));
$this->assertNull($res); $this->assertNull($res);
} }
// EXCEPTION
public function testDeleteTask(){ public function testDeleteTask(){
$res = $this->oblog->delete_task(); $blog_id = 1;
$this->assertTrue($this->oblog->delete_task()===null); $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)); $this->assertTrue(is_null($res));
} }
public function testDeleteAssignedTask(){ public function testDeleteAssignedTask(){
$res = $this->oblog->delete_assigned_task(); $blog_id = 1;
$this->assertTrue($this->oblog->delete_assigned_task()===null); $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->assertNotNull(is_null($res));
$this->assertFalse($res); $this->assertFalse($res);
} }
public function testGetPersonalTaskList(){ public function testGetPersonalTaskList(){
global $_user; global $_user;
ob_start(); ob_start();
$res = Blog::get_personal_task_list('a'); $res = Blog::get_personal_task_list('a');
$this->assertEqual($this->oblog->get_personal_task_list(1)===1);
$this->assertFalse($res); $this->assertFalse($res);
ob_end_clean(); ob_end_clean();
} }
public function testChangeBlogVisibility(){ public function testChangeBlogVisibility(){
$res = $this->oblog->change_blog_visibility(); $blog_id = 1;
$this->assertTrue($this->oblog->change_blog_visibility()=== null); $res = $this->oblog->change_blog_visibility($blog_id);
$this->assertTrue($this->oblog->change_blog_visibility($blog_id)=== null);
$this->assertTrue(is_null($res)); $this->assertTrue(is_null($res));
} }
public function testDisplayBlogPosts(){ public function testDisplayBlogPosts(){
ob_start(); ob_start();
$res = $this->oblog->display_blog_posts(10,null,null); $blog_id = 1;
$this->assertTrue($this->oblog->display_blog_posts(10,null,null)=== null); $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->assertNull($res);
$this->assertTrue(is_null($res)); $this->assertTrue(is_null($res));
$this->assertFalse(null, $res); $this->assertFalse(null, $res);
ob_end_clean();
} }
public function testDisplaySearchResults(){ public function testDisplaySearchResults(){
ob_start(); ob_start();
$res = $this->oblog->display_search_results(11,null); $blog_id = 1;
$this->assertTrue($this->oblog->display_search_results(11,null)===null); $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(); ob_end_clean();
$this->assertTrue(is_null($res));
$this->assertNull($res);
} }
public function testDisplayDayResults(){ public function testDisplayDayResults(){
ob_start(); ob_start();
$res = $this->oblog->display_day_results(12,null); $blog_id = 1;
$this->assertTrue($this->oblog->display_day_results(12,null)===null); $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->assertFalse($res);
$this->assertNull(null,$res); $this->assertNull(null,$res);
ob_end_clean();
} }
public function testDisplayPost(){ public function testDisplayPost(){
ob_start(); ob_start();
$res = $this->oblog->display_post(12,11); $blog_id = 1;
$this->assertTrue($this->oblog->display_post(12,11)===null); $post_id = 2;
$this->assertFalse($res); $res = $this->oblog->display_post($blog_id, $post_id);
$this->assertTrue(is_null($res));
ob_end_clean(); ob_end_clean();
$this->assertTrue(is_null($res));
$this->assertFalse($res);
} }
public function testAddRating(){ public function testAddRating(){
@ -276,7 +324,6 @@ class TestBlog extends UnitTestCase
$this->assertFalse($this->oblog->add_rating(null,11,2,5)=== bool); $this->assertFalse($this->oblog->add_rating(null,11,2,5)=== bool);
$this->assertTrue(is_bool($res)); $this->assertTrue(is_bool($res));
$this->assertFalse(null,$res); $this->assertFalse(null,$res);
} }
public function testDisplayRating(){ public function testDisplayRating(){
@ -286,7 +333,6 @@ class TestBlog extends UnitTestCase
$this->assertTrue(is_numeric($res)); $this->assertTrue(is_numeric($res));
$this->assertFalse($res); $this->assertFalse($res);
ob_end_clean(); ob_end_clean();
} }
public function testDisplayRatingForm(){ public function testDisplayRatingForm(){
@ -295,43 +341,40 @@ class TestBlog extends UnitTestCase
$this->assertFalse($this->oblog->display_rating_form('xxx',11,1,null)===null); $this->assertFalse($this->oblog->display_rating_form('xxx',11,1,null)===null);
$this->assertTrue(is_string($res)); $this->assertTrue(is_string($res));
$this->assertNotNull($res,null); $this->assertNotNull($res,null);
} }
public function testGetThreadedComments(){ public function testGetThreadedComments(){
ob_start(); ob_start();
$current = 0;
$current_level = 0;
$blog_id = 1;
$post_id = 2;
$task_id = 0;
global $charset, $dataFormatLong; global $charset, $dataFormatLong;
$res = $this->oblog->get_threaded_comments(null,null,11,2,null); $res = $this->oblog->get_threaded_comments($current, $current_level, $blog_id, $post_id, $task_id);
$this->assertFalse($res);
$this->assertTrue($this->oblog->get_threaded_comments(null,null,11,2,null)===null);
ob_end_clean(); 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(){ public function testDisplayFormEditPost(){
ob_start(); 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->assertNotNull(is_null($res));
$this->assertFalse($res); $this->assertFalse($res);
ob_end_clean(); ob_end_clean();
//var_dump($res); //var_dump($res);
} }
public function testDisplayTaskList(){ public function testDisplayTaskList(){
@ -339,9 +382,8 @@ class TestBlog extends UnitTestCase
$res = $this->oblog->display_task_list(11); $res = $this->oblog->display_task_list(11);
$this->assertTrue($this->oblog->display_task_list(11)===null); $this->assertTrue($this->oblog->display_task_list(11)===null);
ob_end_clean(); ob_end_clean();
} }
// exceptions
public function testDisplayAssignedTaskList(){ public function testDisplayAssignedTaskList(){
ob_start(); ob_start();
global $charset, $color2; global $charset, $color2;
@ -349,7 +391,6 @@ class TestBlog extends UnitTestCase
$this->assertTrue($this->oblog->display_assigned_task_list(11)===null); $this->assertTrue($this->oblog->display_assigned_task_list(11)===null);
$this->assertFalse($res); $this->assertFalse($res);
ob_end_clean(); ob_end_clean();
} }
public function testDisplayNewTaskForm(){ public function testDisplayNewTaskForm(){
@ -360,7 +401,7 @@ class TestBlog extends UnitTestCase
ob_end_clean(); ob_end_clean();
} }
// exceptions /*
public function testDisplayEditTaskForm(){ public function testDisplayEditTaskForm(){
ob_start(); ob_start();
$res = $this->oblog->display_edit_task_form(11,12); $res = $this->oblog->display_edit_task_form(11,12);
@ -370,7 +411,7 @@ class TestBlog extends UnitTestCase
$this->assertFalse($res); $this->assertFalse($res);
} }
// exceptions
public function testDisplayAssignTaskForm(){ public function testDisplayAssignTaskForm(){
ob_start(); ob_start();
$res = $this->oblog->display_assign_task_form(11); $res = $this->oblog->display_assign_task_form(11);
@ -379,7 +420,7 @@ class TestBlog extends UnitTestCase
$this->assertTrue(is_null($res)); $this->assertTrue(is_null($res));
ob_end_clean(); ob_end_clean();
} }
// exceptions
public function testDisplayEditAssignedTaskForm(){ public function testDisplayEditAssignedTaskForm(){
global $MonthsLong; global $MonthsLong;
ob_start(); ob_start();
@ -389,7 +430,7 @@ class TestBlog extends UnitTestCase
$this->assertFalse($res); $this->assertFalse($res);
} }
// excetions
public function testAssignTask(){ public function testAssignTask(){
ob_start(); ob_start();
$res = $this->oblog->assign_task(11,1,12,null); $res = $this->oblog->assign_task(11,1,12,null);
@ -397,9 +438,8 @@ class TestBlog extends UnitTestCase
$this->assertFalse(is_numeric($res)); $this->assertFalse(is_numeric($res));
$this->assertNull(null,$res); $this->assertNull(null,$res);
ob_end_clean(); ob_end_clean();
} }
// exceptions
public function testEditAssignedTask(){ public function testEditAssignedTask(){
$task = array('blog_id'=>11, $task = array('blog_id'=>11,
'user_id'=>1, 'user_id'=>1,
@ -409,12 +449,11 @@ class TestBlog extends UnitTestCase
'old_task_id'=>11, 'old_task_id'=>11,
'old_target_date'=>'xxxzxxx' 'old_target_date'=>'xxxzxxx'
); );
$res = $this->oblog->edit_assigned_task(); $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->assertTrue($this->oblog->edit_assigned_task()===null); $this->assertNull($res);
$this->assertTrue(is_null($res)); $this->assertTrue(is_null($res));
} }
// EXCEPTIONS
public function testDisplaySelectTaskPost(){ public function testDisplaySelectTaskPost(){
ob_start(); ob_start();
$res = $this->oblog->display_select_task_post(11,12); $res = $this->oblog->display_select_task_post(11,12);
@ -422,25 +461,22 @@ class TestBlog extends UnitTestCase
$this->assertTrue(is_null($res)); $this->assertTrue(is_null($res));
$this->assertFalse($res); $this->assertFalse($res);
ob_end_clean(); ob_end_clean();
}
}
public function testSetUserSubscribed(){ public function testSetUserSubscribed(){
$res = $this->oblog->set_user_subscribed(11,12); $res = $this->oblog->set_user_subscribed(11,12);
$this->assertTrue($this->oblog->set_user_subscribed(11,12)===null); $this->assertTrue($this->oblog->set_user_subscribed(11,12)===null);
$this->assertFalse($res); $this->assertFalse($res);
$this->assertTrue(is_null($res)); $this->assertTrue(is_null($res));
}
}
public function testUserUnsubscribed(){ public function testUserUnsubscribed(){
$res = $this->oblog->set_user_unsubscribed(11,12); $res = $this->oblog->set_user_unsubscribed(11,12);
$this->assertTrue($this->oblog->set_user_unsubscribed(11,12)===null); $this->assertTrue($this->oblog->set_user_unsubscribed(11,12)===null);
$this->assertFalse($res); $this->assertFalse($res);
$this->assertTrue(is_null($res)); $this->assertTrue(is_null($res));
} }
// exception
public function testDisplayFormUserSubscribe(){ public function testDisplayFormUserSubscribe(){
ob_start(); ob_start();
$res = $this->oblog->display_form_user_subscribe(12); $res = $this->oblog->display_form_user_subscribe(12);
@ -448,31 +484,24 @@ class TestBlog extends UnitTestCase
$this->assertNotNull(is_null($res)); $this->assertNotNull(is_null($res));
$this->assertFalse($res); $this->assertFalse($res);
ob_end_clean(); ob_end_clean();
} }
/**
* this function have been tested modified the function /**
* display_form_user_unsubscribe in the blog.lib.php * this function have been tested modified the function
* main_table and course_table. * display_form_user_unsubscribe in the blog.lib.php
* * main_table and course_table.
*/ /* usando mocks *//* ERROR *
*/public function testDisplayFormUserUnsubscribe(){ */
public function testDisplayFormUserUnsubscribe(){
global $_user; global $_user;
ob_start(); ob_start();
$blog_id = '1'; $blog_id = '1';
$res = Blog::display_form_user_unsubscribe($blog_id); $res = Blog::display_form_user_unsubscribe($blog_id);
$this->assertTrue(($res)===false); $this->assertTrue(is_null($res));
$this->assertTrue(is_bool($res)); $this->assertNull($res);
ob_end_clean(); 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(){ public function testDisplayFormUserRights(){
@ -482,31 +511,30 @@ class TestBlog extends UnitTestCase
$this->assertFalse($res); $this->assertFalse($res);
ob_end_clean(); ob_end_clean();
} }
/* usando mocks ERROR */
public function testDisplayNewCommentForm(){ public function testDisplayNewCommentForm(){
$blog_id = '12'; $blog_id = '12';
$post_id='1'; $post_id='1';
$title='test'; $title='test';
ob_start(); ob_start();
$res =$this->oblog->display_new_comment_form($blog_id,$post_id,$title); $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->assertFalse($res);
$this->assertNotNull(is_null($res)); $this->assertNotNull(is_null($res));
ob_end_clean(); ob_end_clean();
//var_dump($res);
} }
// exception
public function testDisplayMinimonthcalendar(){ public function testDisplayMinimonthcalendar(){
global $_user,$DaysShort, $MonthsLong; global $_user,$DaysShort, $MonthsLong;
ob_start(); ob_start();
$res = $this->oblog->display_minimonthcalendar(); $month = 12;
$this->assertTrue($this->oblog->display_minimonthcalendar()=== null); $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)); $this->assertTrue(is_null($res));
ob_end_clean(); ob_end_clean();
} }
public function testDisplayNewBlogForm(){ public function testDisplayNewBlogForm(){
ob_start(); ob_start();
$res = $this->oblog->display_new_blog_form(); $res = $this->oblog->display_new_blog_form();
@ -514,16 +542,14 @@ class TestBlog extends UnitTestCase
$this->assertTrue(is_null($res)); $this->assertTrue(is_null($res));
$this->assertTrue($this->oblog->display_new_blog_form()===null); $this->assertTrue($this->oblog->display_new_blog_form()===null);
ob_end_clean(); ob_end_clean();
} }
// exception
public function testDisplayEditBlogForm(){ public function testDisplayEditBlogForm(){
ob_start(); ob_start();
$res = $this->oblog->display_edit_blog_form(12); $res = $this->oblog->display_edit_blog_form(12);
$this->assertTrue($this->oblog->display_edit_blog_form(12)===null); $this->assertTrue($this->oblog->display_edit_blog_form(12)===null);
$this->assertTrue(is_null($res)); $this->assertTrue(is_null($res));
ob_end_clean(); ob_end_clean();
} }
public function testDisplayBlogList(){ public function testDisplayBlogList(){
@ -533,37 +559,65 @@ class TestBlog extends UnitTestCase
$this->assertTrue(is_null($res)); $this->assertTrue(is_null($res));
ob_end_clean(); ob_end_clean();
} }
// EXCEPTION
public function testGetBlogAttachment(){ public function testGetBlogAttachment(){
ob_start(); ob_start();
global $blog_table_attachment; ob_end_clean();
$oblog_table_attachment = array('blog_id'=>12); global $_configuration;
$res=get_blog_attachment(); $blog_id = '0';
$post_id = null;
$comment_id = null;
$res = get_blog_attachment($blog_id, $post_id,$comment_id);
$this->assertFalse($res); $this->assertFalse($res);
$this->assertTrue(is_array($res)); $this->assertTrue(is_array($res));
ob_end_clean();
} }
// EXCEPTION
public function testDeleteAllBlogAttachment(){ public function testDeleteAllBlogAttachment(){
global $blog_table_attachment, $_course; global $_course,$_configuration;
$res = delete_all_blog_attachment(12,null,null); $blog_id = 1;
$post_id=null;
$comment_id=null;
$res = delete_all_blog_attachment($blog_id,$post_id,$comment_id);
$this->assertFalse($res); $this->assertFalse($res);
$this->assertNull($res); $this->assertNull($res);
}
}
// EXCEPTION
public function testGetBlogPostFromUser(){ 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->assertFalse($res);
$this->assertTrue(is_string($res)); $this->assertTrue(is_string($res));
} }
// EXCEPTION
public function testGetBlogCOmmentFromUser(){ public function testGetBlogCommentFromUser(){
$res = get_blog_comment_from_user('mate',2); 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->assertFalse($res);
$this->assertTrue(is_string($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 <?php
Mock::generate('Database'); require_once(api_get_path(LIBRARY_PATH).'course.lib.php');
Mock::generate('Display');
$config['survey']['debug'] = false;
require_once(api_get_path(LIBRARY_PATH).'add_course.lib.inc.php');
class TestSurvey extends UnitTestCase { class TestSurvey extends UnitTestCase {
@ -18,152 +14,169 @@ class TestSurvey extends UnitTestCase {
$this->UnitTestCase(''); $this->UnitTestCase('');
} }
public function setUp() { public function setUp() {
$this->smanager = new survey_manager(); $this->smanager = new survey_manager();
$this->squestion = new question(); $this->squestion = new question();
$this->syesno = new yesno(); $this->syesno = new yesno();
$this->smultiplechoice = new multiplechoice(); $this->smultiplechoice = new multiplechoice();
$this->spersonality = new personality(); $this->spersonality = new personality();
$this->smultipleresponse = new multipleresponse(); $this->smultipleresponse = new multipleresponse();
} }
public function tearDown() { public function tearDown() {
$this-> smanager = null; $this-> smanager = null;
$this-> squestion = null; $this-> squestion = null;
$this-> syesno = null; $this-> syesno = null;
$this->smultiplechoice = null; $this->smultiplechoice = null;
$this->personality = null; $this->personality = null;
$this->multipleresponse = null; $this->multipleresponse = null;
} }
public function testGetSurvey() {
$instans = new MockDatabase(); public function testStoreSurvey() {
global $_course; global $_user,$cidReq;
$survey_id=1; $values = array(
$shared=1; 'survey_code' => 'Survey1',
$my_course_id=$_GET['course']; 'survey_title' => '<p>Survey</p>',
$res = $this->smanager->get_survey($survey_id,$shared); 'survey_subtitle' => '',
$my_course_info=api_get_course_info($my_course_id); 'survey_language' => 'spanish',
$table_survey = Database :: get_course_table(TABLE_SURVEY, $my_course_info['dbName']); 'start_date' => '2010-01-19',
$sql = "SELECT * FROM $table_survey WHERE survey_id='".Database::escape_string($survey_id)."'"; 'end_date' => '2010-01-29',
$result = Database::query($sql, __FILE__, __LINE__); 'survey_introduction' => '',
$instans->expectCallCount($table_survey); 'survey_thanks' => '',
$this->assertTrue(is_array($res)); 'survey_type' => '0',
$this->assertFalse($result); 'parent_id' => '0',
//var_dump($table_survey); 'submit_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']))
$res = $this->smanager->store_survey($values); $res = $this->smanager->store_survey($values);
$this->assertTrue($res); $this->assertTrue($res);
$this->assertTrue(is_array($res)); $this->assertTrue(is_array($res));
$this->assertTrue($res);
$this->assertTrue($table_survey);
//var_dump($res);
//var_dump($table_survey);
} }
public function testStoreSharedSurvey($values){ public function testGetSurvey() {
$instans = new MockDatabase(); $course_code = 'COURSEX';
$values=array(''); $survey_id=1;
global $_user; $res3 = $this->smanager->get_survey($survey_id,0,$course_code);
global $_course; $this->assertTrue(is_array($res3));
$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') { public function testStoreSharedSurvey() {
$sql = "INSERT INTO $table_survey (code, title, subtitle, author, lang, template, intro, surveythanks, creation_date, course_code)"; global $_user,$cidReq;
$result = Database::query($sql, __FILE__, __LINE__); $values = array(
$return = Database::insert_id(); 'survey_code' => 'Survey1',
}else{ 'survey_title' => '<p>Survey</p>',
$sql = "UPDATE $table_survey SET"; 'survey_subtitle' => 'Survey subtitle',
$result = Database::query($sql, __FILE__, __LINE__); 'survey_language' => 'spanish',
$return = $values['survey_share']['survey_share']; '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); $res = $this->smanager->store_shared_survey($values);
$this->assertTrue($res); $this->assertTrue($res);
//var_dump($res); //var_dump($res);
//var_dump($table_survey);
//var_dump($table_survey);
} }
public function testDeleteSurvey(){ //Build the form
$instans = new MockDatabase();
$survey_id=1; public function testQuestionCreateForm() {
$shared=false; global $charset;
$course_code=001; global $survey_data;
$table_survey= Database :: get_course_table(TABLE_SURVEY,$course_code); $form_content = array();
$table_survey_question_group = Database :: get_course_table(TABLE_SURVEY_QUESTION_GROUP,$course_code); $res = $this->squestion->create_form($form_content);
$instans->expectOnce($table_survey);
$res = $this->smanager->delete_survey($survey_id, $shared, $course_code);
$this->assertTrue($res);
$this->assertTrue(is_string($res)); $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); //var_dump($res);
} }
public function testYesNoCreateForm() {
$form_content=array();
$res1 = $this->syesno->create_form($form_content);
$this->assertNull($res1);
}
public function testCopySurvey(){ public function testMultipleChoiceCreateForm() {
$instans = new MockDatabase(); $form_content=array();
$parent_survey=null; $res2 = $this->smultiplechoice->create_form($form_content);
$new_survey_id=null; $this->assertNull($res2);
$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__); public function testPersonalityCreateForm() {
$res = $this->smanager->copy_survey($parent_survey,$new_survey_id); $form_content=array();
$this->assertTrue(is_bool($res)); $this->spersonality->create_form($form_content);
$this->assertTrue($res); $this->assertNotNull($this->spersonality->html);
$this->assertTrue($instans); $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($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(){ public function testPersonalityRenderQuestion() {
$instans = new MockDatabase(); $form_content=array();
$table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION); $answers=array();
$table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER); $this->spersonality->render_question($form_content,$answers);
$table_survey = Database :: get_course_table(TABLE_SURVEY); $this->assertNull($this->spersonality->html);
$survey_id=null; $this->assertFalse($this->spersonality->html);
$instans->expectOnce($table_survey); }
$instans->expectCallCount(count($table_survey));
$instans->expectCallCount($table_survey); public function testAddRemoveButtons() {
$res = $this->smanager->empty_survey($survey_id); $form_content = array();
$res = $this->squestion->add_remove_buttons($form_content);
$this->assertTrue($res); $this->assertTrue($res);
$this->assertTrue(is_object($instans));
//var_dump($res); //var_dump($res);
//var_dump($table_survey);
} }
public function testUpdateSurveyAnswered(){ //save the survey
$instans = new MockDatabase();
global $_course; public function testCopySurvey() {
$survey_id=1; $parent_survey = Database::escape_string($parent_survey);
$user=001; $new_survey_id = '1';
$survey_code=001; $res = $this->smanager->copy_survey($parent_survey,$new_survey_id);
$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);
$this->assertTrue(is_bool($res)); $this->assertTrue(is_bool($res));
$this->assertTrue($res === false); $this->assertTrue($res);
//var_dump($result);
//var_dump($res); //var_dump($res);
} }
public function testGetCompleteSurveyStructure(){
public function testGetCompleteSurveyStructure() {
$survey_id=''; $survey_id='';
$shared=0; $shared=0;
$res = $this->smanager->get_complete_survey_structure($survey_id, $shared); $res = $this->smanager->get_complete_survey_structure($survey_id, $shared);
@ -172,7 +185,7 @@ class TestSurvey extends UnitTestCase {
//var_dump($res); //var_dump($res);
} }
public function testIconQuestion(){ public function testIconQuestion() {
$type='open'; $type='open';
$res = $this->smanager->icon_question($type); $res = $this->smanager->icon_question($type);
if(is_bool($res)) { if(is_bool($res)) {
@ -184,342 +197,179 @@ class TestSurvey extends UnitTestCase {
} }
//var_dump($res); //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(){ public function testSaveSharedQuestion() {
$instans = new MockDatabase(); $form_content=array('');
$question_id=01; $survey_data=array('survey_share');
$shared=false; $res = $this->smanager->save_shared_question($form_content,$survey_data);
$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);
$this->assertTrue($res); $this->assertTrue($res);
$instans->expectOnce(count($res));
//var_dump($res); //var_dump($res);
//var_dump($result);
} }
public function testGetQuestions(){ public function testSaveQuestionOptions() {
$get_questions = new MockDatabase(); $form_content=array();
$survey_id =1; $survey_data=array('survey_share');
$tbl_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION); $res = $this->smanager->save_question_options($form_content,$survey_data);
$table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION); $this->assertTrue(is_null($res));
$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);
//var_dump($res); //var_dump($res);
//var_dump($row);
//var_dump($get_questions);
} }
public function testSaveQuestion(){ public function testSaveSharedQuestionOptions() {
global $survey_data; $form_content=array();
global $_course; $survey_data=array();
$form_content=array('question'=>'121212'); $res = $this->smanager->save_shared_question_options($form_content,$survey_data);
$res = $this->smanager->save_question($form_content['question']); $this->assertTrue(is_null($res));
$this->assertTrue($res); $this->assertNull($res);
$this->assertTrue(is_string($res));
//var_dump($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(){ public function testGetQuestion() {
$instans = new MockDatabase(); $question_id=1;
global $_course; $res = $this->smanager->get_question($question_id,false);
$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);
$this->assertTrue($res); $this->assertTrue($res);
$this->assertTrue($instans);
//var_dump($res); //var_dump($res);
//var_dump($instans); //var_dump($result);
} }
public function testMoveSurveyQuestion(){ public function testGetQuestions() {
$instans = new MockDatabase(); $survey_id =1;
$table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION); $res= $this->smanager->get_questions($survey_id);
$this->assertNull($res);
//var_dump($res);
}
//move the survey
public function testMoveSurveyQuestion() {
$direction='moveup'; $direction='moveup';
$survey_question_id=01; $survey_question_id=1;
$survey_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); $res = $this->smanager->move_survey_question($direction,$survey_question_id,$survey_id);
$this->assertTrue(is_null($res)); $this->assertTrue(is_null($res));
//var_dump($res); //var_dump($res);
} }
public function testDeleteAllSurveyQuestions(){ //epmty the survey
$instans = new MockDatabase();
$table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION); 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; $survey_id=1;
$shared=false; $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); $result = $this->smanager->delete_all_survey_questions($survey_id,$shared);
$instans->expectOnce($res);
$this->assertTrue(is_null($result)); $this->assertTrue(is_null($result));
$this->assertTrue(is_bool($res));
$this->assertTrue($res === true || $res === false);
//var_dump($result); //var_dump($result);
//var_dump($res);
} }
public function testDeleteSurveyQuestion(){ public function testDeleteSurveyQuestion() {
$instans = new MockDatabase();
$table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
$survey_id =1; $survey_id =1;
$question_id=01; $question_id=01;
$shared=false; $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); $result = $this->smanager->delete_survey_question($survey_id,$question_id);
$this->assertTrue(is_null($result)); $this->assertTrue(is_null($result));
$this->assertTrue(is_object($instans));
$this->assertFalse($res);
//var_dump($result); //var_dump($result);
//var_dump($res); //var_dump($res);
} }
public function testDeleteSharedSurveyQuestion(){ public function testDeleteSharedSurveyQuestion() {
$instans = new MockDatabase();
$survey_id=1; $survey_id=1;
$question_id=01; $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); $res = $this->smanager->delete_shared_survey_question($survey_id,$question_id);
$instans->expectOnce($table_survey_question);
$this->assertTrue(is_null($res)); $this->assertTrue(is_null($res));
$this->assertTrue(is_object($instans));
//var_dump($res); //var_dump($res);
} }
public function testSaveQuestionOptions(){ public function testDeleteSurvey() {
$instans = new MockDatabase(); $survey_id=1;
$form_content=array('percentage'); $shared=false;
$survey_data=array('survey_share'); $course_code=001;
$table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION); $res = $this->smanager->delete_survey($survey_id, $shared, $course_code);
$instans->expectOnce($table_survey_question_option); $this->assertTrue($res);
$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);
//var_dump($res); //var_dump($res);
//var_dump($result);
} }
public function testDeleteAllSurveyQuestionsOptions(){ public function testDeleteAllSurveyQuestionsOptions() {
$instans = new MockDatabase();
$table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
$survey_id=1; $survey_id=1;
$shared=false; $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); $result = $this->smanager->delete_all_survey_questions_options($survey_id,$shared);
$instans->expectCallCount($res);
$this->assertTrue($result); $this->assertTrue($result);
$this->assertFalse($res);
$this->assertTrue(is_bool($res));
//var_dump($result); //var_dump($result);
//var_dump($res);
} }
public function testDeleteSurveyQuestionOption(){ public function testDeleteSurveyQuestionOption() {
$instans = new MockDatabase();
$survey_id=1; $survey_id=1;
$question_id=01; $question_id=01;
$shared=false; $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); $result = $this->smanager->delete_survey_question_option($survey_id,$question_id,$shared);
if(is_bool($result)) if(is_bool($result))
$this->assertTrue(is_bool($result)); $this->assertTrue(is_bool($result));
$this->assertTrue($result === true || $result===false); $this->assertTrue($result === true || $result===false);
$this->assertTrue($result); $this->assertTrue($result);
if(is_bool($res))
$this->assertTrue(is_bool($res));
$this->assertTrue($res === true || $res===false);
$this->assertFalse($res);
//var_dump($result); //var_dump($result);
//var_dump($res);
} }
public function testDeleteAllSurveyAnswers(){ public function testDeleteAllSurveyAnswers() {
$instans = new MockDatabase();
$survey_id=1; $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); $res = $this->smanager->delete_all_survey_answers($survey_id);
$this->assertTrue(is_bool($res)); $this->assertTrue(is_bool($res));
$this->assertTrue($res); $this->assertTrue($res);
$this->assertTrue($res === true || $res === false); $this->assertTrue($res === true || $res === false);
$this->assertTrue($table_survey_answer);
//var_dump($res); //var_dump($res);
//var_dump($table_survey_answer);
} }
public function testGetPeopleWhoFilledSurvey(){ //Contest the answer
$instans = new MockDatabase();
$survey_id=1; public function testUpdateSurveyAnswered() {
$all_user_info=false; global $user;
global $_course; $survey_code = 'Survey1';
$table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER, $_course['db_name']); $survey_id = '1';
$table_user = Database :: get_main_table('user'); $result = $this->smanager->update_survey_answered($survey_id, $user, $survey_code);
$survey_data = survey_manager::get_survey($survey_id); $this->assertTrue(is_null($result));
$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);
//var_dump($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 <?php
require_once(api_get_path(SYS_CODE_PATH).'user/userInfoLib.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 { class TestUserInfoLib extends UnitTestCase {
@ -71,20 +72,14 @@ class TestUserInfoLib extends UnitTestCase {
*/ */
function testget_cat_content() { function testget_cat_content() {
global $TBL_USERINFO_CONTENT, $TBL_USERINFO_DEF;
$userId=1; $userId=1;
$catId=1; $catId=1;
$sql = "SELECT 1";
$result = Database::query($sql,__FILE__,__LINE__);
$catContent = Database::fetch_array($result);
$res=get_cat_content($userId, $catId); $res=get_cat_content($userId, $catId);
$this->assertTrue(is_array($catContent));
$this->assertTrue(is_bool($res)); $this->assertTrue(is_bool($res));
//var_dump($res); //var_dump($res);
} }
function testget_cat_def() { function testget_cat_def() {
global $TBL_USERINFO_DEF;
$catId=1; $catId=1;
$res=get_cat_def($catId); $res=get_cat_def($catId);
$this->assertTrue(is_bool($res)); $this->assertTrue(is_bool($res));
@ -92,14 +87,12 @@ class TestUserInfoLib extends UnitTestCase {
} }
function testget_cat_def_list() { function testget_cat_def_list() {
global $TBL_USERINFO_DEF;
$res=get_cat_def_list(); $res=get_cat_def_list();
$this->assertTrue(is_bool($res)); $this->assertTrue(is_bool($res));
//var_dump($res); //var_dump($res);
} }
function testget_course_user_info() { function testget_course_user_info() {
global $TBL_USERINFO_CONTENT, $TBL_USERINFO_DEF;
$user_id=1; $user_id=1;
$res=get_course_user_info($user_id); $res=get_course_user_info($user_id);
$this->assertTrue(is_bool($res)); $this->assertTrue(is_bool($res));
@ -115,7 +108,6 @@ class TestUserInfoLib extends UnitTestCase {
} }
function testhtmlize() { function testhtmlize() {
global $charset;
$phrase='test'; $phrase='test';
$res=htmlize($phrase); $res=htmlize($phrase);
$this->assertTrue(is_string($res)); $this->assertTrue(is_string($res));
@ -123,7 +115,6 @@ class TestUserInfoLib extends UnitTestCase {
} }
function testmove_cat_rank() { function testmove_cat_rank() {
global $TBL_USERINFO_DEF;
$id=1; $id=1;
$direction='up'; $direction='up';
$res=move_cat_rank($id, $direction); $res=move_cat_rank($id, $direction);
@ -132,7 +123,6 @@ class TestUserInfoLib extends UnitTestCase {
} }
function testmove_cat_rank_by_rank() { function testmove_cat_rank_by_rank() {
global $TBL_USERINFO_DEF;
$rank=5; $rank=5;
$direction='up'; $direction='up';
$res=move_cat_rank_by_rank($rank, $direction); $res=move_cat_rank_by_rank($rank, $direction);
@ -151,7 +141,6 @@ class TestUserInfoLib extends UnitTestCase {
* @return - bollean - TRUE if succeed, ELSE otherwise * @return - bollean - TRUE if succeed, ELSE otherwise
*/ */
function testremove_cat_def() { function testremove_cat_def() {
global $TBL_USERINFO_CONTENT, $TBL_USERINFO_DEF;
$id=1; $id=1;
$res=remove_cat_def($id, $force = false); $res=remove_cat_def($id, $force = false);
if(!is_null($res))$this->assertTrue(is_bool($res)); if(!is_null($res))$this->assertTrue(is_bool($res));
@ -173,5 +162,13 @@ class TestUserInfoLib extends UnitTestCase {
$this->assertTrue(is_bool($res)); $this->assertTrue(is_bool($res));
//var_dump($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