|
|
|
@ -4,7 +4,7 @@ |
|
|
|
|
*/ |
|
|
|
|
require_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php'); |
|
|
|
|
require_once(api_get_path(LIBRARY_PATH).'document.lib.php'); |
|
|
|
|
|
|
|
|
|
require_once(api_get_path(LIBRARY_PATH).'/pclzip/pclzip.lib.php'); |
|
|
|
|
Mock::generate('DocumentManager'); |
|
|
|
|
Mock::generate('Display'); |
|
|
|
|
Mock::generate('Database'); |
|
|
|
@ -12,18 +12,19 @@ Mock::generate('Database'); |
|
|
|
|
class TestFileUpload extends UnitTestCase { |
|
|
|
|
|
|
|
|
|
function testAddAllDocumentsInFolderToDatabase() { |
|
|
|
|
$docman = new MockDocumentManager(); |
|
|
|
|
//$docman = new MockDocumentManager(); |
|
|
|
|
$_course=''; |
|
|
|
|
$user_id=''; |
|
|
|
|
$base_work_dir=''; |
|
|
|
|
$path = $base_work_dir; |
|
|
|
|
$handle=opendir($path); |
|
|
|
|
$file=readdir($handle); |
|
|
|
|
$safe_file=replace_dangerous_char($file); |
|
|
|
|
//$path = $base_work_dir; |
|
|
|
|
//$handle=opendir($path); |
|
|
|
|
//$file=readdir($handle); |
|
|
|
|
//$safe_file=replace_dangerous_char($file); |
|
|
|
|
$res=add_all_documents_in_folder_to_database($_course,$user_id,$base_work_dir,$current_path='',$to_group_id=0); |
|
|
|
|
$docman->expectOnce('DocumentManager::get_document_id',array($_course, $current_path.'/'.$safe_file)); |
|
|
|
|
$this->assertTrue(is_object($docman)); |
|
|
|
|
//var_dump($docman); |
|
|
|
|
//$docman->expectOnce('DocumentManager::get_document_id',array($_course, $current_path.'/'.$safe_file)); |
|
|
|
|
//$this->assertTrue(is_object($docman)); |
|
|
|
|
$this->assertTrue(is_null($res)); |
|
|
|
|
var_dump($res); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function testAddDocument() { |
|
|
|
@ -74,7 +75,7 @@ class TestFileUpload extends UnitTestCase { |
|
|
|
|
$replaceWhat[$count] = $href_list[$count]; |
|
|
|
|
/** To can test this function you need to comment "die ('can not create file')" |
|
|
|
|
* $res return void |
|
|
|
|
*/ |
|
|
|
|
*/ |
|
|
|
|
$replaceBy[$count] = " $param_name=\"" . $file_path_list[$count] . "\" target =\"_top\""; |
|
|
|
|
$replaceBy[$count] = $replaceWhat[$count]; |
|
|
|
|
$buffer = str_replace($replaceWhat, $replaceBy, $buffer); |
|
|
|
@ -112,12 +113,16 @@ class TestFileUpload extends UnitTestCase { |
|
|
|
|
//var_dump($res); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function testCleanUpPath(&$path) { |
|
|
|
|
$path_array = explode('/',$path); |
|
|
|
|
$path = implode('/',$path_array); |
|
|
|
|
$res=clean_up_path(&$path); |
|
|
|
|
function testCleanUpPath() { |
|
|
|
|
|
|
|
|
|
$path = '/var/tmp/archivo123.txt'; |
|
|
|
|
//$path_array = explode('/',$path); |
|
|
|
|
//$path = implode('/',$path_array); |
|
|
|
|
|
|
|
|
|
$res = clean_up_path($path); |
|
|
|
|
$this->assertTrue(is_numeric($res)); |
|
|
|
|
//var_dump($res); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** To can test this function you need to comment "die ('can not create file')" |
|
|
|
@ -126,11 +131,18 @@ class TestFileUpload extends UnitTestCase { |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
function testCreateLinkFile() { |
|
|
|
|
$filePath=''; |
|
|
|
|
$url=''; |
|
|
|
|
|
|
|
|
|
$filePath='/var/tmp/archivo123.txt'; |
|
|
|
|
$url='http://www.dokeos.com'; |
|
|
|
|
$res= create_link_file($filePath, $url); |
|
|
|
|
$this->assertTrue(is_null($res)); |
|
|
|
|
//var_dump($res); |
|
|
|
|
|
|
|
|
|
if (!is_numeric($res)) { |
|
|
|
|
$this->assertFalse($res); |
|
|
|
|
} |
|
|
|
|
else{ |
|
|
|
|
$this->assertTrue($res); |
|
|
|
|
} |
|
|
|
|
//var_dump($res); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function testCreateUnexistingDirectory() { |
|
|
|
@ -142,6 +154,7 @@ class TestFileUpload extends UnitTestCase { |
|
|
|
|
$desired_dir_name=''; |
|
|
|
|
$res= create_unexisting_directory($_course,$user_id,$to_group_id,$to_user_id,$base_work_dir,$desired_dir_name); |
|
|
|
|
$this->assertTrue(is_bool($res)); |
|
|
|
|
//var_dump($res); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function testDirTotalSpace() { |
|
|
|
@ -189,8 +202,7 @@ class TestFileUpload extends UnitTestCase { |
|
|
|
|
function testfilter_extension() { |
|
|
|
|
$filename=''; |
|
|
|
|
$res= filter_extension($filename); |
|
|
|
|
$this->assertTrue(is_numeric($res)); |
|
|
|
|
//var_dump($res); |
|
|
|
|
$this->assertTrue(is_numeric($res)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function testget_document_title() { |
|
|
|
@ -213,7 +225,7 @@ class TestFileUpload extends UnitTestCase { |
|
|
|
|
$uploaded_file=''; |
|
|
|
|
$base_work_dir=''; |
|
|
|
|
$upload_path=''; |
|
|
|
|
$user_id=''; |
|
|
|
|
$user_id='01'; |
|
|
|
|
$to_group_id=0; |
|
|
|
|
$to_user_id=NULL; |
|
|
|
|
$maxFilledSpace=''; |
|
|
|
@ -304,16 +316,21 @@ class TestFileUpload extends UnitTestCase { |
|
|
|
|
global $_course; |
|
|
|
|
$originalImgPath=''; |
|
|
|
|
$newImgPath=''; |
|
|
|
|
$htmlFile=''; |
|
|
|
|
$htmlFile='file:///var/www/chamilo/documentation/credits.html'; |
|
|
|
|
$res= replace_img_path_in_html_file($originalImgPath, $newImgPath, $htmlFile); |
|
|
|
|
$this->assertTrue(is_null($res)); |
|
|
|
|
//var_dump($res); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function testsearch_img_from_html() { |
|
|
|
|
$htmlFile=''; |
|
|
|
|
$imgFilePath = array(); |
|
|
|
|
$htmlFile= 'file:///var/www/chamilo/documentation/credits.html'; |
|
|
|
|
$res= search_img_from_html($htmlFile); |
|
|
|
|
if(is_array($res)){ |
|
|
|
|
$this->assertTrue(is_array($res)); |
|
|
|
|
}else { |
|
|
|
|
$this->assertTrue(is_null($res)); |
|
|
|
|
} |
|
|
|
|
//var_dump($res); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -386,6 +403,6 @@ class TestFileUpload extends UnitTestCase { |
|
|
|
|
$docman->expectOnce(Database::get_course_table(TABLE_DOCUMENT,$_course['dbName'])); |
|
|
|
|
$this->assertTrue(is_bool($res)); |
|
|
|
|
//var_dump($res); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
?> |
|
|
|
|