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

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

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

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

@ -180,7 +180,7 @@ olms.lms_item_credit = '<?php echo $oItem->get_credit();?>';
olms.lms_item_lesson_mode = '<?php echo $oItem->get_lesson_mode();?>';
olms.lms_item_launch_data = '<?php echo $oItem->get_launch_data();?>';
olms.lms_item_core_exit = '<?php echo $oItem->get_core_exit();?>';
<?php echo $oLP->get_items_details_as_js('olms.lms_item_types')?>
<?php echo $oLP->get_items_details_as_js('olms.lms_item_types');?>
olms.asset_timer = 0;
@ -284,7 +284,7 @@ function LMSInitialize() { //this is the initialize function of all APIobjects
}
<?php } elseif (api_get_setting('show_glossary_in_documents') == 'isautomatic') { ?>
attach_glossary_into_scorm('automatic');
<? } ?>
<?php } ?>
return('true');
}
}

@ -1686,6 +1686,8 @@ class yesno extends question
*/
function render_question($form_content, $answers=array())
{
if (is_array($form_content['options'])) { // check if data is correct
foreach ($form_content['options'] as $key=>$value)
{
$this->html .= '<label><input name="question'.$form_content['question_id'].'" type="radio" value="'.$key.'"';
@ -1705,6 +1707,7 @@ class yesno extends question
$this->html .= '/>'.$value.'</label>';
}
}
}
echo '<div class="survey_question_wrapper">';
echo '<div class="survey_question">'.$form_content['survey_question'].'</div>';
echo '<div class="survey_question_options">';
@ -1756,6 +1759,7 @@ class multiplechoice extends question
$this->html .= ' <div class="formw">';
$total_number_of_answers = count($form_content['answers']);
$this->html .= ' <table>';
if (is_array($form_content['answers'])) { // check if data is correct
foreach ($form_content['answers'] as $key=>$value) {
$this->html .= ' <tr>';
$this->html .= ' <td align="right"><label for="answers['.$key.']">'.($key+1).'</label></td>';
@ -1774,6 +1778,7 @@ class multiplechoice extends question
$this->html .= ' </td>';
$this->html .= ' </tr>';
}
}
// The buttons for adding or removing
$this->html .= ' </table>';
$this->html .= ' </div>';
@ -1849,15 +1854,14 @@ class personality extends question
$question_values=array();
// 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.'" />';
}
}
$count=0;
foreach ($form_content['answers'] as $key=>$value)
{
if(is_array($form_content['answers'])) {
foreach ($form_content['answers'] as $key=>$value) {
$this->html .= ' <tr>';
$this->html .= ' <td align="right"><label for="answers['.$key.']">'.($key+1).'</label></td>';
//$this->html .= ' <td><input type="text" name="answers['.$key.']" id="answers['.$key.']" value="'.$form_content['answers'][$key].'" /></td>';
@ -1885,7 +1889,7 @@ class personality extends question
$this->html .= ' </tr>';
$count++;
}
}
// The buttons for adding or removing
//$this->html .= parent :: add_remove_buttons($form_content);
}
@ -1949,6 +1953,7 @@ class multipleresponse extends question
$this->html .= ' <div class="formw">';
$total_number_of_answers = count($form_content['answers']);
$this->html .= ' <table>';
if(is_array($form_content['answers'])) { // values of question options
foreach ($form_content['answers'] as $key=>$value) {
$this->html .= ' <tr>';
$this->html .= ' <td align="right"><label for="answers['.$key.']">'.($key+1).'</label></td>';
@ -1969,6 +1974,7 @@ class multipleresponse extends question
$this->html .= ' </td>';
$this->html .= ' </tr>';
}
}
// The buttons for adding or removing
$this->html .= ' </table>';
$this->html .= ' </div>';

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

@ -8,6 +8,7 @@ require_once('simpletest/unit_tester.php');
require_once('simpletest/web_tester.php');
require_once('simpletest/mock_objects.php');
require_once('simpletest/autorun.php');
require_once ('load_global.php');
require_once(dirname(__FILE__).'/../main/inc/global.inc.php');
require_once(api_get_path(SYS_CODE_PATH).'admin/calendar.lib.php');
require_once(api_get_path(SYS_CODE_PATH).'admin/statistics/statistics.lib.php');
@ -15,26 +16,24 @@ require_once(api_get_path(LIBRARY_PATH).'usermanager.lib.php');
require_once(api_get_path(SYS_CODE_PATH).'/survey/survey.lib.php');
require_once(api_get_path(SYS_CODE_PATH).'/install/install_upgrade.lib.php');
$_SESSION['_user']['user_id'] = 1;
$_user= 1;
class AllTests2 extends TestSuite {
function AllTests2() {
$this->TestSuite('All tests2');
$this->addTestFile(dirname(__FILE__).'/main/admin/calendar.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/admin/statistics/statistics.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/auth/lost_password.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/auth/openid/xrds.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/chat/chat_functions.lib.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/admin/calendar.lib.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/admin/statistics/statistics.lib.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/auth/lost_password.lib.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/auth/openid/xrds.lib.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/chat/chat_functions.lib.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/conference/get_translation.lib.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/exercice/hotpotatoes.lib.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/newscorm/scorm.lib.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/install/install_upgrade.lib.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/survey/survey.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/survey/survey.lib.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/user/userInfoLib.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/webservices/user_import/import.lib.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/work/work.lib.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/install/install_upgrade.lib.test.php');
/*
$this->addTestFile(dirname(__FILE__).'/main/admin/calendar.lib.test.php');

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

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

@ -1,9 +1,5 @@
<?php
Mock::generate('Database');
Mock::generate('Display');
$config['survey']['debug'] = false;
require_once(api_get_path(LIBRARY_PATH).'add_course.lib.inc.php');
require_once(api_get_path(LIBRARY_PATH).'course.lib.php');
class TestSurvey extends UnitTestCase {
@ -36,134 +32,151 @@ class TestSurvey extends UnitTestCase {
$this->multipleresponse = null;
}
public function testGetSurvey() {
$instans = new MockDatabase();
global $_course;
$survey_id=1;
$shared=1;
$my_course_id=$_GET['course'];
$res = $this->smanager->get_survey($survey_id,$shared);
$my_course_info=api_get_course_info($my_course_id);
$table_survey = Database :: get_course_table(TABLE_SURVEY, $my_course_info['dbName']);
$sql = "SELECT * FROM $table_survey WHERE survey_id='".Database::escape_string($survey_id)."'";
$result = Database::query($sql, __FILE__, __LINE__);
$instans->expectCallCount($table_survey);
$this->assertTrue(is_array($res));
$this->assertFalse($result);
//var_dump($table_survey);
//var_dump($result);
//var_dump($res);
}
public function testStoreSurvey(){
$instans = new MockDatabase();
global $_user;
$values=array('002','003','003');
$table_survey=Database::get_course_table(TABLE_SURVEY);
$shared_survey_id=0;
$instans->expectCallCount($table_survey);
//if(!$values['survey_id'] OR !is_numeric($values['survey_id']))
public function testStoreSurvey() {
global $_user,$cidReq;
$values = array(
'survey_code' => 'Survey1',
'survey_title' => '<p>Survey</p>',
'survey_subtitle' => '',
'survey_language' => 'spanish',
'start_date' => '2010-01-19',
'end_date' => '2010-01-29',
'survey_introduction' => '',
'survey_thanks' => '',
'survey_type' => '0',
'parent_id' => '0',
'submit_survey' => ''
);
$res = $this->smanager->store_survey($values);
$this->assertTrue($res);
$this->assertTrue(is_array($res));
$this->assertTrue($res);
$this->assertTrue($table_survey);
//var_dump($res);
//var_dump($table_survey);
}
public function testStoreSharedSurvey($values){
$instans = new MockDatabase();
$values=array('');
global $_user;
global $_course;
$table_survey=Database::get_main_table(TABLE_MAIN_SHARED_SURVEY);
$instans->expectCallCount(Database::get_main_table(TABLE_MAIN_SHARED_SURVEY));
if(!$values['survey_id'] OR !is_numeric($values['survey_id']) OR $values['survey_share']['survey_share'] == 'true') {
$sql = "INSERT INTO $table_survey (code, title, subtitle, author, lang, template, intro, surveythanks, creation_date, course_code)";
$result = Database::query($sql, __FILE__, __LINE__);
$return = Database::insert_id();
}else{
$sql = "UPDATE $table_survey SET";
$result = Database::query($sql, __FILE__, __LINE__);
$return = $values['survey_share']['survey_share'];
}
public function testGetSurvey() {
$course_code = 'COURSEX';
$survey_id=1;
$res3 = $this->smanager->get_survey($survey_id,0,$course_code);
$this->assertTrue(is_array($res3));
}
public function testStoreSharedSurvey() {
global $_user,$cidReq;
$values = array(
'survey_code' => 'Survey1',
'survey_title' => '<p>Survey</p>',
'survey_subtitle' => 'Survey subtitle',
'survey_language' => 'spanish',
'start_date' => '2010-01-19',
'end_date' => '2010-01-29',
'survey_introduction' => 'introduction',
'survey_thanks' => '',
'survey_type' => '1',
'parent_id' => '1',
'submit_survey' => ''
);
$res = $this->smanager->store_shared_survey($values);
$this->assertTrue($res);
//var_dump($res);
//var_dump($table_survey);
//var_dump($table_survey);
}
public function testDeleteSurvey(){
$instans = new MockDatabase();
$survey_id=1;
$shared=false;
$course_code=001;
$table_survey= Database :: get_course_table(TABLE_SURVEY,$course_code);
$table_survey_question_group = Database :: get_course_table(TABLE_SURVEY_QUESTION_GROUP,$course_code);
$instans->expectOnce($table_survey);
$res = $this->smanager->delete_survey($survey_id, $shared, $course_code);
$this->assertTrue($res);
//Build the form
public function testQuestionCreateForm() {
global $charset;
global $survey_data;
$form_content = array();
$res = $this->squestion->create_form($form_content);
$this->assertTrue(is_string($res));
$this->assertTrue($table_survey);
//var_dump($table_survey_question_group);
}
public function testQuestionRenderForm() {
ob_start();
$this->squestion->render_form();
ob_end_clean();
$this->assertNotNull($this->squestion->html);
//var_dump($res);
}
public function testCopySurvey(){
$instans = new MockDatabase();
$parent_survey=null;
$new_survey_id=null;
$instans->expectCallCount(Database::get_course_table(TABLE_SURVEY));
$sql = "SELECT * from $table_survey_question_group " .
"WHERE survey_id='".$parent_survey."'";
$result = Database::query($sql, __FILE__, __LINE__);
$res = $this->smanager->copy_survey($parent_survey,$new_survey_id);
$this->assertTrue(is_bool($res));
$this->assertTrue($res);
$this->assertTrue($instans);
public function testYesNoCreateForm() {
$form_content=array();
$res1 = $this->syesno->create_form($form_content);
$this->assertNull($res1);
}
public function testMultipleChoiceCreateForm() {
$form_content=array();
$res2 = $this->smultiplechoice->create_form($form_content);
$this->assertNull($res2);
}
public function testPersonalityCreateForm() {
$form_content=array();
$this->spersonality->create_form($form_content);
$this->assertNotNull($this->spersonality->html);
$this->assertTrue($this->spersonality->html);
}
public function testMultipleResponseCreateForm() {
$form_content=array();
$this->smultipleresponse->create_form($form_content);
$this->assertNotNull($this->smultipleresponse->html);
$this->assertTrue($this->smultipleresponse->html);
}
public function testQuestionRenderQuestion() {
$form_content=array();
$res = $this->squestion->render_question($form_content);
$this->assertNull($res);
$this->assertTrue(is_null($res));
//var_dump($res);
//var_dump($result);
}
public function testEmpty_survey(){
$instans = new MockDatabase();
$table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION);
$table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER);
$table_survey = Database :: get_course_table(TABLE_SURVEY);
$survey_id=null;
$instans->expectOnce($table_survey);
$instans->expectCallCount(count($table_survey));
$instans->expectCallCount($table_survey);
$res = $this->smanager->empty_survey($survey_id);
public function 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 testPersonalityRenderQuestion() {
$form_content=array();
$answers=array();
$this->spersonality->render_question($form_content,$answers);
$this->assertNull($this->spersonality->html);
$this->assertFalse($this->spersonality->html);
}
public function testAddRemoveButtons() {
$form_content = array();
$res = $this->squestion->add_remove_buttons($form_content);
$this->assertTrue($res);
$this->assertTrue(is_object($instans));
//var_dump($res);
//var_dump($table_survey);
}
public function testUpdateSurveyAnswered(){
$instans = new MockDatabase();
global $_course;
$survey_id=1;
$user=001;
$survey_code=001;
$table_survey= Database :: get_course_table(TABLE_SURVEY, $_course['db_name']);
$table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION, $_course['db_name']);
$instans->expectCallCount($table_survey);
$instans->expectCallCount(count($table_survey_invitation));
$sql = "UPDATE $table_survey_invitation SET answered='1' WHERE session_id='".api_get_session_id()."' AND user='".Database::escape_string($user)."' AND survey_code='".Database::escape_string($survey_code)."'";
$res = Database::query($sql, __FILE__, __LINE__);
$result = $this->smanager->update_survey_answered($survey_id, $user, $survey_code);
//save the survey
public function testCopySurvey() {
$parent_survey = Database::escape_string($parent_survey);
$new_survey_id = '1';
$res = $this->smanager->copy_survey($parent_survey,$new_survey_id);
$this->assertTrue(is_bool($res));
$this->assertTrue($res === false);
//var_dump($result);
$this->assertTrue($res);
//var_dump($res);
}
public function testGetCompleteSurveyStructure(){
public function testGetCompleteSurveyStructure() {
$survey_id='';
$shared=0;
$res = $this->smanager->get_complete_survey_structure($survey_id, $shared);
@ -172,7 +185,7 @@ class TestSurvey extends UnitTestCase {
//var_dump($res);
}
public function testIconQuestion(){
public function testIconQuestion() {
$type='open';
$res = $this->smanager->icon_question($type);
if(is_bool($res)) {
@ -185,340 +198,177 @@ class TestSurvey extends UnitTestCase {
//var_dump($res);
}
public function testGetQuestion(){
$instans = new MockDatabase();
$question_id=01;
$shared=false;
$tbl_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
$table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
$sql = "SELECT * FROM $tbl_survey_question WHERE question_id='".Database::escape_string($question_id)."' ORDER BY `sort`";
$result = Database::query($sql, __FILE__, __LINE__);
$row = Database::fetch_array($result,'ASSOC');
$res = $this->smanager->get_question($question_id,$shared);
public function testSaveQuestion() {
$form_content=array();
$res = $this->smanager->save_question($form_content);
$this->assertTrue($res);
$instans->expectOnce(count($res));
$this->assertTrue(is_string($res));
//var_dump($res);
//var_dump($result);
}
public function testGetQuestions(){
$get_questions = new MockDatabase();
$survey_id =1;
$tbl_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
$table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
$sql = "SELECT * FROM $tbl_survey_question WHERE survey_id='".Database::escape_string($survey_id)."'";
$result = Database::query($sql, __FILE__, __LINE__);
$row = Database::fetch_array($result,'ASSOC');
$res= $this->smanager->get_questions($survey_id);
$get_questions->expectCallCount($result);
$this->assertNull($res);
public function testSaveSharedQuestion() {
$form_content=array('');
$survey_data=array('survey_share');
$res = $this->smanager->save_shared_question($form_content,$survey_data);
$this->assertTrue($res);
//var_dump($res);
//var_dump($row);
//var_dump($get_questions);
}
public function testSaveQuestion(){
global $survey_data;
global $_course;
$form_content=array('question'=>'121212');
$res = $this->smanager->save_question($form_content['question']);
$this->assertTrue($res);
$this->assertTrue(is_string($res));
public function testSaveQuestionOptions() {
$form_content=array();
$survey_data=array('survey_share');
$res = $this->smanager->save_question_options($form_content,$survey_data);
$this->assertTrue(is_null($res));
//var_dump($res);
}
public function testSaveSharedQuestionOptions() {
$form_content=array();
$survey_data=array();
$res = $this->smanager->save_shared_question_options($form_content,$survey_data);
$this->assertTrue(is_null($res));
$this->assertNull($res);
//var_dump($res);
}
public function testSaveSharedQuestion(){
$instans = new MockDatabase();
global $_course;
$form_content=array('');
$survey_data=array('');
$tbl_survey_question= Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION);
$res = $this->smanager->save_shared_question($form_content,$survey_data);
$instans->expectOnce($tbl_survey_question);
//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 testGetQuestion() {
$question_id=1;
$res = $this->smanager->get_question($question_id,false);
$this->assertTrue($res);
$this->assertTrue($instans);
//var_dump($res);
//var_dump($instans);
//var_dump($result);
}
public function testMoveSurveyQuestion(){
$instans = new MockDatabase();
$table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
public function testGetQuestions() {
$survey_id =1;
$res= $this->smanager->get_questions($survey_id);
$this->assertNull($res);
//var_dump($res);
}
//move the survey
public function testMoveSurveyQuestion() {
$direction='moveup';
$survey_question_id=01;
$survey_question_id=1;
$survey_id=1;
/*$sql = "SELECT * FROM $table_survey_question WHERE survey_id='".Database::escape_string($survey_id)."' ORDER BY sort $sort";
$result = Database::query($sql, __FILE__, __LINE__);
*/
$res = $this->smanager->move_survey_question($direction,$survey_question_id,$survey_id);
$this->assertTrue(is_null($res));
//var_dump($res);
}
public function testDeleteAllSurveyQuestions(){
$instans = new MockDatabase();
$table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
//epmty the survey
public function testEmpty_survey() {
$survey_id=null;
$res = $this->smanager->empty_survey($survey_id);
$this->assertTrue($res);
//var_dump($res);
}
//functions delete
public function testHandleAction() {
$form_content = array('');
$res = $this->squestion->handle_action($form_content);
$this->assertTrue(is_array($res));
//var_dump($res);
}
public function testDeleteAllSurveyQuestions() {
$survey_id=1;
$shared=false;
$sql = "DELETE from $table_survey_question WHERE survey_id='".Database::escape_string($survey_id)."'";
$res = Database::query($sql, __FILE__, __LINE__);
$result = $this->smanager->delete_all_survey_questions($survey_id,$shared);
$instans->expectOnce($res);
$this->assertTrue(is_null($result));
$this->assertTrue(is_bool($res));
$this->assertTrue($res === true || $res === false);
//var_dump($result);
//var_dump($res);
}
public function testDeleteSurveyQuestion(){
$instans = new MockDatabase();
$table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
public function testDeleteSurveyQuestion() {
$survey_id =1;
$question_id=01;
$shared=false;
$sql = "DELETE from $table_survey_question WHERE survey_id='".Database::escape_string($survey_id)."' AND question_id='".Database::escape_string($question_id)."'";
$res = Database::query($sql, __FILE__, __LINE__);
$instans->expectOnce($res);
$result = $this->smanager->delete_survey_question($survey_id,$question_id);
$this->assertTrue(is_null($result));
$this->assertTrue(is_object($instans));
$this->assertFalse($res);
//var_dump($result);
//var_dump($res);
}
public function testDeleteSharedSurveyQuestion(){
$instans = new MockDatabase();
public function testDeleteSharedSurveyQuestion() {
$survey_id=1;
$question_id=01;
$table_survey_question = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION);
$table_survey_question_option = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION_OPTION);
$res = $this->smanager->delete_shared_survey_question($survey_id,$question_id);
$instans->expectOnce($table_survey_question);
$this->assertTrue(is_null($res));
$this->assertTrue(is_object($instans));
//var_dump($res);
}
public function testSaveQuestionOptions(){
$instans = new MockDatabase();
$form_content=array('percentage');
$survey_data=array('survey_share');
$table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
$instans->expectOnce($table_survey_question_option);
$res = $this->smanager->save_question_options($form_content,$survey_data);
$this->assertTrue(is_null($res));
$this->assertTrue(is_object($instans));
//var_dump($res);
//var_dump($table_survey_question_option);
}
public function testSaveSharedQuestionOptions(){
$instans = new MockDatabase();
$form_content=array('answers');
$survey_data=array('');
$table_survey_question_option = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION_OPTION);
$sql = "DELETE FROM $table_survey_question_option WHERE question_id = '".Database::escape_string($form_content['shared_question_id'])."'";
$result = Database::query($sql, __FILE__, __LINE__);
$instans->expectCallCount($result);
$res = $this->smanager->save_shared_question_options($form_content,$survey_data);
$this->assertTrue(is_bool($result));
$this->assertTrue($result === true || $result === false);
$this->assertTrue(is_null($res));
$this->assertNull($res);
public function testDeleteSurvey() {
$survey_id=1;
$shared=false;
$course_code=001;
$res = $this->smanager->delete_survey($survey_id, $shared, $course_code);
$this->assertTrue($res);
//var_dump($res);
//var_dump($result);
}
public function testDeleteAllSurveyQuestionsOptions(){
$instans = new MockDatabase();
$table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
public function testDeleteAllSurveyQuestionsOptions() {
$survey_id=1;
$shared=false;
$sql = "DELETE from $table_survey_question_option WHERE survey_id='".Database::escape_string($survey_id)."'";
$res = Database::query($sql, __FILE__, __LINE__);
$result = $this->smanager->delete_all_survey_questions_options($survey_id,$shared);
$instans->expectCallCount($res);
$this->assertTrue($result);
$this->assertFalse($res);
$this->assertTrue(is_bool($res));
//var_dump($result);
//var_dump($res);
}
public function testDeleteSurveyQuestionOption(){
$instans = new MockDatabase();
public function testDeleteSurveyQuestionOption() {
$survey_id=1;
$question_id=01;
$shared=false;
$table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
$sql = "DELETE from $table_survey_question_option WHERE survey_id='".Database::escape_string($survey_id)."' AND question_id='".Database::escape_string($question_id)."'";
$res = Database::query($sql, __FILE__, __LINE__);
$instans->expectOnce($res);
$instans->expectCallCount($res);
$result = $this->smanager->delete_survey_question_option($survey_id,$question_id,$shared);
if(is_bool($result))
$this->assertTrue(is_bool($result));
$this->assertTrue($result === true || $result===false);
$this->assertTrue($result);
if(is_bool($res))
$this->assertTrue(is_bool($res));
$this->assertTrue($res === true || $res===false);
$this->assertFalse($res);
//var_dump($result);
//var_dump($res);
}
public function testDeleteAllSurveyAnswers(){
$instans = new MockDatabase();
public function testDeleteAllSurveyAnswers() {
$survey_id=1;
$table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER);
$instans->expectCallCount($table_survey_answer);
$res = $this->smanager->delete_all_survey_answers($survey_id);
$this->assertTrue(is_bool($res));
$this->assertTrue($res);
$this->assertTrue($res === true || $res === false);
$this->assertTrue($table_survey_answer);
//var_dump($res);
//var_dump($table_survey_answer);
}
public function testGetPeopleWhoFilledSurvey(){
$instans = new MockDatabase();
$survey_id=1;
$all_user_info=false;
global $_course;
$table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER, $_course['db_name']);
$table_user = Database :: get_main_table('user');
$survey_data = survey_manager::get_survey($survey_id);
$sql = "SELECT DISTINCT user FROM $table_survey_answer WHERE survey_id= '".Database::escape_string($survey_data['survey_id'])."'";
$res = Database::query($sql, __FILE__, __LINE__);
$instans->expectCallCount($table_user);
$result = $this->smanager->get_people_who_filled_survey($survey_id,$all_user_info);
$this->assertTrue(is_array($result));
$this->assertNotNull($res);
$this->assertFalse($res);
$this->assertTrue(is_bool($res));
$this->assertTrue($res=== true || $res === false);
$this->assertTrue($sql);
//var_dump($res);
//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);
}
//Contest the answer
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 testUpdateSurveyAnswered() {
global $user;
$survey_code = 'Survey1';
$survey_id = '1';
$result = $this->smanager->update_survey_answered($survey_id, $user, $survey_code);
$this->assertTrue(is_null($result));
//var_dump($result);
}
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
/**
* This functon only is added to the end of the test and the end of the files in the all test.
*/
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);
}
/* public function testDeleteCourse() {
global $cidReq;
$resu = CourseManager::delete_course($cidReq);
}*/
}

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