瀏覽代碼

Fixed the functions for test suite CT#191

Arthur Portugal 15 年之前
父節點
當前提交
be3b9e9b0d
共有 1 個文件被更改,包括 223 次插入190 次删除
  1. 223 190
      tests/main/inc/lib/fileUpload.lib.test.php

+ 223 - 190
tests/main/inc/lib/fileUpload.lib.test.php

@@ -1,14 +1,69 @@
 <?php
-/** To can run this test you need comment "die() This code is in the line 278,1377,1386,1389,1542,1547,1571 file fileUpload.lib.php
- *  @author aportugal arthur.portugal@dokeos.com
- */
-
 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');
 
 class TestFileUpload extends UnitTestCase {
 
+
+/*		
+ 		//Deprecated
+ 		//settings
+		
+		function testset_default_settings() {
+			global $dbTable,$_configuration;
+			global $default_visibility;
+			$upload_path = api_get_path(SYS_PATH).'courses';
+			$filename = 'test.txt';
+			$res= set_default_settings($upload_path,$filename,$filetype="file");
+			$this->assertTrue(is_null($res));
+			//var_dump($res);
+		}
+*/
+		//Creating
+		
+		function testCreateUnexistingDirectory()  {
+			global $_course, $user_id;
+			$to_group_id = 1;
+			$to_user_id = 1;
+			$base_work_dir = api_get_path(SYS_COURSE_PATH).'document/';
+			$desired_dir_name = 'images';
+			$res= create_unexisting_directory($_course,$user_id,$to_group_id,$to_user_id,$base_work_dir,$desired_dir_name);
+			
+			if(!is_null($res)) {
+				$this->assertTrue(is_string($res));
+				$this->assertTrue($res);	
+			} else {
+				$this->assertFalse(is_string($res));
+				} 
+			}
+
+		/**
+		 * Creates a file containing an html redirection to a given url
+		 * @param string $filePath
+		 * @param string $url
+		 * @return void
+		 */
+		function testCreateLinkFile() {
+			$base_work_dir=api_get_path(SYS_COURSE_PATH);
+			$filePath = $base_work_dir.'upload/blog';
+			$dirurl = api_get_path(WEB_COURSE_PATH);
+			$url = $dirurl.'doc.php';
+			$res= create_link_file($filePath, $url);
+			if (!is_numeric($res)) {
+				$this->assertFalse($res);
+			} else {
+				 $this->assertTrue($res);
+			}
+		}
+		
+		/**
+		 * This recursive function can be used during the upgrade process form older versions of Dokeos
+		 * It crawls the given directory, checks if the file is in the DB and adds it if it's not
+		 *
+		 * @param string $base_work_dir
+		 * @param string $current_path, needed for recursivity
+		 */
 		function testAddAllDocumentsInFolderToDatabase() {
 			global $_course, $user_id;
 			$base_work_dir= api_get_path(SYS_PATH).'';
@@ -39,133 +94,29 @@ class TestFileUpload extends UnitTestCase {
 			$this->assertTrue(is_string($res));
 			//var_dump($res);
 		}
-
-		function testApiReplaceLinksInHtml() {
-			$upload_path='/var/www/chamilo1/courses/COURSEX/upload/blog';
-			$full_file_name = 'doc.php';
-			$res=api_replace_links_in_html($upload_path,$full_file_name);
-			$this->assertTrue(is_null($res));
-			//var_dump($res);
-		}
-
-		function testApiReplaceLinksInString() {
-			$upload_path='';
-			$buffer=ob_get_contents();
-			$res=api_replace_links_in_string($upload_path,$buffer);
-			$this->assertTrue(is_string($res));
-			//var_dump($res);
-		}
-
-		function testApiReplaceParameter() {
-			$count = 0;
-			$matches = array();
-			$href_list=array();
-			$file_path_list[] = $matches[1];
-			$upload_path='';
-			$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);
-			$param_name="src";
-			$res=api_replace_parameter($upload_path, $buffer, $param_name="src");
-			$this->assertTrue(is_string($res));
-			//var_dump($res);
-		}
+		
+		//build
 
 		function testBuildMissingFilesForm() {
 			global	$_course;
 			$missing_files = array();
-			$upload_path=api_get_path(SYS_COURSE_PATH).'/COURSEX/document/image';
+			$upload_path=api_get_path(SYS_COURSE_PATH).'document/image';
 			$file_name = 'board.jpg';
 			$res=build_missing_files_form($missing_files,$upload_path,$file_name);
 			$this->assertTrue(is_string($res));
 			//var_dump($res);
 		}
 
+		//check
+
 		function testCheckForMissingFiles() {
 			$file='';
 			$res=check_for_missing_files($file);
 			$this->assertTrue(is_bool($res));
 		}
 
-		function testCleanUpFilesInZip() {
-			$p_event='';
-			$p_header['filename']='';
-			$res=clean_up_files_in_zip($p_event, &$p_header);
-			$this->assertTrue(is_numeric($res));
-			//var_dump($res);
-		}
-
-		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));
-
-			
-		}
-
-		/** To can test this function you need to comment "die ('can not create file')"
-		 *  $res return void/
-		 *
-		 */
-
-		function testCreateLinkFile() {
-			
-			$filePath = api_get_path(SYS_PATH).'documentation/README.txt';
-			$url = 'http://www.chamilo.com';
-			$res= create_link_file($filePath, $url);
-			
-			if (!is_numeric($res)) {
-				$this->assertFalse($res);
-			}
-			else{
-				 $this->assertTrue($res);
-			}		
-			//var_dump($res);	
-		}
-
-		function testCreateUnexistingDirectory()  {
-			global $_course, $user_id;
-			$to_group_id = 1;
-			$to_user_id = 1;
-			$base_work_dir = api_get_path(SYS_COURSE_PATH).'COURSEX/document';
-			$desired_dir_name = 'images';
-			$res= create_unexisting_directory($_course,$user_id,$to_group_id,$to_user_id,$base_work_dir,$desired_dir_name);
-			
-			if(is_string($res)){
-				$this->assertTrue(is_string($res));
-				$this->assertTrue($res);	
-			} else {
-				$this->assertTrue(is_bool($res));
-				$this->assertFalse(is_string($res));
-			} 
- 			//var_dump($res);
-			}
-
-
-		function testDirTotalSpace() {
-			$dirPath= api_get_path(SYS_COURSE_PATH).'COURSEX/document/';
-			$res= dir_total_space($dirPath);
-			$this->assertTrue(is_numeric($res));
-			$this->assertTrue($res);
-			//var_dump($res);
-		}
-
-		function testDisableDangerousFile() {
-			$filename = 'index.php';
-			$res= disable_dangerous_file($filename);
-			$this->assertTrue(is_string($res));
-			//var_dump($res);
-		}
-
-
+		//space
+		
 		function testdocuments_total_space() {
 			$to_group_id='0';
 			$res= documents_total_space($to_group_id);
@@ -184,19 +135,31 @@ class TestFileUpload extends UnitTestCase {
 			//var_dump($res);
 		}
 
-		function enough_space() {
+		function testenough_space() {
 			$file_size='';
 			$max_dir_space='';
 			$res= enough_space($file_size, $max_dir_space);
 			$this->assertTrue(is_bool($res));
 			//var_dump($res);
 		}
-
+		
+		function testDirTotalSpace() {
+			$dirPath= api_get_path(SYS_COURSE_PATH).'document/';
+			$res= dir_total_space($dirPath);
+			if(!is_string($res)) {
+			$this->assertTrue(is_numeric($res));
+			}
+		}
+		
+		//filter
+		
 		function testfilter_extension() {
 			$filename='index.php';
 			$res= filter_extension($filename);
 			$this->assertTrue(is_numeric($res));			
 		}
+		
+		//get
 
 		function testget_document_title() {
 			$name='';
@@ -212,30 +175,7 @@ class TestFileUpload extends UnitTestCase {
 			//var_dump($res);
 		}
 
-		function testhandle_uploaded_document() {
-			global $_course;
-			$uploaded_file='';
-			$base_work_dir='';
-			$upload_path='';
-			$user_id='01';
-			$to_group_id=0;
-			$to_user_id=NULL;
-			$maxFilledSpace='';
-			$unzip=0;
-			$what_if_file_exists='';
-			$output=true;
-			$clean_name = disable_dangerous_file($clean_name);
-			$where_to_save = $base_work_dir.$upload_path;
-			$new_name = unique_name($where_to_save, $clean_name);
-			$new_file_path = $upload_path.$new_name;
-			$clean_name = disable_dangerous_file($clean_name);
-			$file_path = $upload_path.$clean_name;
-			ob_start();
-			$res= handle_uploaded_document($_course,$uploaded_file,$base_work_dir,$upload_path,$user_id,$to_group_id=0,$to_user_id=NULL,$maxFilledSpace='',$unzip=0,$what_if_file_exists='',$output=true);
-			$this->assertTrue(is_null($res));
-			ob_end_clean();
-			//var_dump($res);
-		}
+		//access
 
 		function testhtaccess2txt() {
 			$filename = 'readme.txt';
@@ -244,20 +184,14 @@ class TestFileUpload extends UnitTestCase {
 			//var_dump($res);
 		}
 
-		function testitem_property_update_on_folder() {
-			global $_course, $user_id;
-			$path=api_get_path(SYS_COURSE_PATH).'COURSEX/document/license.txt';
-			$res= item_property_update_on_folder($_course,$path,$user_id);
-			$this->assertTrue(is_null($res));
-			//var_dump($res);
-		}
-
+		//moving
+		
 		function testmove_uploaded_file_collection_into_directory() {
 			global $_course;
 			$uploaded_file_collection=array();
-			$base_work_dir='';
+			$base_work_dir=api_get_path(SYS_COURSE_PATH).'upload/';
 			$missing_files_dir='';
-			$user_id='';
+			$user_id=1;
 			$to_group_id='';
 			$to_user_id='';
 			$max_filled_space='';
@@ -265,7 +199,9 @@ class TestFileUpload extends UnitTestCase {
 			$this->assertTrue(is_null($res));
 			//var_dump($res);
 		}
-
+		
+		//php?
+		
 		function testphp2phps () {
 			$fileName = 'index.php';
 			$res= php2phps($fileName);
@@ -273,28 +209,11 @@ class TestFileUpload extends UnitTestCase {
 			//var_dump($res);
 		}
 
-		function testprocess_uploaded_file() {
-			$uploaded_file='';
-			ob_start();
-			$res= process_uploaded_file($uploaded_file);
-			ob_end_clean();
-			$this->assertTrue(is_bool($res));
-			
-		}
-
-		function testreplace_img_path_in_html_file() {
-			global $_course;
-			$originalImgPath='';
-			$newImgPath='';
-			$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);
-		}
+		//searching
 
 		function testsearch_img_from_html() {
 			$imgFilePath = array();
-			$htmlFile= 'file:///var/www/chamilo/documentation/credits.html';
+			$htmlFile= 'file:///var/www/chamilotest/documentation/credits.html';
 			$res= search_img_from_html($htmlFile);
 			if(is_array($res)){
 			$this->assertTrue(is_array($res));
@@ -303,17 +222,15 @@ class TestFileUpload extends UnitTestCase {
 			}
 			//var_dump($res);
 		}
-
-		function testset_default_settings() {
-			global $_course, $_configuration, $cidReq;
-			global $default_visibility, $dbTable;
-			$dbTable = Database::get_course_table(TABLE_DOCUMENT);
-			$upload_path = api_get_path(SYS_COURSE_PATH).'COURSEX/document';
-			$filetype="file";
-			$filename = substr($filename,0,-1);
-			$res= set_default_settings($upload_path,$filename,$filetype);
-			$this->assertTrue(is_null($res));
-			//var_dump($res);
+		
+		//uploading
+		
+		function testprocess_uploaded_file() {
+			$uploaded_file='';
+			ob_start();
+			$res= process_uploaded_file($uploaded_file);
+			ob_end_clean();
+			$this->assertTrue(is_bool($res));
 		}
 		
 		function testtreat_uploaded_file() {
@@ -327,7 +244,53 @@ class TestFileUpload extends UnitTestCase {
 			$this->assertTrue(is_bool($res));
 			//var_dump($res);
 		}
-
+		
+		function testhandle_uploaded_document() {
+			global $_course;
+			$uploaded_file='';
+			$base_work_dir='';
+			$upload_path='';
+			$user_id=1;
+			$to_group_id=0;
+			$to_user_id=NULL;
+			$maxFilledSpace='';
+			$unzip=0;
+			$what_if_file_exists='';
+			$output=true;
+			$clean_name = disable_dangerous_file($clean_name);
+			$where_to_save = $base_work_dir.$upload_path;
+			$new_name = unique_name($where_to_save, $clean_name);
+			$new_file_path = $upload_path.$new_name;
+			$clean_name = disable_dangerous_file($clean_name);
+			$file_path = $upload_path.$clean_name;
+			ob_start();
+			$res= handle_uploaded_document($_course,$uploaded_file,$base_work_dir,$upload_path,$user_id,$to_group_id=0,$to_user_id=NULL,$maxFilledSpace='',$unzip=0,$what_if_file_exists='',$output=true);
+			$this->assertTrue(is_null($res));
+			ob_end_clean();
+			//var_dump($res);
+		}
+	
+		//updating
+		
+		function testupdate_existing_document() {
+			$_course='';
+			$document_id='';
+			$filesize='';
+			$res= update_existing_document($_course,$document_id,$filesize,$readonly=0);
+			$this->assertTrue(is_bool($res));
+			//var_dump($res);
+		}
+		
+		function testitem_property_update_on_folder() {
+			global $_course, $user_id;
+			$path=api_get_path(SYS_COURSE_PATH).'document/license.txt';
+			$res= item_property_update_on_folder($_course,$path,$user_id);
+			$this->assertTrue(is_null($res));
+			//var_dump($res);
+		}
+		
+		//unique name
+		
 		function testunique_name() {
 			$path='';
 			$name='';
@@ -335,6 +298,8 @@ class TestFileUpload extends UnitTestCase {
 			$this->assertTrue(is_string($res));
 			//var_dump($res);
 		}
+		
+		//unzipping
 
 		function testunzip_uploaded_document() {
 			//require_once(api_get_path(LIBRARY_PATH).'/pclzip/pclzip.lib.php');
@@ -358,20 +323,88 @@ class TestFileUpload extends UnitTestCase {
 			$uploadedFile   = 'README.txt';
 			$uploadPath     = api_get_path(SYS_PATH).$_course.'/document';
 			$baseWorkDir    = api_get_path(SYS_PATH);
-			$maxFilledSpace = 10;
+			$maxFilledSpace = 1000;
 			$res= unzip_uploaded_file($uploadedFile, $uploadPath, $baseWorkDir, $maxFilledSpace);
 			$this->assertTrue(is_bool($res));
 			//var_dump($res);
 		}
+		
+		//disable
 
-		function testupdate_existing_document() {
-			$_course='';
-			$document_id='';
-			$filesize='';
-			$res= update_existing_document($_course,$document_id,$filesize,$readonly=0);
-			$this->assertTrue(is_bool($res));
+		function testDisableDangerousFile() {
+			$filename = 'index.php';
+			$res= disable_dangerous_file($filename);
+			$this->assertTrue(is_string($res));
+			//var_dump($res);
+		}
+		
+		//replace
+
+		function testreplace_img_path_in_html_file() {
+			global $_course;
+			$originalImgPath='';
+			$newImgPath='';
+			$htmlFile='file:///var/www/chamilotest/documentation/credits.html';
+			$res= replace_img_path_in_html_file($originalImgPath, $newImgPath, $htmlFile);
+			$this->assertTrue(is_null($res));
+			//var_dump($res);
+		}
+		
+		function testApiReplaceLinksInHtml() {
+			$base_work_dir=api_get_path(SYS_COURSE_PATH);
+			$upload_path=$base_work_dir.'upload/blog';
+			$full_file_name = 'doc.php';
+			$res=api_replace_links_in_html($upload_path,$full_file_name);
+			$this->assertTrue(is_null($res));
+			//var_dump($res);
+		}
+
+		function testApiReplaceLinksInString() {
+			$base_work_dir=api_get_path(SYS_COURSE_PATH);
+			$upload_path=$base_work_dir.'upload/blog';
+			$buffer=ob_get_contents();
+			$res=api_replace_links_in_string($upload_path,$buffer);
+			$this->assertTrue(is_string($res));
 			//var_dump($res);
 		}
+
+		function testApiReplaceParameter() {
+			$count = 0;
+			$matches = array();
+			$href_list=array();
+			$file_path_list[] = $matches[1];
+			$base_work_dir=api_get_path(SYS_COURSE_PATH);
+			$upload_path=$base_work_dir.'upload/blog';
+			$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);
+			$param_name="src";
+			$res=api_replace_parameter($upload_path, $buffer, $param_name="src");
+			$this->assertTrue(is_string($res));
+			//var_dump($res);
+		}
+		
+		//clenaning
+
 		
+		function testCleanUpFilesInZip() {
+			$p_event='';
+			$p_header['filename']='';
+			$res=clean_up_files_in_zip($p_event, &$p_header);
+			$this->assertTrue(is_numeric($res));
+			//var_dump($res);
+		}
+
+		function testCleanUpPath() {
+			$base_work_dir=api_get_path(SYS_COURSE_PATH);
+			$path = $base_work_dir.'upload/blog';			
+			$res = clean_up_path($path);
+			$this->assertTrue(is_numeric($res));
+
+		}
 }
 ?>