fixed files, this files have exceptions when are run tests

skala
Ricardo Rodriguez 15 years ago
parent 7d3af900eb
commit 2db99f58ff
  1. 39
      main/inc/lib/fileDisplay.lib.php
  2. 185
      main/inc/lib/fileManage.lib.php
  3. 290
      main/inc/lib/fileUpload.lib.php
  4. 7
      main/inc/lib/geometry.lib.php
  5. 1
      main/inc/lib/groupmanager.lib.php
  6. 32
      tests/main/admin/sub_language.class.test.php
  7. 33
      tests/main/inc/lib/add_course.lib.inc.test.php
  8. 81
      tests/main/inc/lib/blog.lib.test.php
  9. 174
      tests/main/inc/lib/course.lib.test.php
  10. 4
      tests/main/inc/lib/database.lib.test.php
  11. 10
      tests/main/inc/lib/display.lib.test.php
  12. 56
      tests/main/inc/lib/document.lib.test.php
  13. 205
      tests/main/inc/lib/fileManage.lib.test.php
  14. 6
      tests/main/inc/lib/fileUpload.lib.test.php
  15. 77
      tests/main/inc/lib/geometry.lib.test.php
  16. 205
      tests/main/inc/lib/groupmanager.lib.test.php

@ -201,27 +201,30 @@ function format_url($file_path)
*/
function recent_modified_file_time($dir_name, $do_recursive = true)
{
$dir = dir($dir_name);
$last_modified = 0;
while(($entry = $dir->read()) !== false)
{
if ($entry != '.' && $entry != '..')
continue;
if (!is_dir($dir_name.'/'.$entry))
$current_modified = filemtime($dir_name.'/'.$entry);
elseif ($do_recursive)
$current_modified = recent_modified_file_time($dir_name.'/'.$entry, true);
if ($current_modified > $last_modified)
$last_modified = $current_modified;
$return = 0;
if (is_dir($dir)) {
while(($entry = $dir->read()) !== false)
{
if ($entry != '.' && $entry != '..')
continue;
if (!is_dir($dir_name.'/'.$entry))
$current_modified = filemtime($dir_name.'/'.$entry);
elseif ($do_recursive)
$current_modified = recent_modified_file_time($dir_name.'/'.$entry, true);
if ($current_modified > $last_modified)
$last_modified = $current_modified;
}
$dir->close();
//prevents returning 0 (for empty directories)
$return = ($last_modified == 0) ? filemtime($dir_name) : $last_modified;
}
$dir->close();
//prevents returning 0 (for empty directories)
return ($last_modified == 0) ? filemtime($dir_name) : $last_modified;
return $return;
}
/**

@ -343,49 +343,51 @@ function copyDirTo($origDirPath, $destination, $move=true)
$save_dir=getcwd();
// extract directory name - create it at destination - update destination trail
$dirName = basename($origDirPath);
mkdir ($destination."/".$dirName, 0775);
$destinationTrail = $destination."/".$dirName;
chdir ($origDirPath) ;
$handle = opendir($origDirPath);
while ($element = readdir($handle) )
{
if ( $element == "." || $element == "..")
{
continue; // skip the current and parent directories
}
elseif ( is_file($element) )
if(is_dir($dirName)){
mkdir ($destination."/".$dirName, 0775);
$destinationTrail = $destination."/".$dirName;
if(is_dir($destination)){
chdir ($origDirPath) ;
$handle = opendir($origDirPath);
while ($element = readdir($handle) )
{
copy($element, $destinationTrail."/".$element);
if($move)
if ( $element == "." || $element == "..")
{
unlink($element) ;
continue; // skip the current and parent directories
}
elseif ( is_file($element) )
{
copy($element, $destinationTrail."/".$element);
if($move)
{
unlink($element) ;
}
}
elseif ( is_dir($element) )
{
$dirToCopy[] = $origDirPath."/".$element;
}
}
elseif ( is_dir($element) )
closedir($handle) ;
if ( sizeof($dirToCopy) > 0)
{
$dirToCopy[] = $origDirPath."/".$element;
foreach($dirToCopy as $thisDir)
{
copyDirTo($thisDir, $destinationTrail, $move); // recursivity
}
}
}
closedir($handle) ;
if ( sizeof($dirToCopy) > 0)
{
foreach($dirToCopy as $thisDir)
if($move)
{
copyDirTo($thisDir, $destinationTrail, $move); // recursivity
rmdir ($origDirPath) ;
}
}
if($move)
{
rmdir ($origDirPath) ;
}
chdir($save_dir);
chdir($save_dir);
}
}
}
//------------------------------------------------------------------------------
@ -408,10 +410,12 @@ function copyDirTo($origDirPath, $destination, $move=true)
function index_dir($path)
{
$save_dir = getcwd();
chdir($path);
$handle = opendir($path);
// reads directory content end record subdirectoies names in $dir_array
while ($element = readdir($handle) )
{
@ -434,6 +438,7 @@ function index_dir($path)
chdir($save_dir) ;
return $dirArray ;
}
@ -477,7 +482,6 @@ function form_dir_list($sourceType, $sourceComponent, $command, $baseWorkDir)
{
$dirList = index_and_sort_dir($baseWorkDir);
$dialogBox .= "<form action=\"".api_get_self()."\" method=\"post\">\n" ;
$dialogBox .= "<input type=\"hidden\" name=\"".$sourceType."\" value=\"".$sourceComponent."\">\n" ;
$dialogBox .= get_lang('Move').' '.$sourceComponent.' '.get_lang('To');
@ -487,7 +491,6 @@ function form_dir_list($sourceType, $sourceComponent, $command, $baseWorkDir)
$bwdLen = strlen($baseWorkDir) ; // base directories lenght, used under
/* build html form inputs */
if ($dirList)
{
while (list( , $pathValue) = each($dirList) )
@ -666,32 +669,36 @@ class FileManager
---------------------------------------------------------------
*/
function list_all_directories($path)
{
$save_dir = getcwd();
chdir($path);
$handle = opendir($path);
while ($element = readdir($handle) )
{
if ( $element == "." || $element == "..") continue; // skip the current and parent directories
if ( is_dir($element) )
{
$dirArray[] = $path."/".$element;
{
$resultArray = array();
if (is_dir($path)) {
$save_dir = getcwd();
chdir($path);
$handle = opendir($path);
while ($element = readdir($handle) )
{
if ( $element == "." || $element == "..") continue; // skip the current and parent directories
if ( is_dir($element) )
{
$dirArray[] = $path."/".$element;
}
}
}
closedir($handle) ;
// recursive operation if subdirectories exist
$dirNumber = sizeof($dirArray);
if ( $dirNumber > 0 )
{
for ($i = 0 ; $i < $dirNumber ; $i++ )
closedir($handle);
// recursive operation if subdirectories exist
$dirNumber = sizeof($dirArray);
if ( $dirNumber > 0 )
{
$subDirArray = FileManager::list_all_directories( $dirArray[$i] ) ; // function recursivity
$dirArray = array_merge( $dirArray , $subDirArray ) ; // data merge
for ($i = 0 ; $i < $dirNumber ; $i++ )
{
$subDirArray = FileManager::list_all_directories($dirArray[$i]) ; // function recursivity
if (is_array($dirArray) && is_array($subDirArray)) {
$dirArray = array_merge( $dirArray , $subDirArray ) ; // data merge
}
}
}
}
$resultArray = $dirArray;
chdir($save_dir) ;
$resultArray = $dirArray;
chdir($save_dir) ;
}
return $resultArray ;
}
@ -706,26 +713,32 @@ class FileManager
===============================================================
*/
function list_all_files($dirArray)
{
$save_dir = getcwd();
foreach ($dirArray as $directory)
{
$elementArray = array();
if(is_dir($dirArray))
{
chdir($directory);
$handle = opendir($directory);
while ($element = readdir($handle) )
$save_dir = getcwd();
foreach ($dirArray as $directory)
{
if ( $element == "." || $element == ".." || $element == '.htaccess') continue; // skip the current and parent directories
if ( ! is_dir($element) )
{
$elementArray[] = $directory."/".$element;
}
chdir($directory);
$handle = opendir($directory);
while ($element = readdir($handle) )
{
if ( $element == "." || $element == ".." || $element == '.htaccess') continue; // skip the current and parent directories
if ( ! is_dir($element) )
{
$elementArray[] = $directory."/".$element;
}
}
closedir($handle) ;
chdir("..") ;
chdir($save_dir);
}
closedir($handle) ;
chdir("..") ;
}
chdir($save_dir);
}
return $elementArray;
}
@ -736,12 +749,17 @@ class FileManager
Function is binary safe (is needed on Windows)
*/
function compat_load_file($file_name)
{
$fp = fopen($file_name, "rb");
$buffer = fread ($fp, filesize ($file_name));
fclose ($fp);
//api_display_debug_info(htmlentities($buffer));
{
$buffer = '';
if(file_exists($file_name))
{
$fp = fopen($file_name, "rb");
$buffer = fread ($fp, filesize ($file_name));
fclose ($fp);
//api_display_debug_info(htmlentities($buffer));
}
return $buffer;
}
@ -782,9 +800,8 @@ class FileManager
$sql_query = "SELECT count(*) as number_existing FROM $glued_table WHERE path='$full_file_name'";
//api_display_debug_info($sql_query);
$sql_result = Database::query($sql_query,__FILE__,__LINE__);
$sql_result = Database::query($sql_query,__FILE__,__LINE__);
$result = Database::fetch_array($sql_result);
//determine which query to execute
if( $result["number_existing"] > 0 )
{

@ -116,7 +116,7 @@ function htaccess2txt($filename)
* @see htaccess2txt()
*/
function disable_dangerous_file($filename)
{
{
$filename = php2phps($filename);
$filename = htaccess2txt($filename);
return $filename;
@ -491,7 +491,8 @@ function enough_space($file_size, $max_dir_space)
*/
function dir_total_space($dirPath)
{
{
$save_dir = getcwd();
chdir ($dirPath) ;
$handle = opendir($dirPath);
@ -709,7 +710,7 @@ function treat_uploaded_file($uploadedFile, $baseWorkDir, $uploadPath, $maxFille
$fileName = add_ext_on_mime($fileName,$uploadedFile['type']);
// HANDLE PHP FILES
$fileName = php2phps($fileName);
$fileName = ($fileName);
// COPY THE FILE TO THE DESIRED DESTINATION
if(move_uploaded_file($uploadedFile['tmp_name'], $baseWorkDir.$uploadPath."/".$fileName))
@ -734,124 +735,124 @@ function treat_uploaded_file($uploadedFile, $baseWorkDir, $uploadPath, $maxFille
*/
function unzip_uploaded_file($uploadedFile, $uploadPath, $baseWorkDir, $maxFilledSpace)
{
{
$zipFile = new pclZip($uploadedFile['tmp_name']);
// Check the zip content (real size and file extension)
$zipContentArray = $zipFile->listContent();
$okScorm=false;
foreach($zipContentArray as $thisContent)
{
if ( preg_match('~.(php.*|phtml)$~i', $thisContent['filename']) )
if(file_exists($uploadedFile)) {
$zipContentArray = $zipFile->listContent();
$okScorm=false;
foreach($zipContentArray as $thisContent)
{
return api_failure::set_failure('php_file_in_zip_file');
if ( preg_match('~.(php.*|phtml)$~i', $thisContent['filename']) )
{
return api_failure::set_failure('php_file_in_zip_file');
}
elseif(stristr($thisContent['filename'],'imsmanifest.xml'))
{
$okScorm=true;
}
elseif(stristr($thisContent['filename'],'LMS'))
{
$okPlantynScorm1=true;
}
elseif(stristr($thisContent['filename'],'REF'))
{
$okPlantynScorm2=true;
}
elseif(stristr($thisContent['filename'],'SCO'))
{
$okPlantynScorm3=true;
}
elseif(stristr($thisContent['filename'],'AICC'))
{
$okAiccScorm=true;
}
$realFileSize += $thisContent['size'];
}
elseif(stristr($thisContent['filename'],'imsmanifest.xml'))
if ((($okPlantynScorm1==true) and ($okPlantynScorm2==true) and ($okPlantynScorm3==true)) or ($okAiccScorm==true))
{
$okScorm=true;
}
elseif(stristr($thisContent['filename'],'LMS'))
if(!$okScorm && defined('CHECK_FOR_SCORM') && CHECK_FOR_SCORM)
{
$okPlantynScorm1=true;
return api_failure::set_failure('not_scorm_content');
}
elseif(stristr($thisContent['filename'],'REF'))
if (! enough_size($realFileSize, $baseWorkDir, $maxFilledSpace) )
{
$okPlantynScorm2=true;
return api_failure::set_failure('not_enough_space');
}
elseif(stristr($thisContent['filename'],'SCO'))
// it happens on Linux that $uploadPath sometimes doesn't start with '/'
if($uploadPath[0] != '/')
{
$okPlantynScorm3=true;
$uploadPath='/'.$uploadPath;
}
elseif(stristr($thisContent['filename'],'AICC'))
if($uploadPath[strlen($uploadPath)-1] == '/')
{
$okAiccScorm=true;
$uploadPath=substr($uploadPath,0,-1);
}
$realFileSize += $thisContent['size'];
}
if ((($okPlantynScorm1==true) and ($okPlantynScorm2==true) and ($okPlantynScorm3==true)) or ($okAiccScorm==true))
{
$okScorm=true;
}
if(!$okScorm && defined('CHECK_FOR_SCORM') && CHECK_FOR_SCORM)
{
return api_failure::set_failure('not_scorm_content');
}
if (! enough_size($realFileSize, $baseWorkDir, $maxFilledSpace) )
{
return api_failure::set_failure('not_enough_space');
}
// it happens on Linux that $uploadPath sometimes doesn't start with '/'
if($uploadPath[0] != '/')
{
$uploadPath='/'.$uploadPath;
}
if($uploadPath[strlen($uploadPath)-1] == '/')
{
$uploadPath=substr($uploadPath,0,-1);
}
/*
--------------------------------------
Uncompressing phase
--------------------------------------
*/
/*
The first version, using OS unzip, is not used anymore
because it does not return enough information.
We need to process each individual file in the zip archive to
- add it to the database
- parse & change relative html links
*/
if (PHP_OS == 'Linux' && ! get_cfg_var('safe_mode') && false) // *** UGent, changed by OC ***
{
// Shell Method - if this is possible, it gains some speed
exec("unzip -d \"".$baseWorkDir.$uploadPath."/\"".$uploadedFile['name']." "
.$uploadedFile['tmp_name']);
}
else
{
// PHP method - slower...
$save_dir = getcwd();
chdir($baseWorkDir.$uploadPath);
$unzippingState = $zipFile->extract();
for($j=0;$j<count($unzippingState);$j++)
/*
--------------------------------------
Uncompressing phase
--------------------------------------
*/
/*
The first version, using OS unzip, is not used anymore
because it does not return enough information.
We need to process each individual file in the zip archive to
- add it to the database
- parse & change relative html links
*/
if (PHP_OS == 'Linux' && ! get_cfg_var('safe_mode') && false) // *** UGent, changed by OC ***
{
$state=$unzippingState[$j];
//fix relative links in html files
$extension = strrchr($state["stored_filename"], ".");
// Shell Method - if this is possible, it gains some speed
exec("unzip -d \"".$baseWorkDir.$uploadPath."/\"".$uploadedFile['name']." "
.$uploadedFile['tmp_name']);
}
if($dir=@opendir($baseWorkDir.$uploadPath))
else
{
while($file=readdir($dir))
// PHP method - slower...
$save_dir = getcwd();
chdir($baseWorkDir.$uploadPath);
$unzippingState = $zipFile->extract();
for($j=0;$j<count($unzippingState);$j++)
{
$state=$unzippingState[$j];
//fix relative links in html files
$extension = strrchr($state["stored_filename"], ".");
}
if($dir=@opendir($baseWorkDir.$uploadPath))
{
if($file != '.' && $file != '..')
while($file=readdir($dir))
{
$filetype="file";
if(is_dir($baseWorkDir.$uploadPath.'/'.$file)) $filetype="folder";
$safe_file=replace_dangerous_char($file,'strict');
@rename($baseWorkDir.$uploadPath.'/'.$file,$baseWorkDir.$uploadPath.'/'.$safe_file);
set_default_settings($uploadPath,$safe_file,$filetype);
if($file != '.' && $file != '..')
{
$filetype="file";
if(is_dir($baseWorkDir.$uploadPath.'/'.$file)) $filetype="folder";
$safe_file=replace_dangerous_char($file,'strict');
@rename($baseWorkDir.$uploadPath.'/'.$file,$baseWorkDir.$uploadPath.'/'.$safe_file);
set_default_settings($uploadPath,$safe_file,$filetype);
}
}
closedir($dir);
}
closedir($dir);
chdir($save_dir); //back to previous dir position
}
chdir($save_dir); //back to previous dir position
}
return true;
@ -1395,7 +1396,7 @@ function create_unexisting_directory($_course,$user_id,$to_group_id,$to_user_id,
$perm = api_get_setting('permissions_for_new_directories');
$perm = octdec(!empty($perm)?$perm:'0770');
if (mkdir($base_work_dir.$desired_dir_name.$nb,$perm,true))
{
{
$document_id = add_document($_course, $desired_dir_name.$nb,'folder',0,$title);
if ($document_id)
{
@ -1545,15 +1546,17 @@ function create_link_file($filePath, $url)
function api_replace_links_in_html($upload_path, $full_file_name)
{
//Open the file
$fp = fopen($full_file_name, "r");
$buffer = fread ($fp, filesize ($full_file_name));
//Parse the contents
$new_html_content = api_replace_links_in_string($upload_path, $buffer);
//Write the result
$fp = fopen($full_file_name, "w");
fwrite($fp, $new_html_content);
if(file_exists($full_file_name)){
$fp = fopen($full_file_name, "r");
$buffer = fread ($fp, filesize ($full_file_name));
//Parse the contents
$new_html_content = api_replace_links_in_string($upload_path, $buffer);
//Write the result
$fp = fopen($full_file_name, "w");
fwrite($fp, $new_html_content);
}
}
//------------------------------------------------------------------------------
@ -1852,46 +1855,47 @@ $current_session_id = api_get_session_id();
$path = $base_work_dir.$current_path;
//open dir
$handle=opendir($path);
if(is_dir($path)){
//run trough
while($file=readdir($handle))
{
if ($file=='.' || $file=='..') continue;
$completepath="$path/$file";
//directory?
if (is_dir($completepath))
{
$title=get_document_title($file);
$safe_file=replace_dangerous_char($file);
@rename($path.'/'.$file, $path.'/'.$safe_file);
//if we can't find the file, add it
if(!DocumentManager::get_document_id($_course, $current_path.'/'.$safe_file))
{
$document_id=add_document($_course,$current_path.'/'.$safe_file,'folder',0,$title);
api_item_property_update($_course,TOOL_DOCUMENT,$document_id,'DocumentAdded',$user_id, $to_group_id,null,null,null,$current_session_id);
//echo $current_path.'/'.$safe_file." added!<br/>";
}
//recursive
add_all_documents_in_folder_to_database($_course,$user_id,$base_work_dir,$current_path.'/'.$safe_file, $to_group_id);
}
//file!
else
while($file=readdir($handle))
{
//rename
$safe_file=disable_dangerous_file(replace_dangerous_char($file, 'strict'));
@rename($base_work_dir.$current_path.'/'.$file,$base_work_dir.$current_path.'/'.$safe_file);
if ($file=='.' || $file=='..') continue;
$completepath="$path/$file";
//directory?
if (is_dir($completepath))
{
$title=get_document_title($file);
$safe_file=replace_dangerous_char($file);
@rename($path.'/'.$file, $path.'/'.$safe_file);
//if we can't find the file, add it
if(!DocumentManager::get_document_id($_course, $current_path.'/'.$safe_file))
{
$title=get_document_title($file);
$size = filesize($base_work_dir.$current_path.'/'.$safe_file);
$document_id = add_document($_course,$current_path.'/'.$safe_file,'file',$size,$title);
api_item_property_update($_course,TOOL_DOCUMENT,$document_id,'DocumentAdded',$user_id,$to_group_id,null,null,null,$current_session_id);
//echo $current_path.'/'.$safe_file." added!<br/>";
$document_id=add_document($_course,$current_path.'/'.$safe_file,'folder',0,$title);
api_item_property_update($_course,TOOL_DOCUMENT,$document_id,'DocumentAdded',$user_id, $to_group_id,null,null,null,$current_session_id);
//echo $current_path.'/'.$safe_file." added!<br/>";
}
}
//recursive
add_all_documents_in_folder_to_database($_course,$user_id,$base_work_dir,$current_path.'/'.$safe_file, $to_group_id);
}
//file!
else
{
//rename
$safe_file=disable_dangerous_file(replace_dangerous_char($file, 'strict'));
@rename($base_work_dir.$current_path.'/'.$file,$base_work_dir.$current_path.'/'.$safe_file);
if(!DocumentManager::get_document_id($_course, $current_path.'/'.$safe_file))
{
$title=get_document_title($file);
$size = filesize($base_work_dir.$current_path.'/'.$safe_file);
$document_id = add_document($_course,$current_path.'/'.$safe_file,'file',$size,$title);
api_item_property_update($_course,TOOL_DOCUMENT,$document_id,'DocumentAdded',$user_id,$to_group_id,null,null,null,$current_session_id);
//echo $current_path.'/'.$safe_file." added!<br/>";
}
}
}
}
}

@ -865,10 +865,9 @@ function fully_inside($axs, $ays, $bxs, $bys) {
return TRUE;
}
function _is_next_to($point, $last_point, $xs, $ys, $between_points=FALSE) {
$polygon = _to_points_array($xs, $ys);
if ( ($pos=array_search($point, $polygon)) !== NULL && !empty($pos)) {
function _is_next_to($point, $last_point, $xs, $ys, $between_points=FALSE) {
$polygon = _to_points_array($xs, $ys);
if ( is_array($polygon) && ($pos=array_search($point, $polygon)) !== NULL && !empty($pos)) {
//echo ":: :: is_next_to :: pos found !!<br />";
if ( $rp=_get_right_point($last_point['point'], $polygon) == $point
|| $lp=_get_left_point($last_point['point'], $polygon) == $point ) {

@ -293,6 +293,7 @@ class GroupManager {
$category_id = self :: create_category('Subgroups', '', TOOL_PRIVATE, TOOL_PRIVATE, 0, 0, 1, 1);
$users = self :: get_users($group_id);
$group_ids = array ();
for ($group_nr = 1; $group_nr <= $number_of_groups; $group_nr ++)
{
$group_ids[] = self :: create_group('SUBGROUP '.$group_nr, $category_id, 0, 0);

@ -72,8 +72,9 @@ class TestSubLanguageManager extends UnitTestCase {
$dokeos_path_file = $dirname.'spanish.inc.php';
$res = SubLanguageManager::add_file_in_language_directory($dokeos_path_file);
unlink($dokeos_path_file);
$this->assertTrue($res);
$this->assertTrue(is_null($res));
}
//var_dump($res);
}
public function testwrite_data_in_file(){
@ -88,11 +89,9 @@ class TestSubLanguageManager extends UnitTestCase {
$new_sub_language='spanishtest';
$variable_sub_language='test';
$res = SubLanguageManager::write_data_in_file($path_file,$new_sub_language,$variable_sub_language);
$this->assertTrue($res);
}
$this->assertNull($res);
}
//var_dump($res);
$this->assertFalse($res);
$this->assertTrue(is_null($res));
}
@ -221,11 +220,20 @@ class TestSubLanguageManager extends UnitTestCase {
// var_dump($res);
}
public function testDeleteCourse() {
global $cidReq;
$resu = CourseManager::delete_course($cidReq);
session_destroy();
}
public function TestDeleteCourse(){
$code = 'COURSEX';
$res = CourseManager::delete_course($code);
$path = api_get_path(SYS_PATH).'archive';
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if (strpos($file,$code)!==false) {
if (is_dir($path.'/'.$file)) {
rmdirr($path.'/'.$file);
}
}
}
closedir($handle);
}
}
}
?>

@ -70,22 +70,6 @@ class TestAddCourse extends UnitTestCase {
$this->assertTrue($res);
}
public function TestDeleteCourse(){
$code = 'COD16';
$res = CourseManager::delete_course($code);
$path = api_get_path(SYS_PATH).'archive';
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if (strpos($file,$code)!==false) {
if (is_dir($path.'/'.$file)) {
rmdirr($path.'/'.$file);
}
}
}
closedir($handle);
}
}
/* // 26 excepciones
function TestPrepareCourseRepository(){
umask(0);
@ -185,4 +169,21 @@ class TestAddCourse extends UnitTestCase {
//var_dump($res);
}
*/
public function TestDeleteCourse(){
$code = 'COD16';
$res = CourseManager::delete_course($code);
$path = api_get_path(SYS_PATH).'archive';
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if (strpos($file,$code)!==false) {
if (is_dir($path.'/'.$file)) {
rmdirr($path.'/'.$file);
}
}
}
closedir($handle);
}
}
}

@ -21,50 +21,11 @@ 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);
}
}
/*
@ -121,6 +82,8 @@ class TestBlog extends UnitTestCase
*/
public function testGetBlogTitle(){
global $_course;
$res = $this->oblog->get_Blog_title(11);
$this->assertFalse($this->oblog->get_Blog_title(11)===String);
$this->assertTrue(is_String($res));
@ -389,16 +352,18 @@ class TestBlog extends UnitTestCase
global $charset, $color2;
$res = $this->oblog->display_assigned_task_list(11);
$this->assertTrue($this->oblog->display_assigned_task_list(11)===null);
$this->assertFalse($res);
ob_end_clean();
$this->assertFalse($res);
}
public function testDisplayNewTaskForm(){
ob_start();
$res = $this->oblog->display_new_task_form(11);
$this->assertTrue($this->oblog->display_new_task_form(11)===null);
$this->assertFalse($res);
ob_end_clean();
$this->assertFalse($res);
}
@ -416,9 +381,10 @@ class TestBlog extends UnitTestCase
ob_start();
$res = $this->oblog->display_assign_task_form(11);
$this->assertTrue($this->oblog->display_assign_task_form(11)===null);
ob_end_clean();
$this->assertFalse($res);
$this->assertTrue(is_null($res));
ob_end_clean();
}
public function testDisplayEditAssignedTaskForm(){
@ -435,9 +401,10 @@ class TestBlog extends UnitTestCase
ob_start();
$res = $this->oblog->assign_task(11,1,12,null);
$this->assertTrue($this->oblog->assign_task(11,1,12,null)===null);
ob_end_clean();
$this->assertFalse(is_numeric($res));
$this->assertNull(null,$res);
ob_end_clean();
}
public function testEditAssignedTask(){
@ -458,9 +425,10 @@ class TestBlog extends UnitTestCase
ob_start();
$res = $this->oblog->display_select_task_post(11,12);
$this->assertTrue($this->oblog->display_select_task_post(11,12)===null);
ob_end_clean();
$this->assertTrue(is_null($res));
$this->assertFalse($res);
ob_end_clean();
}
public function testSetUserSubscribed(){
@ -481,9 +449,10 @@ class TestBlog extends UnitTestCase
ob_start();
$res = $this->oblog->display_form_user_subscribe(12);
$this->assertTrue($this->oblog->display_form_user_subscribe(12)===null);
ob_end_clean();
$this->assertNotNull(is_null($res));
$this->assertFalse($res);
ob_end_clean();
}
/**
@ -499,17 +468,19 @@ class TestBlog extends UnitTestCase
ob_start();
$blog_id = '1';
$res = Blog::display_form_user_unsubscribe($blog_id);
ob_end_clean();
$this->assertTrue(is_null($res));
$this->assertNull($res);
ob_end_clean();
}
public function testDisplayFormUserRights(){
ob_start();
$res = $this->oblog->display_form_user_rights(12);
$this->assertTrue($this->oblog->display_form_user_rights(12)===null);
$this->assertFalse($res);
ob_end_clean();
$this->assertFalse($res);
}
public function testDisplayNewCommentForm(){
@ -518,9 +489,10 @@ class TestBlog extends UnitTestCase
$title='test';
ob_start();
$res =$this->oblog->display_new_comment_form($blog_id,$post_id,$title);
ob_end_clean();
$this->assertFalse($res);
$this->assertNotNull(is_null($res));
ob_end_clean();
}
public function testDisplayMinimonthcalendar(){
@ -531,8 +503,9 @@ class TestBlog extends UnitTestCase
$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();
$this->assertTrue(is_null($res));
}
public function testDisplayNewBlogForm(){
@ -548,16 +521,18 @@ class TestBlog extends UnitTestCase
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();
$this->assertTrue(is_null($res));
}
public function testDisplayBlogList(){
ob_start();
$res = $this->oblog->display_blog_list();
$this->assertTrue($this->oblog->display_blog_list()===null);
$this->assertTrue(is_null($res));
ob_end_clean();
$this->assertTrue(is_null($res));
}
public function testGetBlogAttachment(){
@ -587,6 +562,7 @@ class TestBlog extends UnitTestCase
$res = get_blog_post_from_user('chamilo_COURSEX',1);
$this->assertFalse($res);
$this->assertTrue(is_string($res));
//var_dump($res);
}
public function testGetBlogCommentFromUser(){
@ -608,12 +584,13 @@ class TestBlog extends UnitTestCase
closedir($handle);
}
}
/*
public function testDeleteCourse() {
global $cidReq;
$resu = CourseManager::delete_course($cidReq);
}
*/

@ -18,7 +18,6 @@ class TestCourse extends UnitTestCase{
public function TestCourse(){
$this->UnitTestCase('All main course function tests');
}
public function setUp(){
@ -26,8 +25,8 @@ class TestCourse extends UnitTestCase{
$this->tcourse = new CourseManager();
$course_datos = array(
'wanted_code'=> 'CURSO1',
'title'=>'CURSO1',
'wanted_code'=> 'COURSE1',
'title'=>'COURSE1',
'tutor_name'=>'R. J. Wolfagan',
'category_code'=>'2121',
'course_language'=>'english',
@ -38,15 +37,14 @@ class TestCourse extends UnitTestCase{
$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_datos['db_prefix'], $course_datos['firstExpirationDelay']);
}
public function tearDown(){
$this->tcourse = null;
$this->dbase = null;
$code = 'CURSO1';
$code = 'COURSE1';
$res = CourseManager::delete_course($code);
$path = api_get_path(SYS_PATH).'archive';
if ($handle = opendir($path)) {
@ -59,7 +57,7 @@ class TestCourse extends UnitTestCase{
}
closedir($handle);
}
}
/*
@ -118,7 +116,6 @@ class TestCourse extends UnitTestCase{
$this->assertFalse($res);
$this->assertTrue(is_bool($res));
$this->assertTrue($this->tcourse->get_course_information(1211)=== is_array($res));
}
public function testGetCoursesList(){
@ -143,7 +140,7 @@ class TestCourse extends UnitTestCase{
public function testUnsubscribeUser(){
$user_id = 1;
$course_code = 'CURSO1';
$course_code = 'COURSE1';
$res = CourseManager::unsubscribe_user($user_id, $course_code);
$this->assertNull($res);
$this->assertFalse(is_string($res));
@ -151,24 +148,22 @@ class TestCourse extends UnitTestCase{
public function testSubscribeUser(){
$user_id = 1;
$course_code = 'CURSO1';
$course_code = 'COURSE1';
$status = STUDENT;
$res = CourseManager::subscribe_user($user_id, $course_code, $status);
$this->assertTrue(is_bool($res));
}
public function testAddUserToCourse(){
$user_id = 1;
$course_code = 'CURSO1';
$course_code = 'COURSE1';
$status = STUDENT;
$res = CourseManager::add_user_to_course($user_id, $course_code, $status);
$this->assertTrue($res);
$this->assertTrue(is_bool($res));
//var_dump($res);
}
//function deprecated public function testGetRealCourseCodeSelectHtml(){}
public function testCheckParameter(){
$parameter = '123';
$error_message = 'oops!!';
@ -188,7 +183,7 @@ class TestCourse extends UnitTestCase{
}
public function testIsExistingCourseCode() {
$wanted_course_code = 'CURSO1';
$wanted_course_code = 'COURSE1';
$res = $this->tcourse->is_existing_course_code($wanted_course_code);
$this->assertTrue(is_bool($res));
$this->assertTrue($res);
@ -213,27 +208,36 @@ class TestCourse extends UnitTestCase{
$result = Database::fetch_array($sql_result);
$virtual_course_list[] = $result;
$res=$this->tcourse->get_virtual_course_list();
if (!empty($res)) {
$this->assertTrue(is_array($res));
} else {
$this->assertTrue(is_null($res));
}
}
public function testGetRealCourseListOfUserAsCourseAdmin(){
$user_id = 1;
$res = $this->tcourse->get_real_course_list_of_user_as_course_admin($user_id);
if(is_array($res)){
$this->assertTrue(is_array($res));
$this->assertTrue($res);
} else {
$this->assertNull($res);
$this->assertTrue(is_null($res));
}
//var_dump($res);
}
public function testGetCourseListOfUserAsCourseAdmin(){
$user_id = 1;
$res = $this->tcourse->get_course_list_of_user_as_course_admin($user_id);
if(is_array($res)){
$this->assertTrue($res);
$this->assertTrue(is_array($res));
} else {
$this->assertTrue(is_null($res));
$this->assertNull($res);
}
//var_dump($res);
}
@ -248,7 +252,7 @@ class TestCourse extends UnitTestCase{
public function testCreateCombinedName(){
$complete_course_name = array();
$user_is_registered_in_real_course = false;
$real_course_name = 'CURSO1';
$real_course_name = 'COURSE1';
$virtual_course_list = array();
$res = CourseManager::create_combined_name($user_is_registered_in_real_course,
$real_course_name,
@ -262,26 +266,33 @@ class TestCourse extends UnitTestCase{
public function testCreateCombinedCode(){
$complete_course_code = array();
$user_is_registered_in_real_course = false;
$real_course_code = 'CURSO1';
$real_course_code = 'COURSE1';
$virtual_course_list = array();
$res = CourseManager::create_combined_code($user_is_registered_in_real_course,
$real_course_code,
$virtual_course_list);
if(is_array($res)){
$this->assertFalse($res);
$this->assertFalse(is_null($res));
$this->assertTrue(is_string($res));
} else {
$this->assertFalse(is_null($res));
}
//var_dump($res);
}
public function testGetVirtualCourseInfo(){
$real_course_code = 'CURSO1';
$real_course_code = 'COURSE1';
$res = $this->tcourse->get_virtual_course_info($real_course_code);
$this->assertTrue($res);
if(is_array($res)){
$this->assertTrue(is_array($res));
} else {
$this->assertTrue($res);
}
//var_dump($res);
}
public function testIsVirtualCourseFromSystemCode(){
$system_code = 'CURSO1';
$system_code = 'COURSE1';
$res = $this->tcourse->is_virtual_course_from_system_code($system_code);
$this->assertFalse($res);
$this->assertTrue(is_bool($res));
@ -289,23 +300,27 @@ class TestCourse extends UnitTestCase{
}
public function testIsVirtualCourseFromVisualCode(){
$system_code = 'CURSO1';
$system_code = 'COURSE1';
$res = $this->tcourse->is_virtual_course_from_visual_code($system_code);
$this->assertFalse($res);
$this->assertTrue(is_bool($res));
}
public function testHasVirtualCourseFromCode(){
$real_course_code = 'CURSO1';
$real_course_code = 'COURSE1';
$user_id = 1;
$res = CourseManager::has_virtual_courses_from_code($real_course_code, $user_id);
$this->assertTrue($res);
$this->assertTrue(is_bool($res));
$this->assertFalse(is_null($res));
if(is_bool($res)){
$this->assertFalse($res);
$this->assertTrue(is_bool($res));
} else {
$this->assertFalse(is_null($res));
}
//var_dump($res);
}
public function testGetVirtualCourseLinkedToRealCourse(){
$real_course_code = 'CURSO1';
$real_course_code = 'COURSE1';
$res = CourseManager::get_virtual_courses_linked_to_real_course($real_course_code);
$this->assertFalse($res);
$this->assertTrue(is_array($res));
@ -313,7 +328,7 @@ class TestCourse extends UnitTestCase{
}
public function testGetTargetOfLinkedCourse(){
$virtual_course_code = 'CURSO1';
$virtual_course_code = 'COURSE1';
$res = CourseManager::get_target_of_linked_course($virtual_course_code);
$this->assertFalse($res);
$this->assertTrue(is_null($res));
@ -322,7 +337,7 @@ class TestCourse extends UnitTestCase{
public function testIsUserSubscribedInCourse(){
$user_id = 1;
$course_code = 'CURSO1';
$course_code = 'COURSE1';
$in_a_session = false;
$res = CourseManager::is_user_subscribed_in_course($user_id, $course_code, $in_a_session);
$this->assertTrue(is_bool($res));
@ -331,7 +346,7 @@ class TestCourse extends UnitTestCase{
public function testIsCourseTeacher(){
$user_id = 1;
$course_code = 'CURSO1';
$course_code = 'COURSE1';
$res = CourseManager::is_course_teacher($user_id, $course_code);
$this->assertTrue(is_bool($res));
$this->assertFalse($res);
@ -339,15 +354,20 @@ class TestCourse extends UnitTestCase{
public function testIsUserSubscribedInRealOrLinkedCourse(){
$user_id = 1;
$course_code = 'CURSO1';
$course_code = 'COURSE1';
$session_id = '';
$res = CourseManager::is_user_subscribed_in_real_or_linked_course($user_id, $course_code, $session_id);
$this-> assertTrue(is_bool($res));
$this->assertTrue($res);
if(is_bool($res)){
$this-> assertTrue(is_bool($res));
$this->assertFalse($res);
} else {
$this->assertTrue($res);
}
//var_dump($res);
}
public function testGetUserListFromCourseCode(){
$course_code = 'CURSO1';
$course_code = 'COURSE1';
$with_session = true;
$session_id = 0;
$limit = '';
@ -359,7 +379,7 @@ class TestCourse extends UnitTestCase{
}
public function testGetCoachListFromCourseCode(){
$course_code = 'CURSO1';
$course_code = 'COURSE1';
$session_id = '';
$res = CourseManager::get_coach_list_from_course_code($course_code, $session_id);
$this->assertFalse($res);
@ -367,7 +387,7 @@ class TestCourse extends UnitTestCase{
}
public function testGetStudentListFromCourseCode(){
$course_code = 'CURSO1';
$course_code = 'COURSE1';
$session_id = '001';
$res = $this->tcourse->get_student_list_from_course_code($course_code, $session_id);
//$this->assertTrue($res);
@ -376,7 +396,7 @@ class TestCourse extends UnitTestCase{
}
public function testGetTeacherListFromCourseCode(){
$course_code = 'CURSO1';
$course_code = 'COURSE1';
$res = $this->tcourse->get_teacher_list_from_course_code($course_code);
$this->assertFalse($res);
$this->assertFalse(is_null($res));
@ -384,7 +404,7 @@ class TestCourse extends UnitTestCase{
}
public function testGetRealAndLinkedUserList(){
$course_code = 'CURSO1';
$course_code = 'COURSE1';
$with_sessions = true;
$session_id = 0;
$res = $this->tcourse->get_real_and_linked_user_list($course_code, $with_sessions, $session_id);
@ -395,15 +415,19 @@ class TestCourse extends UnitTestCase{
}
public function testGetListOfVirtualCoursesForSpecificUserAndRealCourse(){
$result_array = array('user_id' => 1, 'real_course_code' => 'CURSO1');
$result_array = array('user_id' => 1, 'real_course_code' => 'COURSE1');
$res = CourseManager::get_list_of_virtual_courses_for_specific_user_and_real_course($result_array['user_id'],$result_array['real_course_code']);
$this->assertTrue($res);
if(is_array($res)){
$this->assertTrue(is_array($res));
} else {
$this->assertTrue($res);
}
//var_dump($res);
}
public function testGetGroupListOfCourse(){
$course_code = 'CURSO1';
$sql= "SELECT * FROM chamilo_CURSO1";
$course_code = 'COURSE1';
$sql= "SELECT * FROM chamilo_COURSE1";
$result = CourseManager::get_group_list_of_course($course_code);
$this->assertTrue(is_array($result));
$this->assertFalse($result);
@ -411,46 +435,37 @@ class TestCourse extends UnitTestCase{
}
public function testAttemptCreateVirtualCourse(){
$real_course_code = 'CURSO1';
$course_title = 'CURSO2';
$wanted_course_code = 'CURSO3';
$real_course_code = 'COURSE1';
$course_title = 'COURSE1';
$wanted_course_code = 'COURSE1';
$course_language = 'english';
$course_category = 'LANG';
ob_start();
$res = CourseManager::attempt_create_virtual_course($real_course_code, $course_title, $wanted_course_code, $course_language, $course_category);
ob_end_clean();
$this->assertTrue(is_bool($res));
$this->assertTrue(is_bool($res));
}
public function testCreateVirtualCourse(){
$real_course_code = 'CURSO2';
$course_title = 'CURSO2';
$wanted_course_code = 'CURSO4';
$real_course_code = 'COURSE1';
$course_title = 'COURSE1';
$wanted_course_code = 'COURSE1';
$course_language = 'english';
$course_category = 'LANG';
ob_start();
$res = CourseManager::create_virtual_course($real_course_code, $course_title, $wanted_course_code, $course_language, $course_category);
ob_end_clean();
$this->assertTrue($res);
$this->assertTrue(is_bool($res));
if(is_bool($res)){
$this->assertTrue(is_bool($res));
} else {
$this->assertTrue($res);
}
//var_dump($res);
}
public function testDeleteCourse(){
global $_configuration;
$code = 'CURSO1';
if (!empty($course_code)) {
$code = $course_code;
}
$res = CourseManager::delete_course($code);
$this->assertTrue(is_null($res));
}
public function testCreateDatabaseDump(){
global $_configuration;
$course_code='CURSO1';
$course_code='COURSE1';
$res = $this->tcourse->create_database_dump($course_code);
$this->assertFalse($res);
$this->assertTrue(is_null($res));
@ -458,7 +473,7 @@ class TestCourse extends UnitTestCase{
public function testUserCourseSort(){
$user_id ='01';
$course_code='CURSO1';
$course_code='COURSE1';
$res = CourseManager::UserCourseSort($user_id,$course_code);
$this->assertTrue($res);
$this->assertTrue(is_numeric($res));
@ -474,7 +489,7 @@ class TestCourse extends UnitTestCase{
}
public function testCourseExists(){
$course_code='CURSO1';
$course_code='COURSE1';
$accept_virtual = false;
$res=$this->tcourse->course_exists($course_code, $accept_virtual);
$this->assertTrue(is_numeric($res));
@ -482,7 +497,7 @@ class TestCourse extends UnitTestCase{
public function testEmailToTutor() {
$user_id= '01';
$course_code= 'CURSO1';
$course_code= 'COURSE1';
$res=CourseManager::email_to_tutor($course_code,$user_id);
$this->assertTrue(is_string($course_code));
//var_dump($res);
@ -518,7 +533,7 @@ class TestCourse extends UnitTestCase{
public function testGetEmailOfTutorToSession(){
$session_id = '01';
$course_code = 'CURSO1';
$course_code = 'COURSE1';
ob_start();
$res = CourseManager::get_email_of_tutor_to_session($session_id,$course_code);
ob_end_clean();
@ -536,15 +551,26 @@ class TestCourse extends UnitTestCase{
}
public function testUpdateCourseExtraFieldValue(){
$course_code = 'CURSO1';
$course_code = 'COURSE1';
$fname = '';
$fvalue= '';
$res = $this->tcourse->update_course_extra_field_value($course_code,$fname,$fvalue='');
$this->assertTrue($res);
$this->assertTrue(is_bool($res));
$this->assertFalse(is_null($res));
}
public function testDeleteCourse(){
global $_configuration;
$code = 'COURSE1';
if (!empty($course_code)) {
$code = $course_code;
}
$res = CourseManager::delete_course($code);
$this->assertTrue(is_null($res));
}
}
?>

@ -14,7 +14,7 @@ class TestDatabase extends UnitTestCase {
$this->dbase = new Database();
$course_datos = array(
'wanted_code'=> 'COD16',
'wanted_code'=> 'CURSO1',
'title'=>'CURSO1',
'tutor_name'=>'R. J. Wolfagan',
'category_code'=>'2121',
@ -32,7 +32,7 @@ class TestDatabase extends UnitTestCase {
public function tearDown() {
$this->dbase = null;
$code = 'COD16';
$code = 'CURSO1';
$res = CourseManager::delete_course($code);
$path = api_get_path(SYS_PATH).'archive';
if ($handle = opendir($path)) {

@ -16,7 +16,7 @@ class TestDisplay extends UnitTestCase {
public function testdisplay_localised_html_file(){
global $language_interface;
$doc_url = str_replace('/..', '', $doc_url);
$full_file_name=api_get_path(SYS_COURSE_PATH).api_get_course_path().'courses/index'.$doc_url;
$full_file_name=api_get_path(SYS_COURSE_PATH).'/index'.$doc_url;
ob_start();
$res = Display::display_localised_html_file($full_file_name);
ob_end_clean();
@ -148,7 +148,7 @@ class TestDisplay extends UnitTestCase {
* Display the reduced page header (without banner)
*/
// [/var/www/chamilo/main/inc/reduced_header.inc.php line 30] - exception
public function testdisplay_reduced_header() {
/* public function testdisplay_reduced_header() {
global $_plugins,$lp_theme_css,$mycoursetheme,$user_theme,$platform_theme;
global $httpHeadXtra, $htmlHeadXtra, $htmlIncHeadXtra, $_course, $_user, $clarolineRepositoryWeb, $text_dir, $plugins, $_user, $rootAdminWeb, $_cid, $interbreadcrumb, $charset, $language_file, $noPHP_SELF, $language_interface;
global $menu_navigation;
@ -158,7 +158,7 @@ class TestDisplay extends UnitTestCase {
$this->assertTrue(is_null($res));
//var_dump($res);
}
*/
/**
* Displays an confirmation message. Use this if something has been done successfully
*
@ -216,7 +216,7 @@ class TestDisplay extends UnitTestCase {
* @return string Display the hearders messages
*/
// [/var/www/chamilo/main/inc/header.inc.php line 31] - exception
public function testdisplay_header() {
/* public function testdisplay_header() {
global $_plugins,$lp_theme_css,$mycoursetheme,$user_theme,$platform_theme;
global $httpHeadXtra, $htmlHeadXtra, $htmlIncHeadXtra, $_course, $_user, $clarolineRepositoryWeb, $text_dir, $plugins, $_user, $rootAdminWeb, $_cid, $interbreadcrumb, $charset, $language_file, $noPHP_SELF;
global $menu_navigation;
@ -229,7 +229,7 @@ class TestDisplay extends UnitTestCase {
$this->assertTrue(is_null($res));
//var_dump($res);
}
*/
/**
* This public function displays an icon
* @param string $image the filename of the file (in the main/img/ folder

@ -4,26 +4,24 @@ require_once(api_get_path(LIBRARY_PATH).'document.lib.php');
class TestDocumentManager extends UnitTestCase {
public function CreateCourse(){
public function testcreateCourse(){
global $_configuration;
$course_datos = array('wanted_code'=> 'CURSO1',
'title'=>'CURSO1',
'tutor_name'=>'R. J. Wolfagan',
'category_code'=>'2121',
'course_language'=>'english',
'course_admin_id'=>'1211',
'db_prefix'=> $_configuration['db_prefix'],
'firstExpirationDelay'=>'112'
);
$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_datos = array('wanted_code'=> 'CURSO1',
'title'=>'CURSO1',
'tutor_name'=>'R. J. Wolfagan',
'category_code'=>'2121',
'course_language'=>'english',
'course_admin_id'=>'1211',
'db_prefix'=> $_configuration['db_prefix'],
'firstExpirationDelay'=>'112'
);
$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']
);
}
/**
* This check if a document has the readonly property checked, then see if
* the user is the owner of this file, if all this is true then return true.
@ -36,7 +34,7 @@ class TestDocumentManager extends UnitTestCase {
* @return boolean true/false
**/
public function testcheck_readonly() {
$_course='';
$_course='chamilo_CURSO1';
$user_id='';
$file='';
$res=DocumentManager::check_readonly($_course,$user_id,$file);
@ -57,7 +55,7 @@ class TestDocumentManager extends UnitTestCase {
* rename them too.
*/
function testdelete_document() {
$_course['dbName']='';
$_course['dbName']='chamilo_CURSO1';
$path='';
$base_work_dir='';
$res=DocumentManager::delete_document($_course, $path, $base_work_dir);
@ -137,7 +135,7 @@ class TestDocumentManager extends UnitTestCase {
* @return array with all document data
*/
function testget_all_document_data() {
$_course['dbName']='';
$_course['dbName']='chamilo_CURSO1';
$path = '/';
$to_group_id = 0;
$to_user_id = NULL;
@ -157,8 +155,10 @@ class TestDocumentManager extends UnitTestCase {
* @return array with paths
*/
function testget_all_document_folders() {
$_course['dbName']='';
$res=DocumentManager::get_all_document_folders($_course);
$_course['dbName']='chamilo_CURSO1';
$to_group_id = '0';
$can_see_invisible = false;
$res=DocumentManager::get_all_document_folders($_course, $to_group_id, $can_see_invisible);
$this->assertTrue(is_array($_course));
//var_dump($_course);
}
@ -180,7 +180,7 @@ class TestDocumentManager extends UnitTestCase {
* @return int id of document / false if no doc found
*/
function testget_document_id() {
$_course['dbName']='';
$_course['dbName']='chamilo_CURSO1';
$path = Database::escape_string($path);
$res=DocumentManager::get_document_id($_course, $path);
$this->assertTrue(is_bool($res));
@ -195,7 +195,6 @@ class TestDocumentManager extends UnitTestCase {
function testis_folder() {
$_course['dbName'] = 'chamilo_CURSO1';
$document_id = 1;
$document_id = Database::escape_string($document_id);
$res=DocumentManager::is_folder($_course, $document_id);
$this->assertTrue(is_bool($res));
}
@ -207,9 +206,9 @@ class TestDocumentManager extends UnitTestCase {
* @param array $course the _course array info of the document's course
*/
function testis_visible() {
$course['dbName']='';
global $_course;
$doc_path = Database::escape_string($doc_path);
$res=DocumentManager::is_visible($doc_path, $course);
$res=DocumentManager::is_visible($doc_path, $_course);
$this->assertTrue(is_bool($res));
}
@ -272,7 +271,7 @@ class TestDocumentManager extends UnitTestCase {
//var_dump($res);
}
public function DeleteCourse(){
public function testdeleteCourseInDocument(){
$this->dmanager = null;
$code = 'CURSO1';
$res = CourseManager::delete_course($code);
@ -288,7 +287,6 @@ class TestDocumentManager extends UnitTestCase {
closedir($handle);
}
}
}
}
?>

@ -0,0 +1,205 @@
<?php
//require_once(api_get_path(LIBRARY_PATH).'classManager.lib.php');
class TestFileManager extends UnitTestCase {
public $fmanager;
public function TestFileManager(){
$this->UnitTestCase ('File Display Manage');
}
public function setUp(){
$this->fmanager = new FileManager();
}
public function tearDown(){
$this->fmanager = null;
}
//todo public function testUpdatedbInfo
//todo public function testCheckNameExist
//todo public function testMyDelete
//todo public function testRemoveDir
//todo public function testMyRename
//todo public function testMove
//todo public function testCopyDirTo
//todo public function testIndexDir
//todo public function testIndexAndSortDir
//todo public function testFormDirList
//todo public function testMkpath
//todo public function testGetextension
//todo public function testDirsize
//todo public function testListAllDirectories
//todo public function testListAllFiles
//todo public function testCompatLoadFile
//todo public function testSetDefaultSettings
//todo public function testMkdirs
public function testUpdatedbInfo(){
$action ='';
$oldPath ='';
$res = update_db_info($action, $oldPath, $newPath="");
$this->assertTrue(is_null($res));
//var_dump($res);
}
public function testCheckNameExist(){
$filePath ='';
$res = check_name_exist($filePath);
$this->assertFalse($res);
$this->assertTrue(is_bool($res));
$this->assertTrue($res === false);
//var_dump($res);
}
public function testMyDelete(){
$file='';
$res = my_delete($file);
$this->assertFalse($res);
$this->assertTrue(is_bool($res));
$this->assertTrue($res===false);
//var_dump($res);
}
public function testRemoveDir(){
$dir='';
$res = removeDir($dir);
$this->assertTrue(is_bool($res));
$this->assertFalse($res === true);
//var_dump($res);
}
public function testMyRename(){
$filePath ='documents';
$newFileName='';
$res = my_rename($filePath, $newFileName);
$this->assertTrue(is_bool($res));
$this->assertTrue($res === false);
//var_dump($res);
}
public function testMove(){
$source ='';
$target ='';
$res = move($source, $target);
$this->assertTrue(is_bool($res));
$this->assertTrue($res === false);
$this->assertFalse($res);
//var_dump($res);
}
public function testCopyDirTo(){
$origDirPath=api_get_path(SYS_COURSE_PATH).'COURSEX/document/audio';
$destination=api_get_path(SYS_COURSE_PATH).'COURSEX/document/flash/audio';
$res = copyDirTo($origDirPath, $destination, $move = false);
$this->assertTrue($res===null);
$this->assertNull($res);
}
public function testIndexDir(){
$path=api_get_path(SYS_COURSE_PATH).'COURSEX/document';
$res = index_dir($path);
$this->assertTrue(is_array($res));
$this->assertTrue($res);
//var_dump($res);
}
public function testIndexAndSortDir(){
$path=api_get_path(SYS_COURSE_PATH).'COURSEX/document';
$res = index_and_sort_dir($path);
$this->assertTrue($res);
$this->assertTrue(is_array($res));
$this->assertFalse(is_bool($res));
$this->assertFalse($res === array());
//var_dump($res);
}
public function testFormDirList(){
$sourceType = '';
$sourceComponent = '';
$command = '';
$baseWorkDir = api_get_path(SYS_COURSE_PATH).'COURSEX/document/';
$res = form_dir_list($sourceType, $sourceComponent, $command, $baseWorkDir);
$this->assertTrue($res);
$this->assertTrue(is_string($res));
//var_dump($res);
}
public function testMkpath(){
$path=api_get_path(SYS_COURSE_PATH).'COURSEX/document';
$res =mkpath($path, $verbose=false);
$this->assertFalse($res);
$this->assertNull($res);
$this->assertTrue($res === null);
//var_dump($res);
}
public function testGetextension(){
$filename='documents';
$res =getextension($filename);
$this->assertTrue($res);
$this->assertTrue(is_array($res));
}
public function testDirsize(){
$root='';
$res =dirsize($root,$recursive=true);
$this->assertFalse($res);
$this->assertTrue(is_numeric($res));
$this->assertTrue($res ===0);
//var_dump($res);
}
public function testListAllDirectories(){
$path=api_get_path(SYS_COURSE_PATH).'COURSEX/document';
$res = $this->fmanager->list_all_directories($path);
$this->assertTrue($res);
$this->assertTrue(is_array($res));
//var_dump($res);
}
public function testListAllFiles(){
$dirArray = array('COURSEX, document, images');
$res = $this->fmanager->list_all_files($dirArray);
$this->assertFalse($res);
$this->assertTrue(is_array($res));
$this->assertTrue($res === array());
//var_dump($res);
}
public function testCompatLoadFile(){
$file_name='README.txt';
$res = $this->fmanager->compat_load_file($file_name);
$this->assertFalse($res);
$this->assertTrue(is_string($res));
//var_dump($res);
}
public function testSetDefaultSettings(){
global $_course, $_configuration;
$upload_path=api_get_path(SYS_COURSE_PATH).'COURSEX';
$filename='index.html';
$glue_table = $_course['dbName'].'.document';
$res = $this->fmanager->set_default_settings($upload_path, $filename, $filetype="file", $glue_table, $default_visibility='v');
$this->assertTrue(is_null($res));
//var_dump($res);
}
public function testMkdirs(){
$path=api_get_path(SYS_COURSE_PATH).'COURSEX/document';
$res = $this->fmanager->mkdirs($path);
$this->assertFalse($res);
$this->assertTrue(is_bool($res));
$this->assertTrue($res === false);
//var_dump($res);
}
}
?>

@ -373,11 +373,5 @@ class TestFileUpload extends UnitTestCase {
//var_dump($res);
}
public function testdeleteCourse(){
$this->dmanager = null;
$code = 'COURSEX';
$res = CourseManager::delete_course($code);
}
}
?>

@ -11,7 +11,7 @@ class TestGeometry extends UnitTestCase {
public function testCalculateArea(){
$xs = 12;
$ys = 11;
$ys = 12;
$res = calculate_area($xs,$ys);
$this->assertTrue(is_bool($res));
//var_dump($res);
@ -68,8 +68,8 @@ class TestGeometry extends UnitTestCase {
}
public function testCheckPolygon(){
$xs=32;
$ys=13;
$xs=12;
$ys=12;
$res = _check_polygon($xs, $ys);
$this->assertTrue(is_bool($res));
$this->assertTrue($res === false);
@ -78,8 +78,8 @@ class TestGeometry extends UnitTestCase {
}
public function testPolygon2String(){
$xs=42;
$ys=62;
$xs=12;
$ys=12;
$res = polygon2string($xs, $ys);
$this->assertTrue(is_string($res));
$this->assertTrue($res);
@ -88,8 +88,8 @@ class TestGeometry extends UnitTestCase {
public function testIsInsidePolygon(){
$p=43;
$xs=11;
$ys=45;
$xs=12;
$ys=12;
$res = _is_inside_polygon($p, $xs, $ys);
$this->assertTrue(is_bool($res));
$this->assertTrue($res === false);
@ -97,8 +97,8 @@ class TestGeometry extends UnitTestCase {
}
public function testGetInsideConditionals(){
$xs=11;
$ys=23;
$xs=array(12);
$ys=array(12);
$res = _get_inside_conditionals($xs, $ys);
$this->assertTrue(is_array($res));
$this->assertTrue($res);
@ -117,10 +117,10 @@ class TestGeometry extends UnitTestCase {
}
public function testGetIntersectionPolygon(){
$rxs='11';
$rys='23';
$uxs='54';
$uys='56';
$rxs= 11;
$rys= 23;
$uxs= 54;
$uys= 56;
$res = get_intersection_polygon($rxs, $rys, $uxs, $uys);
$this->assertTrue(is_null($res));
$this->assertTrue($res === null);
@ -152,11 +152,12 @@ class TestGeometry extends UnitTestCase {
}
public function testIsNextTo(){
$point=32;
$last_point=11;
$xs=15;
$ys=56;
$res = _is_next_to($point, $last_point, $xs, $ys);
$point = 32;
$last_point = 10;
$xs = 12;
$ys = 12;
$between_points = FALSE;
$res = _is_next_to($point, $last_point, $xs, $ys, $between_points);
$this->assertTrue(is_bool($res));
$this->assertTrue($res === false);
$this->assertFalse($res);
@ -165,7 +166,7 @@ class TestGeometry extends UnitTestCase {
public function testGetRightPoint(){
$point=44;
$polygon=0;
$polygon= array(12,12);
$res = _get_right_point($point, $polygon);
$this->assertTrue(is_null($res));
$this->assertNull($res);
@ -174,8 +175,8 @@ class TestGeometry extends UnitTestCase {
}
public function testGetLeftPoint(){
$point=44;
$polygon=01;
$point = 44;
$polygon= array(12,12);
$res = _get_left_point($point, $polygon);
$this->assertTrue(is_null($res));
$this->assertNull($res);
@ -184,8 +185,8 @@ class TestGeometry extends UnitTestCase {
}
public function testToPointsArray(){
$xs=22;
$ys=33;
$xs=12;
$ys=12;
$res = _to_points_array($xs, $ys);
$this->assertTrue(is_bool($res));
$this->assertTrue($res === false);
@ -194,8 +195,8 @@ class TestGeometry extends UnitTestCase {
}
public function testToPointsIntersection(){
$xs=14;
$ys=14;
$xs=12;
$ys=12;
$res = _to_points_intersection($xs, $ys);
$this->assertTrue(is_bool($res));
$this->assertTrue($res === false);
@ -204,16 +205,30 @@ class TestGeometry extends UnitTestCase {
}
public function testInInternArray(){
$oint=34;
$intern_points=13;
$res = in_intern_array($oint,$intern_points);
$point = 34;
$intern_points = array();
$res = in_intern_array($point,$intern_points);
$this->assertTrue(is_bool($res));
$this->assertTrue($res === false);
$this->assertFalse($res);
//var_dump($res);
}
public function TestDeleteCourse(){
$code = 'COURSEX';
$res = CourseManager::delete_course($code);
$path = api_get_path(SYS_PATH).'archive';
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if (strpos($file,$code)!==false) {
if (is_dir($path.'/'.$file)) {
rmdirr($path.'/'.$file);
}
}
}
closedir($handle);
}
}
}
?>

@ -7,13 +7,6 @@ require_once(api_get_path(LIBRARY_PATH).'course.lib.php');
require_once(api_get_path(LIBRARY_PATH).'tablesort.lib.php');
//require_once(dirname(__FILE__).'/../../../simpletest/mock_objects.php');
Mock::generate('Database');
Mock::generate('ClassManager');
Mock::generate('FileManager');
Mock::generate('CourseManager');
Mock::generate('TableSort');
$_course = api_get_course_info('0001');
class TestGroupManager extends UnitTestCase {
/**
@ -21,20 +14,7 @@ class TestGroupManager extends UnitTestCase {
* file manager, course manager and table sort.
* @author Ricardo Rodriguez Salazar
*/
/*
function testExportTableCsv() {
$docman = new MockDocumentManager();
$data = array();
$filename = 'export';
$this->export = new Export();
$res=$this->export->export_table_csv($data,$filename);
$docman->expectOnce('DocumentManager::file_send_for_download',array($filename,true,$filename.'.csv'));
$this->assertTrue(is_object($this->export));
//var_dump($docman);
//var_dump($export);
}
*/
public function testGetGroupList(){
global $_user;
$res = GroupManager::get_group_list();
@ -50,16 +30,16 @@ class TestGroupManager extends UnitTestCase {
global $_course, $_user;
$res = GroupManager::create_group($name, $category_id, $tutor, $places);
$this->assertTrue(is_numeric($res));
$this->assertTrue(($res) == int);
$this->assertTrue(($res) == 1);
//var_dump($res);
}
public function testCreateSubgroups(){
$group_id = 2;
$number_of_groups=3;
global $_course;
$group_id = 1;
$number_of_groups = 2;
$res = GroupManager::create_subgroups($group_id, $number_of_groups);
$this->assertTrue(is_null($res));
$this->assertTrue(GroupManager::create_subgroups($res)===null);
//var_dump($res);
}
@ -74,18 +54,13 @@ class TestGroupManager extends UnitTestCase {
$category_id=2;
$res =GroupManager::create_class_groups($category_id);
$this->assertTrue(is_array($res));
$this->assertTrue(GroupManager::create_class_groups($category_id) === array());
//var_dump($res);
}
public function testDeleteGroups(){
$fmanager = new MockFileManager();
$dbase = new MockDatabase();
$group_ids='01';
$course_code=null;
$res =GroupManager::delete_groups($group_ids, $course_code = null);
$fmanager->expectOnce('FileManager :: mkdirs($group_garbage, $perm);');
$dbase->expectOnce('Database::affected_rows()');
$this->assertTrue(is_numeric($res));
//var_dump($res);
}
@ -121,52 +96,43 @@ class TestGroupManager extends UnitTestCase {
}
public function testGetNumberOfGroups(){
$dbase = new MockDataBase();
$res = GroupManager::get_number_of_groups();
$dbase->expectOnce('Database :: get_course_table(TABLE_GROUP)');
$dbase->expectOnce('Database::fetch_object($res)');
$dbase->expectOnce('$obj->number_of_groups');
$this->assertTrue(is_null($res));
//$this->assertTrue(is_string($res));
$this->assertTrue(($res));
$this->assertTrue(is_string($res));
//var_dump($res);
}
public function testGetCategories(){
$course_code ='COD128983';
$course_db = '';
$course_code ='COURSEX';
$course_db = 'chamilo_COURSEX';
$res = GroupManager::get_categories($course_code);
$this->assertTrue(is_array($res));
//var_dump($res);
}
public function testGetCategory(){
$dbase = new MockDataBase();
$id =2;
$course_code =null;
$course_code = 'COURSEX';
$res = GroupManager::get_category($id,$course_code);
$dbase->expectOnce('Database::fetch_array($res)');
$this->assertTrue(is_bool($res));
$this->assertTrue(is_array($res));
$this->assertTrue($res);
//var_dump($res);
}
public function testGetCategoryFromGroup(){
$course_code='';
$group_id='';
$course_db = '';
$sql = "SELECT 1 ";
$res = Database::query($sql);
$cat = Database::fetch_array($res);
$course_code='COURSEX';
$group_id= 1;
$course_db = 'chamilo_COURSEX';
$resu = GroupManager::get_category_from_group($group_id,$course_code);
$this->assertTrue(is_bool($resu));
$this->assertTrue(is_array($cat));
//var_dump($res);
//var_dump($cat);
}
public function testDeleteCategory(){
$cat_id=1;
$course_code =null;
$course_db = 'z22COD12A945';
$course_code = 'COURSEX';
$course_db = 'chamilo_COURSEX';
$res = GroupManager::delete_category($cat_id, $course_code);
$this->assertTrue(is_null($res));
$this->assertNull($res);
@ -221,17 +187,17 @@ class TestGroupManager extends UnitTestCase {
}
public function testGetCurrenMaxGroupsPerUser(){
$category_id = null;
$course_code = null;
$course_db='';
$category_id = 2;
$course_code = 'COURSEX';
$course_db= 'chamilo_COURSEX';
$res =GroupManager::get_current_max_groups_per_user($category_id = null, $course_code = null);
$this->assertTrue(is_Null($res));
//var_dump($res);
}
public function testSwapCategoryOrder(){
$id1='2';
$id2=null;
$id1= 1;
$id2= 3;
$res = GroupManager::swap_category_order($id1,$id2);
$this->assertFalse($res);
$this->assertNull($res,true);
@ -239,7 +205,7 @@ class TestGroupManager extends UnitTestCase {
}
public function testGetUsers(){
$group_id='1';
$group_id= 1;
$res =GroupManager::get_users($group_id);
$this->assertTrue(is_array($res));
$this->assertTrue($res ===array());
@ -247,33 +213,26 @@ class TestGroupManager extends UnitTestCase {
}
public function testFillGroups(){
$group_ids='2';
global $_course;
$group_ids= 2;
$res = GroupManager::fill_groups($group_ids);
$this->assertNull($res);
$this->assertEqual($res,0);
//var_dump($res);
}
/*
public function testNumberOfStudents(){
/*
$connection = &new MockDatabase($this);
$connection->setReturnValue('get_course_table', 'dokeos_0001.group_rel_user');
$connection->get_course_table();
$group_id='2';
$_course = api_get_course_info('0001');
$res = $this->gManager->number_of_students($group_id);
$this->assertTrue($res);
public function testNumberOfStudents(){
global $_course;
$group_id= 2;
$res = GroupManager::number_of_students($group_id);
$this->assertFalse($res);
$this->assertTrue(is_string($res));
var_dump($res);
//var_dump($res);
}
*/
public function testMaximumNumberOfStudents(){
$group_id ='2';
$_course = api_get_course_info('0001');
global $_course;
$group_id = 2;
$res =GroupManager::maximum_number_of_students($group_id);
$this->assertTrue($res);
$this->assertTrue(is_string($res));
@ -281,18 +240,18 @@ class TestGroupManager extends UnitTestCase {
}
public function testUserInNumberOfGroups(){
$user_id='1';
$cat_id = '6';
//$_course = api_get_course_info('0001');
global $_course;
$user_id= 1;
$cat_id = 6;
$res = GroupManager::user_in_number_of_groups($user_id,$cat_id);
$this->assertTrue(is_numeric($cat_id));
$this->assertTrue(is_null($res));
$this->assertTrue(is_string($res));
//var_dump($res);
}
public function testIsSelfRegistrationAllowed(){
$user_id='1';
$group_id='6';
$user_id = 1;
$group_id = 6;
$res = GroupManager::is_self_registration_allowed($user_id,$group_id);
$this->assertTrue(is_bool($res));
$this->assertTrue($res === false);
@ -300,8 +259,8 @@ class TestGroupManager extends UnitTestCase {
}
public function testIsSelfUnregistrationAllowed(){
$user_id='2';
$group_id='6';
$user_id = 2 ;
$group_id = 6;
$res =GroupManager::is_self_unregistration_allowed($user_id,$group_id);
$this->assertTrue(is_bool($res));
$this->assertTrue($res === false);
@ -309,19 +268,17 @@ class TestGroupManager extends UnitTestCase {
}
public function testIsSubscribed(){
$dbase = new MockDataBase();
$db_result ='2';
$user_id='2';
$group_id='6';
$db_result = 2;
$user_id = 2;
$group_id = 6;
$res = GroupManager::is_subscribed($user_id, $group_id);
$dbase->expectOnce('Database::fetch_array($res)');
$this->assertTrue(is_bool($res));
//var_dump($res);
}
public function testCanUserSubscribe(){
$user_id='2';
$group_id='2';
global $user_id;
$group_id = 2;
global $_course;
$res = GroupManager::can_user_subscribe($user_id, $group_id);
$this->assertTrue(is_numeric($res));
@ -329,8 +286,8 @@ class TestGroupManager extends UnitTestCase {
}
public function testCanUserUnsubscribe(){
$user_id ='6';
$group_id='6';
global $user_id;
$group_id = 6;
$res = GroupManager::can_user_unsubscribe($user_id, $group_id);
$this->assertTrue(is_bool($res));
$this->assertTrue($res === false);
@ -338,31 +295,31 @@ class TestGroupManager extends UnitTestCase {
}
public function testGetSubscribedUsers(){
$group_id='2';
$group_id = 2;
$res = GroupManager::get_subscribed_users($group_id);
$this->assertTrue(is_array($res));
//var_dump($res);
}
public function testGetSubscribedTutors(){
$group_id='2';
$group_id = 2;
$res = GroupManager::get_subscribed_tutors($group_id);
$this->assertTrue(is_array($res));
//var_dump($res);
}
public function testSubscribeUsers(){
$user_ids = '2';
$group_id= '2';
global $user_ids;
$group_id = 2;
$res = GroupManager::subscribe_users($user_ids, $group_id);
$this->assertTrue(is_numeric($res));
//var_dump($res);
}
public function testSubscribeTutors(){
$user_ids='2';
global $user_id;
$group_id='6';
$res &= GroupManager::subscribe_tutors($user_ids, $group_id);
$res &= GroupManager::subscribe_tutors($user_id, $group_id);
$this->assertTrue(is_numeric($res));
//var_dump($res);
}
@ -376,7 +333,7 @@ class TestGroupManager extends UnitTestCase {
}
public function testUnsubscribeAllUsers(){
$group_ids=array(2,);
$group_ids=array(2);
$res = GroupManager::unsubscribe_all_users($group_ids);
$this->assertTrue(is_bool($res));
//var_dump($res);
@ -390,7 +347,7 @@ class TestGroupManager extends UnitTestCase {
}
public function testIsTutorOfGroup(){
$user_id=2;
global $user_id;
$group_id=2;
$res = GroupManager::is_tutor_of_group($user_id,$group_id);
$this->assertTrue(is_bool($res));
@ -398,7 +355,7 @@ class TestGroupManager extends UnitTestCase {
}
public function testIsUserInGroup(){
$user_id= 2;
global $user_id;
$group_id= 4;
$res =GroupManager::is_user_in_group($user_id, $group_id);
$this->assertTrue(is_bool($res));
@ -414,8 +371,7 @@ class TestGroupManager extends UnitTestCase {
}
public function testIsTutor(){
$user_id = 2;
global $_course;
global $user_id, $_course;
$res = GroupManager::is_tutor($user_id);
$this->assertTrue(is_bool($res));
$this->assertTrue($res === false);
@ -424,8 +380,8 @@ class TestGroupManager extends UnitTestCase {
}
public function testGetGroupIds(){
$course_db='';
$user_id=2;
global $user_id;
$course_db= 'chamilo_COURSEX';
$res = GroupManager::get_group_ids($course_db,$user_id);
$this->assertTrue(is_array($res));
//var_dump($res);
@ -433,28 +389,30 @@ class TestGroupManager extends UnitTestCase {
public function testGetCompleteListOfUsersThatCanBeAddedToGroup(){
global $_course, $_user;
$course_code=0001;
$course_code= 'chamilo_COURSEX';
$group_id=2;
$res = GroupManager::get_complete_list_of_users_that_can_be_added_to_group($course_code, $group_id);
$this->assertTrue(is_null($res));
$this->assertTrue(is_array($res));
$this->assertTrue($res);
//var_dump($res);
}
public function testfilter_duplicates(){
$user_array_in='';
$compare_field='';
$user_array_in = '';
$compare_field = '';
$res = GroupManager::filter_duplicates($user_array_in, $compare_field);
$this->assertTrue(is_array($res));
//var_dump($res);
}
/*
public function testFilterUsersAlreadyInGroup(){
$user_array_in='2';
$group_id=2;
$res = $this->gManager->filter_users_already_in_group($user_array_in, $group_id);
$this->assertTrue(is_array($res));
$user_array_in= 2;
$group_id = 2;
$res = GroupManager::filter_users_already_in_group($user_array_in, $group_id);
$this->assertTrue(is_null($res));
$this->assertNull($res);
//var_dump($res);
}*/
}
public function testFilterOnlyStudents(){
$user_array_in='';
@ -464,7 +422,7 @@ class TestGroupManager extends UnitTestCase {
}
public function testUserHasAccess(){
$user_id='2';
global $user_id;
$group_id='5';
$tool='wiki_state';
$res = GroupManager::user_has_access($user_id, $group_id, $tool);
@ -474,10 +432,27 @@ class TestGroupManager extends UnitTestCase {
}
public function testGetUserGroupName(){
$user_id='';
global $user_id;
$res=GroupManager::get_user_group_name($user_id);
$this->assertTrue(is_array($res));
//var_dump($res);
}
public function TestDeleteCourse(){
$code = 'COURSEX';
$res = CourseManager::delete_course($code);
$path = api_get_path(SYS_PATH).'archive';
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if (strpos($file,$code)!==false) {
if (is_dir($path.'/'.$file)) {
rmdirr($path.'/'.$file);
}
}
}
closedir($handle);
}
}
}
?>

Loading…
Cancel
Save