cvargas 15 years ago
parent
commit
911bb35456

+ 6 - 3
main/inc/lib/fileUpload.lib.php

@@ -1527,10 +1527,13 @@ function create_link_file($filePath, $url)
 				  .'<body>'
 				  .'</body>'
 				  .'</html>';
-	if (!($fp = fopen ($filePath, 'w'))) {
-		return false;
+	if(file_exists($filePath)){
+		if (!($fp = fopen ($filePath, 'w'))) {
+			return false;
+		}
+	
+		return fwrite($fp, $fileContent); 	
 	}
-	return fwrite($fp, $fileContent); 	 		 
 }
 
 //------------------------------------------------------------------------------

+ 179 - 141
main/inc/lib/main_api.lib.php

@@ -135,7 +135,7 @@ define('TOOL_GRADEBOOK','gradebook');
 define('TOOL_NOTEBOOK','notebook');
 define('TOOL_ATTENDANCE','attendance');
 
-// CONSTANTS defining dokeos sections
+// CONSTANTS defining Chamilo interface sections
 define('SECTION_CAMPUS', 'mycampus');
 define('SECTION_COURSES', 'mycourses');
 define('SECTION_MYPROFILE', 'myprofile');
@@ -250,7 +250,9 @@ require_once dirname(__FILE__).'/internationalization.lib.php';
 */
 
 /**
- *	Returns a full path to a certain Dokeos area, which you specify through a parameter.
+ *	Returns a path to a certain resource within the Chamilo area, specifyed through a parameter.
+ *	Also, this function provides conversion between path types, in this case the input path points inside the Chamilo area too.
+ *
  *	See $_configuration['course_folder'] in the configuration.php to alter the WEB_COURSE_PATH and SYS_COURSE_PATH parameters.
  *	@param string $type				The requested path type (a defined constant), see the examples.
  *	@param string $path (optional)	A path which type is to be converted. Also, it may be a defined constant for a path.
@@ -260,62 +262,62 @@ require_once dirname(__FILE__).'/internationalization.lib.php';
  *	A terminology note:
  *	The defined constants used by this function contain the abbreviations WEB, REL, SYS with the following meaning for types:
  *	WEB - an absolute URL (we often call it web-path),
- *	example: http://www.mydokeos.com/dokeos/courses/COURSE01/document/lesson01.html;
+ *	example: http://www.mychamilo.org/chamilo/courses/COURSE01/document/lesson01.html;
  *	REL - represents a semi-absolute URL - a web-path, which is relative to the root web-path of the server, without server's base,
- *	example: /dokeos/courses/COURSE01/document/lesson01.html;
+ *	example: /chamilo/courses/COURSE01/document/lesson01.html;
  *	SYS - represents an absolute path inside the scope of server's file system,
- *	/var/www/dokeos/courses/COURSE01/document/lesson01.html or
- *	C:/Inetpub/wwwroot/dokeos/courses/COURSE01/document/lesson01.html.
+ *	/var/www/chamilo/courses/COURSE01/document/lesson01.html or
+ *	C:/Inetpub/wwwroot/chamilo/courses/COURSE01/document/lesson01.html.
  *	In some abstract sense we can consider these three path types as absolute.
  *
  *	Notes about the current behaviour model:
  *	1. Windows back-slashes are converted to slashes in the result.
  *	2. A semi-absolute web-path is detected by its leading slash. On Linux systems, absolute system paths start with
  *	a slash too, so an additional check about presense of leading system server base is implemented. For example, the function is
- *	able to distinguish type difference between /var/www/dokeos/courses/ (SYS) and /dokeos/courses/ (REL).
+ *	able to distinguish type difference between /var/www/chamilo/courses/ (SYS) and /chamilo/courses/ (REL).
  *	3. The function api_get_path() returns only these three types of paths, which in some sense are absolute. The function has
  *	no a mechanism for processing relative web/system paths, such as: lesson01.html, ./lesson01.html, ../css/my_styles.css.
  *	It has not been identified as needed yet.
  *	4. Also, resolving the meta-symbols "." and ".." withiin paths has not been implemented, it is to be identified as needed.
  *
  * 	@example
- *	Assume that your server root is /var/www/ dokeos is installed in a subfolder dokeos/ and the URL of your campus is http://www.mydokeos.com
+ *	Assume that your server root is /var/www/ , Chamilo is installed in a subfolder chamilo/ and the URL of your campus is http://www.mychamilo.org
  * 	The other configuration paramaters have not been changed.
  *
  * 	This is how we can retireve mosth used paths, for common purpose:
- *	api_get_path(WEB_SERVER_ROOT_PATH)			http://www.mydokeos.com/
- *	api_get_path(SYS_SERVER_ROOT_PATH)			/var/www/ - This is the physical folder where the system Dokeos has been placed. It is not always equal to $_SERVER['DOCUMENT_ROOT'].
- * 	api_get_path(WEB_PATH)						http://www.mydokeos.com/dokeos/
- * 	api_get_path(SYS_PATH)						/var/www/dokeos/
- * 	api_get_path(REL_PATH)						/dokeos/
- * 	api_get_path(WEB_COURSE_PATH)				http://www.mydokeos.com/dokeos/courses/
- * 	api_get_path(SYS_COURSE_PATH)				/var/www/dokeos/courses/
- *	api_get_path(REL_COURSE_PATH)				/dokeos/courses/
- * 	api_get_path(REL_CODE_PATH)					/dokeos/main/
- * 	api_get_path(WEB_CODE_PATH)					http://www.mydokeos.com/dokeos/main/
- * 	api_get_path(SYS_CODE_PATH)					/var/www/dokeos/main/
- * 	api_get_path(SYS_LANG_PATH)					/var/www/dokeos/main/lang/
- * 	api_get_path(WEB_IMG_PATH)					http://www.mydokeos.com/dokeos/main/img/
- *	api_get_path(WEB_CSS_PATH)					http://www.mydokeos.com/dokeos/main/css/
+ *	api_get_path(WEB_SERVER_ROOT_PATH)			http://www.mychamilo.org/
+ *	api_get_path(SYS_SERVER_ROOT_PATH)			/var/www/ - This is the physical folder where the system Chamilo has been placed. It is not always equal to $_SERVER['DOCUMENT_ROOT'].
+ * 	api_get_path(WEB_PATH)						http://www.mychamilo.org/chamilo/
+ * 	api_get_path(SYS_PATH)						/var/www/chamilo/
+ * 	api_get_path(REL_PATH)						/chamilo/
+ * 	api_get_path(WEB_COURSE_PATH)				http://www.mychamilo.org/chamilo/courses/
+ * 	api_get_path(SYS_COURSE_PATH)				/var/www/chamilo/courses/
+ *	api_get_path(REL_COURSE_PATH)				/chamilo/courses/
+ * 	api_get_path(REL_CODE_PATH)					/chamilo/main/
+ * 	api_get_path(WEB_CODE_PATH)					http://www.mychamilo.org/chamilo/main/
+ * 	api_get_path(SYS_CODE_PATH)					/var/www/chamilo/main/
+ * 	api_get_path(SYS_LANG_PATH)					/var/www/chamilo/main/lang/
+ * 	api_get_path(WEB_IMG_PATH)					http://www.mychamilo.org/chamilo/main/img/
+ *	api_get_path(WEB_CSS_PATH)					http://www.mychamilo.org/chamilo/main/css/
  * 	api_get_path(GARBAGE_PATH)					Deprecated?
- * 	api_get_path(WEB_PLUGIN_PATH)				http://www.mydokeos.com/dokeos/plugin/
- * 	api_get_path(SYS_PLUGIN_PATH)				/var/www/dokeos/plugin/
- * 	api_get_path(WEB_ARCHIVE_PATH)				http://www.mydokeos.com/dokeos/archive/
- * 	api_get_path(SYS_ARCHIVE_PATH)				/var/www/dokeos/archive/
- *	api_get_path(INCLUDE_PATH)					/var/www/dokeos/main/inc/
- * 	api_get_path(WEB_LIBRARY_PATH)				http://www.mydokeos.com/dokeos/main/inc/lib/
- * 	api_get_path(LIBRARY_PATH)					/var/www/dokeos/main/inc/lib/
- * 	api_get_path(CONFIGURATION_PATH)			/var/www/dokeos/main/inc/conf/
+ * 	api_get_path(WEB_PLUGIN_PATH)				http://www.mychamilo.org/chamilo/plugin/
+ * 	api_get_path(SYS_PLUGIN_PATH)				/var/www/chamilo/plugin/
+ * 	api_get_path(WEB_ARCHIVE_PATH)				http://www.mychamilo.org/chamilo/archive/
+ * 	api_get_path(SYS_ARCHIVE_PATH)				/var/www/chamilo/archive/
+ *	api_get_path(INCLUDE_PATH)					/var/www/chamilo/main/inc/
+ * 	api_get_path(WEB_LIBRARY_PATH)				http://www.mychamilo.org/chamilo/main/inc/lib/
+ * 	api_get_path(LIBRARY_PATH)					/var/www/chamilo/main/inc/lib/
+ * 	api_get_path(CONFIGURATION_PATH)			/var/www/chamilo/main/inc/conf/
  *
  *	This is how we retrieve paths of "registerd" resource files (scripts, players, etc.):
- *	api_get_path(TO_WEB, FLASH_PLAYER_AUDIO)	http://www.mydokeos.com/dokeos/main/inc/lib/mediaplayer/player.swf
- *	api_get_path(TO_WEB, FLASH_PLAYER_VIDEO)	http://www.mydokeos.com/dokeos/main/inc/lib/mediaplayer/player.swf
- *	api_get_path(TO_SYS, SCRIPT_SWFOBJECT)		/var/www/dokeos/main/inc/lib/swfobject/swfobject.js
- *	api_get_path(TO_REL, SCRIPT_ASCIIMATHML)	/dokeos/main/inc/lib/asciimath/ASCIIMathML.js
+ *	api_get_path(TO_WEB, FLASH_PLAYER_AUDIO)	http://www.mychamilo.org/chamilo/main/inc/lib/mediaplayer/player.swf
+ *	api_get_path(TO_WEB, FLASH_PLAYER_VIDEO)	http://www.mychamilo.org/chamilo/main/inc/lib/mediaplayer/player.swf
+ *	api_get_path(TO_SYS, SCRIPT_SWFOBJECT)		/var/www/chamilo/main/inc/lib/swfobject/swfobject.js
+ *	api_get_path(TO_REL, SCRIPT_ASCIIMATHML)	/chamilo/main/inc/lib/asciimath/ASCIIMathML.js
  *	...
  *
  *	We can convert arbitrary paths, that are not registered (no defined constant).
- *	For guaranteed result, these paths should point inside the systen Dokeos.
+ *	For guaranteed result, these paths should point inside the system Chamilo.
  *	Some random examples:
  *	api_get_path(TO_WEB, $_SERVER['REQUEST_URI'])
  *	api_get_path(TO_SYS, $_SERVER['PHP_SELF'])
@@ -467,10 +469,10 @@ function api_get_path($path_type, $path = null) {
 		$paths[WEB_PLUGIN_PATH] 	= $paths[WEB_PATH].$paths[WEB_PLUGIN_PATH];
 		$paths[SYS_ARCHIVE_PATH] 	= $paths[SYS_PATH].$paths[SYS_ARCHIVE_PATH];
 		$paths[WEB_ARCHIVE_PATH] 	= $paths[WEB_PATH].$paths[WEB_ARCHIVE_PATH];
-		// A change for Dokeos 1.8.6.2
+		// A change as of Chamilo 1.8.6.2
 		// Calculation in the previous way does not rely on configuration settings and in some cases gives unexpected results.
 		//$paths[INCLUDE_PATH] = $include_path_sys; // Old behaviour, Dokeos 1.8.6.1.
-		$paths[INCLUDE_PATH] 		= $paths[SYS_CODE_PATH].$paths[INCLUDE_PATH]; // New behaviour, coherrent with the model, Dokeos 1.8.6.2.
+		$paths[INCLUDE_PATH] 		= $paths[SYS_CODE_PATH].$paths[INCLUDE_PATH]; // New behaviour, coherrent with the model, Chamilo 1.8.6.2.
 		//
 		$paths[LIBRARY_PATH] 		= $paths[SYS_CODE_PATH].$paths[LIBRARY_PATH];
 		$paths[CONFIGURATION_PATH] 	= $paths[SYS_CODE_PATH].$paths[CONFIGURATION_PATH];
@@ -526,16 +528,16 @@ function api_get_path($path_type, $path = null) {
 		$path = substr($path, 0, $pos);
 	}
 
-	// Detection of the input path type. Conversion to semi-absolute type ( /dokeos/main/inc/.... ).
+	// Detection of the input path type. Conversion to semi-absolute type ( /chamilo/main/inc/.... ).
 
 	if (preg_match(VALID_WEB_PATH, $path)) {
 
 		// A special case: When a URL points to the document download script directly, without
 		// mod-rewrite translation, we have to translate it into an "ordinary" web path.
 		// For example:
-		// http://localhost/dokeos/main/document/download.php?doc_url=/image.png&cDir=/
+		// http://localhost/chamilo/main/document/download.php?doc_url=/image.png&cDir=/
 		// becomes
-		// http://localhost/dokeos/courses/TEST/document/image.png
+		// http://localhost/chamilo/courses/TEST/document/image.png
 		// TEST is a course directory name, so called "system course code".
 		if (strpos($path, 'download.php') !== false) { // Fast detection first.
 			$path = urldecode($path);
@@ -873,7 +875,7 @@ function api_get_real_course_id() {
  *
  * This function relies on api_get_course_info()
  * @param	string	The course code - optional (takes it from session if not given)
- * @return	string	The directory where the course is located inside the Dokeos "courses" directory
+ * @return	string	The directory where the course is located inside the Chamilo "courses" directory
  * @author	Yannick Warnier <yannick.warnier@dokeos.com>
  */
 function api_get_course_path($course_code = null) {
@@ -999,7 +1001,7 @@ function api_get_course_info($course_code = null) {
 */
 
 /**
- * Start the Dokeos session.
+ * Start the Chamilo session.
  *
  * The default lifetime for session is set here. It is not possible to have it
  * as a database setting as it is used before the database connection has been made.
@@ -2478,7 +2480,7 @@ function api_item_property_update($_course, $tool, $item_id, $lastedit_type, $us
  * @param int 		id of the item itself, linked to key of every tool ('id', ...), "*" = all items of the tool
  */
 function api_get_item_property_id ($course_code, $tool, $ref) {
-	
+
 	$course_info = api_get_course_info($course_code);
 	$tool 		 = Database::escape_string($tool);
 	$ref 		 = intval($ref);
@@ -2836,47 +2838,74 @@ function api_time_to_hms($seconds) {
 	return "$hours:$min:$sec";
 }
 
-// TODO: This function is to be simplified. File access modes to be implemented.
+/*
+==============================================================================
+		FILE SYSTEM RELATED FUNCTIONS
+==============================================================================
+*/
+
 /**
- * function adapted from a php.net comment
- * copy recursively a folder
- * @param the source folder
- * @param the dest folder
- * @param an array of excluded file_name (without extension)
- * @param copied_files the returned array of copied files
+ * Returns the permissions to be assigned to every newly created directory by the web-server.
+ * The returnd value is based on the platform administrator's setting "Administration > Configuration settings > Security > Permissions for new directories".
+ * @return int		Returns the permissions in the format "Owner-Group-Others, Read-Write-Execute", as an integer value.
  */
-
-function copyr($source, $dest, $exclude = array(), $copied_files = array()) {
-	// Simple copy for a file
-	if (is_file($source)) {
-		$path_info = pathinfo($source);
-		if (!in_array($path_info['filename'], $exclude)) {
-			copy($source, $dest);
-		}
-		return;
+function api_get_permissions_for_new_directories() {
+	static $permissions;
+	if (!isset($permissions)) {
+		$permissions = trim(api_get_setting('permissions_for_new_directories'));
+		// The default value 0777 is according to that in the platform administration panel after fresh system installation.
+		$permissions = octdec(!empty($permissions) ? $permissions : '0777');
 	}
+	return $permissions;
+}
 
-	// Make destination directory
-	if (!is_dir($dest)) {
-		mkdir($dest);
+/**
+ * Returns the permissions to be assigned to every newly created directory by the web-server.
+ * The returnd value is based on the platform administrator's setting "Administration > Configuration settings > Security > Permissions for new files".
+ * @return int		Returns the permissions in the format "Owner-Group-Others, Read-Write-Execute", as an integer value.
+ */
+function api_get_permissions_for_new_files() {
+	static $permissions;
+	if (!isset($permissions)) {
+		$permissions = trim(api_get_setting('permissions_for_new_files'));
+		// The default value 0666 is according to that in the platform administration panel after fresh system installation.
+		$permissions = octdec(!empty($permissions) ? $permissions : '0666');
 	}
+	return $permissions;
+}
 
-	// Loop through the folder
-	$dir = dir($source);
-	while (false !== $entry = $dir->read()) {
-		// Skip pointers
-		if ($entry == '.' || $entry == '..') {
-			continue;
+/**
+ * sys_get_temp_dir() was introduced as of PHP 5.2.1
+ * For older PHP versions the following implementation is to be activated.
+ * @link Based on http://www.phpit.net/article/creating-zip-tar-archives-dynamically-php/2/
+ */
+if (!function_exists('sys_get_temp_dir')) {
+
+	function sys_get_temp_dir() {
+
+		// Try to get from environment variable
+		if (!empty($_ENV['TMP'])) {
+			return realpath($_ENV['TMP']);
+		}
+		if (!empty($_ENV['TMPDIR'])) {
+			return realpath($_ENV['TMPDIR']);
+		}
+		if (!empty($_ENV['TEMP'])) {
+			return realpath($_ENV['TEMP']);
 		}
 
-		// Deep copy directories
-		if ($dest !== "$source/$entry") {
-			$files = copyr("$source/$entry", "$dest/$entry", $exclude, $copied_files);
+		// Detect by creating a temporary file
+		// Try to use system's temporary directory
+		// as random name shouldn't exist
+		$temp_file = tempnam(md5(uniqid(rand(), true)), '');
+		if ($temp_file) {
+			$temp_dir = realpath(dirname($temp_file));
+			@unlink( $temp_file );
+			return $temp_dir;
 		}
+
+		return false;
 	}
-	// Clean up
-	$dir->close();
-	return $files;
 }
 
 /**
@@ -2932,55 +2961,96 @@ function rmdirr($dirname) {
 	return $res;
 }
 
-function copy_folder_course_session($pathname, $base_path_document,$session_id,$course_info, $document)
-{
+// TODO: This function is to be simplified. File access modes to be implemented.
+/**
+ * function adapted from a php.net comment
+ * copy recursively a folder
+ * @param the source folder
+ * @param the dest folder
+ * @param an array of excluded file_name (without extension)
+ * @param copied_files the returned array of copied files
+ */
+function copyr($source, $dest, $exclude = array(), $copied_files = array()) {
+	// Simple copy for a file
+	if (is_file($source)) {
+		$path_info = pathinfo($source);
+		if (!in_array($path_info['filename'], $exclude)) {
+			copy($source, $dest);
+		}
+		return;
+	}
+
+	// Make destination directory
+	if (!is_dir($dest)) {
+		mkdir($dest);
+	}
+
+	// Loop through the folder
+	$dir = dir($source);
+	while (false !== $entry = $dir->read()) {
+		// Skip pointers
+		if ($entry == '.' || $entry == '..') {
+			continue;
+		}
+
+		// Deep copy directories
+		if ($dest !== "$source/$entry") {
+			$files = copyr("$source/$entry", "$dest/$entry", $exclude, $copied_files);
+		}
+	}
+	// Clean up
+	$dir->close();
+	return $files;
+}
+
+// TODO: Using DIRECTORY_SEPARATOR is not recommended, this is an obsolete approach. Documentation header to be added here.
+function copy_folder_course_session($pathname, $base_path_document,$session_id,$course_info, $document) {
 	$table = Database :: get_course_table(TABLE_DOCUMENT, $course_info['dbName']);
 	$session_id = intval($session_id);
-    // Check if directory already exists
-    if (is_dir($pathname) || empty($pathname)) {
-        return true;
-    }
+	// Check if directory already exists
+	if (is_dir($pathname) || empty($pathname)) {
+		return true;
+	}
 
-    // Ensure a file does not already exist with the same name
-    if (is_file($pathname)) {
-        trigger_error('mkdirr() File exists', E_USER_WARNING);
-        return false;
-    }
+	// Ensure a file does not already exist with the same name
+	if (is_file($pathname)) {
+		trigger_error('copy_folder_course_session(): File exists', E_USER_WARNING);
+		return false;
+	}
 
-    $folders = explode(DIRECTORY_SEPARATOR,str_replace($base_path_document.DIRECTORY_SEPARATOR,'',$pathname));
+	$folders = explode(DIRECTORY_SEPARATOR,str_replace($base_path_document.DIRECTORY_SEPARATOR,'',$pathname));
 
-    $new_pathname = $base_path_document;
-    $path = '';
+	$new_pathname = $base_path_document;
+	$path = '';
 
-    foreach ($folders as $folder) {
-	$new_pathname .= DIRECTORY_SEPARATOR.$folder;
-	$path .= DIRECTORY_SEPARATOR.$folder;
+	foreach ($folders as $folder) {
+		$new_pathname .= DIRECTORY_SEPARATOR.$folder;
+		$path .= DIRECTORY_SEPARATOR.$folder;
 
-	if (!file_exists($new_pathname)) {
+		if (!file_exists($new_pathname)) {
 
-		$sql = "SELECT * FROM $table WHERE path = '$path' AND filetype = 'folder' AND session_id = '$session_id'";
-		$rs1  = Database::query($sql,__FILE__,__LINE__);
-		$num_rows = Database::num_rows($rs1);
+			$sql = "SELECT * FROM $table WHERE path = '$path' AND filetype = 'folder' AND session_id = '$session_id'";
+			$rs1  = Database::query($sql,__FILE__,__LINE__);
+			$num_rows = Database::num_rows($rs1);
 
-		if ($num_rows == 0) {
-			if (mkdir($new_pathname)) {
-				$perm = api_get_setting('permissions_for_new_directories');
-				$perm = octdec(!empty($perm)?$perm:'0770');
-				chmod($new_pathname,$perm);
+			if ($num_rows == 0) {
+				if (mkdir($new_pathname)) {
+					$perm = api_get_setting('permissions_for_new_directories');
+					$perm = octdec(!empty($perm)?$perm:'0770');
+					chmod($new_pathname,$perm);
+				}
+				// Insert new folder with destination session_id
+				$sql = "INSERT INTO ".$table." SET path = '$path', comment = '".Database::escape_string($document->comment)."', title = '".Database::escape_string(basename($new_pathname))."' ,filetype='folder', size= '0', session_id = '$session_id'";
+				Database::query($sql, __FILE__, __LINE__);
+				$document_id = Database::insert_id();
+				api_item_property_update($course_info,TOOL_DOCUMENT,$document_id,'FolderCreated',api_get_user_id(),0,0,null,null,$session_id);
 			}
-			// Insert new folder with destination session_id
-			$sql = "INSERT INTO ".$table." SET path = '$path', comment = '".Database::escape_string($document->comment)."', title = '".Database::escape_string(basename($new_pathname))."' ,filetype='folder', size= '0', session_id = '$session_id'";
-			Database::query($sql, __FILE__, __LINE__);
-			$document_id = Database::insert_id();
-			api_item_property_update($course_info,TOOL_DOCUMENT,$document_id,'FolderCreated',api_get_user_id(),0,0,null,null,$session_id);
 		}
-	}
-
-    } // en foreach
 
+	} // en foreach
 }
 
-// TODO: chmodr() is a better name. Some corrections are needed.
+// TODO: chmodr() is a better name. Some corrections are needed. Documentation header to be added here.
 function api_chmod_R($path, $filemode) {
 	if (!is_dir($path)) {
 		return chmod($path, $filemode);
@@ -3885,38 +3955,6 @@ function api_is_in_group($group_id = null, $course_code = null) {
 	return false;
 }
 
-// sys_get_temp_dir() is on php since 5.2.1
-if (!function_exists('sys_get_temp_dir')) {
-
-	// Based on http://www.phpit.net/
-	// article/creating-zip-tar-archives-dynamically-php/2/
-	function sys_get_temp_dir() {
-
-		// Try to get from environment variable
-		if (!empty($_ENV['TMP'])) {
-			return realpath($_ENV['TMP']);
-		}
-		if (!empty($_ENV['TMPDIR'])) {
-			return realpath($_ENV['TMPDIR']);
-		}
-		if (!empty($_ENV['TEMP'])) {
-			return realpath($_ENV['TEMP']);
-		}
-
-		// Detect by creating a temporary file
-		// Try to use system's temporary directory
-		// as random name shouldn't exist
-		$temp_file = tempnam(md5(uniqid(rand(), true)), '');
-		if ($temp_file) {
-			$temp_dir = realpath(dirname($temp_file));
-			@unlink( $temp_file );
-			return $temp_dir;
-		}
-
-		return false;
-	}
-}
-
 /**
  * This function informs whether the sent request is XMLHttpRequest
  */

+ 23 - 22
main/inc/lib/surveymanager.lib.php

@@ -628,33 +628,34 @@ class SurveyTree {
 	 */
 	public function createList ($list) {
 		$result=array();
-		foreach ($list as $key=>$node)
-		{
-			if (is_array($node['children']))
-			{
-				//echo $key; echo '--<br>';
-				//print_r($node);
-				//echo '<br>';
-				$result[$key]= $node['name'];
-				$re=self::createList($node['children']);
-				if (!empty($re))
+		if(is_array($list)) {
+			foreach ($list as $key=>$node) {
+				if (is_array($node['children']))
 				{
-					if (is_array($re))
-						foreach ($re as $key=>$r)
+					//echo $key; echo '--<br>';
+					//print_r($node);
+					//echo '<br>';
+					$result[$key]= $node['name'];
+					$re=self::createList($node['children']);
+					if (!empty($re))
+					{
+						if (is_array($re))
+							foreach ($re as $key=>$r)
+							{
+								$result[$key]=''.$r;
+							}
+						else
 						{
-							$result[$key]=''.$r;
+							$result[]=$re;
 						}
-					else
-					{
-						$result[]=$re;
+	
 					}
-
 				}
-			}
-			else
-			{
-				//echo $key; echo '-<br>';
-				$result[$key]=$node['name'];
+				else
+				{
+					//echo $key; echo '-<br>';
+					$result[$key]=$node['name'];
+				}
 			}
 		}
 		return $result;

+ 225 - 250
tests/main/admin/calendar.lib.test.php

@@ -1,66 +1,45 @@
 <?php
 
 require_once(api_get_path(LIBRARY_PATH) . "/fckeditor/fckeditor.php");
-require_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
+//require_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
 require_once(api_get_path(LIBRARY_PATH).'icalcreator/iCalcreator.class.php');
-require_once(api_get_path(LIBRARY_PATH).'course.lib.php');
+//require_once(api_get_path(LIBRARY_PATH).'course.lib.php');
 
 
 class TestCalendar extends UnitTestCase {
 
-	function TestCalendar() {
-        $this->UnitTestCase('testing the file about calendar/agenda');
-    }
-
-	public function setUp(){
-		$this->tcourse = new CourseManager();
-	}
-	
-	public function tearDown(){
-		$this->tcourse = null;
-	}
 	
- 	public function testDisplayMinimonthcalendar(){
- 		ob_start();
- 		global $DaysShort;
- 		$agendaitems=array('test','test2');
- 		$month=01;
- 		$year=2010;
- 		$monthName='';
- 		$res = display_minimonthcalendar($agendaitems, $month, $year, $monthName);
- 		ob_end_clean();
- 		$this->assertTrue(is_null($res));
- 		//var_dump($res);
- 	}
-
- 	public function testToJavascript(){
+	public function testToJavascript(){
  		$res = to_javascript();
  		$this->assertTrue($res);
  		$this->assertTrue(is_string($res));
  		//var_dump($res);
  	}
-
- 	public function testUserGroupFilterJavascript(){
- 		$res = user_group_filter_javascript();
- 		$this->assertTrue($res);
- 		$this->assertTrue(is_string($res));
+ 	
+ 	/**
+	 * Adds an agenda item in the database. Similar to store_new_agenda_item() except it takes parameters
+	 * @param   array   Course info
+	 * @param   string  Event title
+	 * @param   string  Event content/description
+	 * @param   string  Start date
+	 * @param   string  End date
+	 * @param   array   List of groups to which this event is added
+	 * @param   int     Parent id (optional)
+	 * @return  int     The new item's DB ID
+	 */
+ 	public function testAgendaAddItem(){
+ 		global $_course;
+ 		$course_code=$_course;
+ 		$course_info = '';
+ 		$title='test';
+ 		$content='test function';
+ 		$db_start_date='07/11/2009';
+ 		$db_end_date='07/20/2009';
+ 		$res = agenda_add_item($course_info, $title, $content, $db_start_date, $db_end_date, $to=array(), $parent_id=null); 
+ 		$this->assertTrue(is_numeric($res));
  		//var_dump($res);
  	}
-
- 	public function testDisplayMonthcalendar(){
- 		ob_start();
- 		global $MonthsLong;
-		global $DaysShort;
-		global $origin;
-		$month=05;
-		$year=2010;
-		$res = display_monthcalendar($month, $year);
-		ob_end_clean();
-		$this->assertTrue(is_null($res));
-		$this->assertNull($res);
-		//var_dump($res);
- 	}
-
+ 	
  	public function testStoreNewAgendaItem(){
  		global $_user;
  		$res_store = store_new_agenda_item();
@@ -72,33 +51,82 @@ class TestCalendar extends UnitTestCase {
  			$this->assertTrue(is_numeric($res_store));			 				
  		}
  	}
-
- 	public function testDisplayCourseadminLinks(){
+ 	
+ 	 public function testShowAddForm(){
  		ob_start();
- 		$res = display_courseadmin_links();
+ 		global $MonthsLong;
+ 		$id='';
+ 		$res= show_add_form($id);
  		ob_end_clean();
  		$this->assertTrue(is_null($res));
  		//var_dump($res);
  	}
+ 	
+ 	public function testAddWeek(){
+ 		$timestamp=12;
+ 		$num=1;
+ 		$res = add_week($timestamp,$num);
+ 		$this->assertTrue(is_numeric($res));
+ 		//var_dump($res);
+ 	}
 
- 	public function testDisplayStudentLinks(){
- 		ob_start();
- 		global $show;
- 		$res = display_student_links();
- 		ob_end_clean();
- 		$this->assertTrue(is_null($res));
+ 	public function testAddMonth(){
+ 		$timestamp=5;
+ 		$num=1;
+ 		$res = add_month($timestamp,$num);
+ 		$this->assertTrue(is_numeric($res));
  		//var_dump($res);
  	}
 
- 	public function testGetAgendaItem(){
- 		$id=4; 		
- 		$res = get_agenda_item($id); 		
- 		if(is_array($res)) {
- 			$this->assertTrue(is_array($res));
- 		} 
+ 	public function testAddYear(){
+ 		$timestamp=9999;
+ 		$num=1;
+ 		$res = add_year($timestamp,$num);
+ 		$this->assertTrue(is_numeric($res));
+ 		//var_dump($res);
  	}
+ 	
+
+/**
+ * Adds a repetitive item to the database
+ * @param   array   Course info
+ * @param   int     The original event's id
+ * @param   string  Type of repetition
+ * @param   int     Timestamp of end of repetition (repeating until that date)
+ * @param   array   Original event's destination
+ * @return  boolean False if error, True otherwise
+ */
 
- 	public function testStoreEditedAgendaItem(){
+ 	public function testAgendaAddRepeatItem(){
+ 		//this function is not used or deprecated
+ 	}
+ 	
+ 	public function testGetCalendarItems(){
+ 		global $_course;
+ 		$month=01;
+ 		$year=2010;
+		$res = get_calendar_items($month, $year);
+ 		$this->assertTrue(is_array($res));
+ 		//var_dump($res);
+ 	}
+ 	
+ 	//This funtion need a path where will copy to the other folder.
+/*
+ 	public function testAgendaImportIcal() { 
+ 		global $_course;
+ 		$course_info = $_course;
+ 		$file = api_get_path(SYS_PATH).'tests/main/admin/icals/test.ics';
+ 		$res = agenda_import_ical($course_info, $file);
+ 		if(is_bool($res)){
+ 		$this->assertTrue(is_bool($res));
+ 		$this->assertTrue($res===false || $res === true);
+ 		}else{
+ 			$this->assertTrue($res);
+ 		}
+ 	}
+*/
+
+	public function testStoreEditedAgendaItem(){
  		ob_start();
  		$id=1;
 		$title='';
@@ -123,99 +151,7 @@ class TestCalendar extends UnitTestCase {
  		$this->assertTrue(is_bool($res));
  		//var_dump($res);
  	}
-	/**
-	* Makes an agenda item visible or invisible for a student
-	* @param integer id the id of the agenda item we are changing the visibility of
-	*/
- 	public function testShowhideAgendaItem(){
-		ob_start();
-		$id=1;
-		global $nameTools;
- 		$res = showhide_agenda_item($id);
- 		//Show the message when the visibility was changed
- 		$real_show = Display::display_normal_message(get_lang("VisibilityChanged"));
- 		ob_end_clean();
- 		if(!empty($res)){
- 			$this->assertTrue($res);
- 			$this->assertTrue($real_show);	
- 		} else {
- 			$this->assertNull($res);
- 		}
- 		//var_dump($res);	
- 	}
  	
-	/**
-	* Displays all the agenda items
-	*/ 
- 	
- 	public function testDisplayAgendaItems() { 			
- 		ob_start(); 		
- 		$res = display_agenda_items();
- 		ob_end_clean();
- 		$this->assertTrue(is_null($res));	
- 	}
- 	 	
- 	/**
-	* Displays only 1 agenda item. This is used when an agenda item is added to the learning path.
-	*/
- 	public function testDisplayOneAgendaItem(){
- 		ob_start();				
-		$agenda_id=1;
-		$res = display_one_agenda_item($agenda_id);
-		ob_end_clean();
- 		$this->assertTrue(is_null($res));	
-
-  	}
-  	
-	/**
-	* Show the form for adding a new agenda item. This is the same function that is used whenever we are editing an
-	* agenda item. When the id parameter is empty (default behaviour), then we show an empty form, else we are editing and
-	* we have to retrieve the information that is in the database and use this information in the forms.
-	*/
- 	public function testShowGroupFilterForm(){
- 		ob_start();
- 		$res = show_group_filter_form();
- 		ob_end_clean(); 	
- 		$this->assertTrue(is_null($res));
- 	}
-
- 	public function testShowUserFilterForm(){
-		ob_start();
- 		$res = show_user_filter_form();
- 		ob_end_clean(); 
- 		$this->assertTrue(is_null($res));
- 	}
-
- 	public function testShowAddForm(){
- 		ob_start();
- 		global $MonthsLong;
- 		$id='';
- 		$res= show_add_form($id);
- 		ob_end_clean();
- 		$this->assertTrue(is_null($res));
- 		//var_dump($res);
- 	}
-
- 	public function testGetAgendaitems(){
- 		global $_user;
-		global $_configuration;
- 		$month=01;
- 		$year=2010;
- 		$res = get_agendaitems($month, $year);
- 		if(is_array($res)) {
- 			$this->assertTrue(is_array($res));
- 		} 
- 		
- 	}
-
- 	public function testDisplayUpcomingEvents(){
- 		 ob_start();
-		 $res = display_upcoming_events();
-		 ob_end_clean();
-		 $this->assertNull($res);
-		 
- 	}
-
  	public function testCalculateStartEndOfWeek(){
  		$week_number=4;
  		$year=2011;
@@ -224,8 +160,20 @@ class TestCalendar extends UnitTestCase {
  		$this->assertTrue($res);
  		//var_dump($res);
  	}
-
- 	public function testDisplayDaycalendar(){
+ 	
+ 	/**
+	* Displays all the agenda items
+	*/ 
+ 	public function testDisplayAgendaItems() { 	
+ 		global $is_courseAdmin;		
+ 		ob_start(); 		
+ 		$TABLEAGENDA = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
+ 		$res = display_agenda_items();
+ 		ob_end_clean();
+ 		$this->assertTrue(is_null($res));	
+ 	}
+ 	
+ 	 	public function testDisplayDaycalendar(){
  		ob_start();
  		$agendaitems='';
  		$day='';
@@ -302,119 +250,146 @@ class TestCalendar extends UnitTestCase {
 		$this->assertTrue(is_array($resul));
 		//var_dump($resul);
 	}
-
- 	public function testIsRepeatedEvent() {
-	//This is deprecated or not used
+ 	
+	public function testDeleteAgendaItem(){
+		$id=1;
+		$res = delete_agenda_item($id);
+		$this->assertTrue(is_bool($res));
  	}
-
- 	public function testAddWeek(){
- 		$timestamp=12;
- 		$num=1;
- 		$res = add_week($timestamp,$num);
- 		$this->assertTrue(is_numeric($res));
+ 	 	public function testDisplayMinimonthcalendar(){
+ 		ob_start();
+ 		global $DaysShort;
+ 		$agendaitems=array('test','test2');
+ 		$month=01;
+ 		$year=2010;
+ 		$monthName='';
+ 		$res = display_minimonthcalendar($agendaitems, $month, $year, $monthName);
+ 		ob_end_clean();
+ 		$this->assertTrue(is_null($res));
  		//var_dump($res);
  	}
 
- 	public function testAddMonth(){
- 		$timestamp=5;
- 		$num=1;
- 		$res = add_month($timestamp,$num);
- 		$this->assertTrue(is_numeric($res));
+ 	public function testUserGroupFilterJavascript(){
+ 		$res = user_group_filter_javascript();
+ 		$this->assertTrue($res);
+ 		$this->assertTrue(is_string($res));
  		//var_dump($res);
  	}
 
- 	public function testAddYear(){
- 		$timestamp=9999;
- 		$num=1;
- 		$res = add_year($timestamp,$num);
- 		$this->assertTrue(is_numeric($res));
- 		//var_dump($res);
+ 	public function testDisplayMonthcalendar(){
+ 		ob_start();
+ 		global $MonthsLong;
+		global $DaysShort;
+		global $origin;
+		$month=05;
+		$year=2010;
+		$res = display_monthcalendar($month, $year);
+		ob_end_clean();
+		$this->assertTrue(is_null($res));
+		$this->assertNull($res);
+		//var_dump($res);
  	}
- 	
-/**
- * Adds an agenda item in the database. Similar to store_new_agenda_item() except it takes parameters
- * @param   array   Course info
- * @param   string  Event title
- * @param   string  Event content/description
- * @param   string  Start date
- * @param   string  End date
- * @param   array   List of groups to which this event is added
- * @param   int     Parent id (optional)
- * @return  int     The new item's DB ID
- */
- 	public function testAgendaAddItem(){
- 		global $_course;
- 		$course_code=$_course;
- 		$course_info = '';
- 		$title='test';
- 		$content='test function';
- 		$db_start_date='07/11/2009';
- 		$db_end_date='07/20/2009';
- 		$res = agenda_add_item($course_info, $title, $content, $db_start_date, $db_end_date, $to=array(), $parent_id=null); 
- 		$this->assertTrue(is_numeric($res));
+
+ 	public function testDisplayCourseadminLinks(){
+ 		ob_start();
+ 		$res = display_courseadmin_links();
+ 		ob_end_clean();
+ 		$this->assertTrue(is_null($res));
  		//var_dump($res);
  	}
- 	
-/**
- * Adds a repetitive item to the database
- * @param   array   Course info
- * @param   int     The original event's id
- * @param   string  Type of repetition
- * @param   int     Timestamp of end of repetition (repeating until that date)
- * @param   array   Original event's destination
- * @return  boolean False if error, True otherwise
- */
- 	public function testGetCalendarItems(){
- 		global $_course;
- 		$month=01;
- 		$year=2010;
-		$res = get_calendar_items($month, $year);
- 		$this->assertTrue(is_array($res));
+
+ 	public function testDisplayStudentLinks(){
+ 		ob_start();
+ 		global $show;
+ 		$res = display_student_links();
+ 		ob_end_clean();
+ 		$this->assertTrue(is_null($res));
  		//var_dump($res);
  	}
 
- 	public function testAgendaAddRepeatItem(){
- 		//this function is not used or deprecated
+ 	public function testGetAgendaItem(){
+ 		$id=4; 		
+ 		$res = get_agenda_item($id); 		
+ 		if(is_array($res)) {
+ 			$this->assertTrue(is_array($res));
+ 		} 
  	}
+
  	
- 	//This funtion need a path where will copy to the other folder.
-/*
- 	public function testAgendaImportIcal() { 
- 		global $_course;
- 		$course_info = $_course;
- 		$file = api_get_path(SYS_PATH).'tests/main/admin/icals/test.ics';
- 		$res = agenda_import_ical($course_info, $file);
- 		if(is_bool($res)){
- 		$this->assertTrue(is_bool($res));
- 		$this->assertTrue($res===false || $res === true);
- 		}else{
+	/**
+	* Makes an agenda item visible or invisible for a student
+	* @param integer id the id of the agenda item we are changing the visibility of
+	*/
+ 	public function testShowhideAgendaItem(){
+		ob_start();
+		$id=1;
+		global $nameTools;
+ 		$res = showhide_agenda_item($id);
+ 		//Show the message when the visibility was changed
+ 		$real_show = Display::display_normal_message(get_lang("VisibilityChanged"));
+ 		ob_end_clean();
+ 		if(!empty($res)){
  			$this->assertTrue($res);
+ 			$this->assertTrue($real_show);	
+ 		} else {
+ 			$this->assertNull($res);
  		}
+ 		//var_dump($res);	
  	}
-*/
+ 	 	
+ 	/**
+	* Displays only 1 agenda item. This is used when an agenda item is added to the learning path.
+	*/
+ 	public function testDisplayOneAgendaItem(){
+ 		ob_start();				
+		$agenda_id=1;
+		$res = display_one_agenda_item($agenda_id);
+		ob_end_clean();
+ 		$this->assertTrue(is_null($res));	
 
+  	}
+  	
+	/**
+	* Show the form for adding a new agenda item. This is the same function that is used whenever we are editing an
+	* agenda item. When the id parameter is empty (default behaviour), then we show an empty form, else we are editing and
+	* we have to retrieve the information that is in the database and use this information in the forms.
+	*/
+ 	public function testShowGroupFilterForm(){
+ 		ob_start();
+ 		$res = show_group_filter_form();
+ 		ob_end_clean(); 	
+ 		$this->assertTrue(is_null($res));
+ 	}
 
-	public function testDeleteAgendaItem(){
-		$id=1;
-		$res = delete_agenda_item($id);
-		$this->assertTrue(is_bool($res));
+ 	public function testShowUserFilterForm(){
+		ob_start();
+ 		$res = show_user_filter_form();
+ 		ob_end_clean(); 
+ 		$this->assertTrue(is_null($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);
-		}
-	}
-*/
+ 	
+ 	public function testGetAgendaitems(){
+ 		global $_user;
+		global $_configuration;
+ 		$month=01;
+ 		$year=2010;
+ 		$res = get_agendaitems($month, $year);
+ 		if(is_array($res)) {
+ 			$this->assertTrue(is_array($res));
+ 		} 
+ 		
+ 	}
+
+ 	public function testDisplayUpcomingEvents(){
+ 		 ob_start();
+		 $res = display_upcoming_events();
+		 ob_end_clean();
+		 $this->assertNull($res); 
+ 	}
+ 	
+ 	public function testIsRepeatedEvent() {
+	//This is deprecated or not used
+ 	}
+
 }
 ?>

+ 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));
+
+		}
 }
 ?>

+ 34 - 18
tests/main/inc/lib/main_api.lib.test.php

@@ -172,7 +172,7 @@ class TestMainApi extends UnitTestCase {
 
 	function testApiSessionClear() {
 		$variable = 'test';
-		 if (!headers_sent()) {	
+		 if (!headers_sent()) {
 			$res=api_session_clear($variable);
 		 }
 		$this->assertTrue(is_null($res));
@@ -180,7 +180,7 @@ class TestMainApi extends UnitTestCase {
 	}
 
 	function testApiSessionDestroy(){
-		 if (!headers_sent()) {	
+		 if (!headers_sent()) {
 			$res=api_session_destroy();
 		 }
 		$this->assertTrue(is_null($res));
@@ -257,7 +257,7 @@ class TestMainApi extends UnitTestCase {
 		$this->assertTrue(is_numeric($res));
 		//var_dump($res);
     }
-	
+
 
     function testApiGetSessionName(){
    		$session_id='';
@@ -279,7 +279,7 @@ class TestMainApi extends UnitTestCase {
     	$this->assertTrue(is_string($res));
     	//var_dump($res);
 	}
-	
+
 /* function deprecated
    	function testGetLang(){
         global $language_interface, $language_interface_initial_value, $language_file,$variable;
@@ -582,6 +582,22 @@ class TestMainApi extends UnitTestCase {
 		//var_dump($res);
 	}
 
+	public function testApiGetPermissionsForNewDirectories() {
+		$perm = trim(api_get_setting('permissions_for_new_directories'));
+		$perm = octdec(!empty($perm) ? $perm : '0777');
+		$res = api_get_permissions_for_new_directories();
+		$this->assertTrue($res === $perm);
+		//var_dump($res);
+	}
+
+	public function testApiGetPermissionsForNewFiles() {
+		$perm = trim(api_get_setting('permissions_for_new_files'));
+		$perm = octdec(!empty($perm) ? $perm : '0666');
+		$res = api_get_permissions_for_new_files();
+		$this->assertTrue($res === $perm);
+		//var_dump($res);
+	}
+
 	function testCopyr(){
 		$source = api_get_path(SYS_CODE_PATH).'app_share/DokeosAppShare.exe';
 		$dest = '';
@@ -590,7 +606,7 @@ class TestMainApi extends UnitTestCase {
 		//var_dump($res);
 	}
 
-	function testApiChmod_R(){		
+	function testApiChmod_R(){
 		$dirname = api_get_path(SYS_LANG_PATH);
 		$perm_dir = substr(sprintf('%o', fileperms($dirname)), -4);
 		if ($perm_dir != '0777') {
@@ -601,7 +617,7 @@ class TestMainApi extends UnitTestCase {
 			$filemode = '0777';
 			$res = api_chmod_R($path, $filemode);
 			unlink($path);
-			$this->assertTrue($res);	
+			$this->assertTrue($res);
 		}
 	}
 
@@ -618,7 +634,7 @@ class TestMainApi extends UnitTestCase {
 	}
 
 	function testApiStatusKey(){
-		$status = 'user';		
+		$status = 'user';
 		$res = api_status_key($status);
 		$this->assertTrue(is_numeric($res));
 	}
@@ -849,20 +865,20 @@ class TestMainApi extends UnitTestCase {
 		$this->assertTrue($tool_list);
 		//var_dump($res);
 	}
-	public function TestDeleteCourse() {				
-		$code = 'COURSEX';				
-		$res = CourseManager::delete_course($code);			
-		$path = api_get_path(SYS_PATH).'archive';		
+	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);						
-					}				
-				}				
+			while (false !== ($file = readdir($handle))) {
+				if (strpos($file,$code)!==false) {
+					if (is_dir($path.'/'.$file)) {
+						rmdirr($path.'/'.$file);
+					}
+				}
 			}
 			closedir($handle);
 		}
-	}	
+	}
 }
 ?>

+ 40 - 40
tests/main/inc/lib/main_api.lib.test_standalone.php

@@ -56,7 +56,7 @@ class TestMainApi extends UnitTestCase {
 		$message[] = '';
 
 		$message[] = '';
-		$message[] = 'Changed behaviour of the function api_get_path() after Dokeos 1.8.6.1, i.e. as of Dokeos 1.8.6.2.';
+		$message[] = 'Changed behaviour of the function api_get_path() after Dokeos 1.8.6.1, i.e. as of Chamilo 1.8.6.2.';
 		$message[] = '---------------------------------------------------------------------------------------------------------------';
 		$message[] = '';
 		$message[] = 'Old behaviour (1.8.6.1) api_get_path(INCLUDE_PATH) = '.api_get_path_1_8_6_1(INCLUDE_PATH).'&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;'.'New behaviour (1.8.6.2) api_get_path(INCLUDE_PATH) = '.api_get_path(INCLUDE_PATH);
@@ -336,45 +336,45 @@ class TestMainApi extends UnitTestCase {
 }
 
 /**
-*	Returns a full path to a certain Dokeos area, which you specify
-*	through a parameter.
-*
-*	See $_configuration['course_folder'] in the configuration.php
-*	to alter the WEB_COURSE_PATH and SYS_COURSE_PATH parameters.
-*
-*	@param one of the following constants:
-*	WEB_SERVER_ROOT_PATH, SYS_SERVER_ROOT_PATH,
-*	WEB_PATH, SYS_PATH, REL_PATH, WEB_COURSE_PATH, SYS_COURSE_PATH,
-*	REL_COURSE_PATH, REL_CODE_PATH, WEB_CODE_PATH, SYS_CODE_PATH,
-*	SYS_LANG_PATH, WEB_IMG_PATH, GARBAGE_PATH, WEB_PLUGIN_PATH, SYS_PLUGIN_PATH, WEB_ARCHIVE_PATH, SYS_ARCHIVE_PATH,
-*	INCLUDE_PATH, WEB_LIBRARY_PATH, LIBRARY_PATH, CONFIGURATION_PATH
-*
-* 	@example assume that your server root is /var/www/ dokeos is installed in a subfolder dokeos/ and the URL of your campus is http://www.mydokeos.com
-* 	The other configuration paramaters have not been changed.
-* 	The different api_get_paths will give
-*	WEB_SERVER_ROOT_PATH	http://www.mydokeos.com/
-*	SYS_SERVER_ROOT_PATH	/var/www/ - This is the physical folder where the system Dokeos has been placed. It is not always equal to $_SERVER['DOCUMENT_ROOT'].
-* 	WEB_PATH				http://www.mydokeos.com/dokeos/
-* 	SYS_PATH				/var/www/dokeos/
-* 	REL_PATH				dokeos/
-* 	WEB_COURSE_PATH			http://www.mydokeos.com/dokeos/courses/
-* 	SYS_COURSE_PATH			/var/www/dokeos/courses/
-*	REL_COURSE_PATH			/dokeos/courses/
-* 	REL_CODE_PATH			/dokeos/main/
-* 	WEB_CODE_PATH			http://www.mydokeos.com/dokeos/main/
-* 	SYS_CODE_PATH			/var/www/dokeos/main/
-* 	SYS_LANG_PATH			/var/www/dokeos/main/lang/
-* 	WEB_IMG_PATH			http://www.mydokeos.com/dokeos/main/img/
-* 	GARBAGE_PATH
-* 	WEB_PLUGIN_PATH			http://www.mydokeos.com/dokeos/plugin/
-* 	SYS_PLUGIN_PATH			/var/www/dokeos/plugin/
-* 	WEB_ARCHIVE_PATH		http://www.mydokeos.com/dokeos/archive/
-* 	SYS_ARCHIVE_PATH		/var/www/dokeos/archive/
-*	INCLUDE_PATH			/var/www/dokeos/main/inc/
-* 	WEB_LIBRARY_PATH		http://www.mydokeos.com/dokeos/main/inc/lib/
-* 	LIBRARY_PATH			/var/www/dokeos/main/inc/lib/
-* 	CONFIGURATION_PATH		/var/www/dokeos/main/inc/conf/
-*/
+ *	Returns a full path to a certain Dokeos area, which you specify
+ *	through a parameter.
+ *
+ *	See $_configuration['course_folder'] in the configuration.php
+ *	to alter the WEB_COURSE_PATH and SYS_COURSE_PATH parameters.
+ *
+ *	@param one of the following constants:
+ *	WEB_SERVER_ROOT_PATH, SYS_SERVER_ROOT_PATH,
+ *	WEB_PATH, SYS_PATH, REL_PATH, WEB_COURSE_PATH, SYS_COURSE_PATH,
+ *	REL_COURSE_PATH, REL_CODE_PATH, WEB_CODE_PATH, SYS_CODE_PATH,
+ *	SYS_LANG_PATH, WEB_IMG_PATH, GARBAGE_PATH, WEB_PLUGIN_PATH, SYS_PLUGIN_PATH, WEB_ARCHIVE_PATH, SYS_ARCHIVE_PATH,
+ *	INCLUDE_PATH, WEB_LIBRARY_PATH, LIBRARY_PATH, CONFIGURATION_PATH
+ *
+ * 	@example assume that your server root is /var/www/ dokeos is installed in a subfolder dokeos/ and the URL of your campus is http://www.mydokeos.com
+ * 	The other configuration paramaters have not been changed.
+ * 	The different api_get_paths will give
+ *	WEB_SERVER_ROOT_PATH	http://www.mydokeos.com/
+ *	SYS_SERVER_ROOT_PATH	/var/www/ - This is the physical folder where the system Dokeos has been placed. It is not always equal to $_SERVER['DOCUMENT_ROOT'].
+ * 	WEB_PATH				http://www.mydokeos.com/dokeos/
+ * 	SYS_PATH				/var/www/dokeos/
+ * 	REL_PATH				dokeos/
+ * 	WEB_COURSE_PATH			http://www.mydokeos.com/dokeos/courses/
+ * 	SYS_COURSE_PATH			/var/www/dokeos/courses/
+ *	REL_COURSE_PATH			/dokeos/courses/
+ * 	REL_CODE_PATH			/dokeos/main/
+ * 	WEB_CODE_PATH			http://www.mydokeos.com/dokeos/main/
+ * 	SYS_CODE_PATH			/var/www/dokeos/main/
+ * 	SYS_LANG_PATH			/var/www/dokeos/main/lang/
+ * 	WEB_IMG_PATH			http://www.mydokeos.com/dokeos/main/img/
+ * 	GARBAGE_PATH
+ * 	WEB_PLUGIN_PATH			http://www.mydokeos.com/dokeos/plugin/
+ * 	SYS_PLUGIN_PATH			/var/www/dokeos/plugin/
+ * 	WEB_ARCHIVE_PATH		http://www.mydokeos.com/dokeos/archive/
+ * 	SYS_ARCHIVE_PATH		/var/www/dokeos/archive/
+ *	INCLUDE_PATH			/var/www/dokeos/main/inc/
+ * 	WEB_LIBRARY_PATH		http://www.mydokeos.com/dokeos/main/inc/lib/
+ * 	LIBRARY_PATH			/var/www/dokeos/main/inc/lib/
+ * 	CONFIGURATION_PATH		/var/www/dokeos/main/inc/conf/
+ */
 function api_get_path_1_8_6_1($path_type) {
 
 	global $_configuration;

+ 1 - 2
tests/main/inc/lib/surveymanager.lib.test.php

@@ -285,7 +285,6 @@ class TestSurveyManager extends UnitTestCase {
 	}
 }
 
-
 class TestSurveyTree extends UnitTestCase {
 
 	var $surveylist;
@@ -298,7 +297,7 @@ class TestSurveyTree extends UnitTestCase {
 		//var_dump($res);
 	}
 	function testcreateList() {
-		$list='';
+		$list=array();
 		$res=SurveyTree::createList($list);
 		$this->assertTrue(is_array($res));
 		//var_dump($res);

+ 3 - 2
tests/main/notebook/notebook.lib.test.php

@@ -6,8 +6,9 @@ class TestNotebook extends UnitTestCase {
 
 	function testJavascriptNotebook() {
 		ob_start();
-		$res = NotebookManager::javascript_notebook();
-		$this->assertTrue(is_string($res)); 
+		$values =array();
+		$res = NotebookManager::javascript_notebook($values);
+		$this->assertTrue(is_bool($res)); 
 		ob_end_clean();
 		//var_dump($res);
 	}

+ 13 - 12
tests/test_suite.php

@@ -48,7 +48,7 @@ require_once $maindir.'survey/survey.lib.php';
 require_once $maindir.'install/install_upgrade.lib.php';
 require_once $incdir.'lib/fileManage.lib.php';
 
-class AllTestsSuite extends TestSuite {
+class TestsSuite extends TestSuite {
 	function setUp() {
 		
 		global $_configuration, $_user, $_course, $cidReq;
@@ -120,14 +120,16 @@ class AllTestsSuite extends TestSuite {
 	    $_SESSION['show'] = showall;
 		
 	}
-    function AllTestsSuite() {
+    function TestsSuite() {
     	$this->setUp();
     	$this->TestSuite('All tests suite');
-		$this->addTestFile(dirname(__FILE__).'/main/install/install_upgrade.lib.test.php');
+		/*$this->addTestFile(dirname(__FILE__).'/main/install/install_upgrade.lib.test.php');
 		$this->addTestFile(dirname(__FILE__).'/main/inc/lib/database.lib.test.php');
 		$this->addTestFile(dirname(__FILE__).'/main/inc/lib/add_course.lib.inc.test.php');
 		$this->addTestFile(dirname(__FILE__).'/main/inc/lib/course.lib.test.php');
 		$this->addTestFile(dirname(__FILE__).'/main/inc/banner.lib.test.php');
+		$this->addTestFile(dirname(__FILE__).'/main/admin/calendar.lib.test.php');
+		$this->addTestFile(dirname(__FILE__).'/main/inc/lib/surveymanager.lib.test.php');
 		$this->addTestFile(dirname(__FILE__).'/main/inc/lib/session_handler.class.test.php');
         $this->addTestFile(dirname(__FILE__).'/main/inc/lib/sessionmanager.lib.test.php');
         $this->addTestFile(dirname(__FILE__).'/main/inc/lib/classmanager.lib.test.php');
@@ -154,9 +156,8 @@ class AllTestsSuite extends TestSuite {
 		$this->addTestFile(dirname(__FILE__).'/main/inc/lib/events.lib.inc.test.php');
 		$this->addTestFile(dirname(__FILE__).'/main/inc/lib/fileDisplay.lib.test.php');
 		$this->addTestFile(dirname(__FILE__).'/main/inc/lib/fileManage.lib.test.php');
-	    //$this->addTestFile(dirname(__FILE__).'/main/inc/lib/geometry.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/inc/lib/geometry.lib.test.php');
+    	$this->addTestFile(dirname(__FILE__).'/main/admin/statistics/statistics.lib.test.php');
     	$this->addTestFile(dirname(__FILE__).'/main/admin/sub_language.class.test.php');
     	$this->addTestFile(dirname(__FILE__).'/main/auth/lost_password.lib.test.php');
         $this->addTestFile(dirname(__FILE__).'/main/auth/openid/xrds.lib.test.php');
@@ -167,23 +168,23 @@ class AllTestsSuite extends TestSuite {
         $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/inc/lib/surveymanager.lib.test.php');
+        $this->addTestFile(dirname(__FILE__).'/main/work/work.lib.test.php');     
         $this->addTestFile(dirname(__FILE__).'/main/inc/lib/usermanager.lib.test.php'); 
         $this->addTestFile(dirname(__FILE__).'/main/inc/lib/groupmanager.lib.test.php');	 
         $this->addTestFile(dirname(__FILE__).'/main/inc/lib/image.lib.test.php'); 
         $this->addTestFile(dirname(__FILE__).'/main/inc/lib/import.lib.test.php');
         $this->addTestFile(dirname(__FILE__).'/main/inc/lib/internationalization.lib.test.php');  
         $this->addTestFile(dirname(__FILE__).'/main/inc/lib/system_announcements.lib.test.php');
-        $this->addTestFile(dirname(__FILE__).'/main/inc/lib/main_api.lib.test.php');//al final      
-        $this->addTestFile(dirname(__FILE__).'/main/inc/lib/debug.lib.inc.test.php');
-        //$this->addTestFile(dirname(__FILE__).'/main/inc/lib/fileUpload.lib.test.php');
+        $this->addTestFile(dirname(__FILE__).'/main/inc/lib/fileUpload.lib.test.php');
+        $this->addTestFile(dirname(__FILE__).'/main/inc/lib/main_api.lib.test.php');//this file delete the course     
+        $this->addTestFile(dirname(__FILE__).'/main/inc/lib/debug.lib.inc.test.php');//this file need be to the finish of the tests
+        */
         //This files have a metadata and is not available for the test.
         //$this->addTestFile(dirname(__FILE__).'/main/inc/lib/xht.lib.test.php');
 	    //$this->addTestFile(dirname(__FILE__).'/main/inc/lib/xmd.lib.test.php');
     }
 }
-$test = &new AllTestsSuite();
+$test = &new TestsSuite();