diff --git a/main/inc/lib/document.lib.php b/main/inc/lib/document.lib.php index aae9f069d2..32ce0c5727 100755 --- a/main/inc/lib/document.lib.php +++ b/main/inc/lib/document.lib.php @@ -492,7 +492,7 @@ class DocumentManager { $result = Database::query($sql); - if ($result && Database::num_rows($result) != 0) { + if ($result!==false && Database::num_rows($result) != 0) { while ($row = Database::fetch_array($result, 'ASSOC')) { if ($row['filetype'] == 'file' && pathinfo($row['path'], PATHINFO_EXTENSION) == 'html') { //Templates management diff --git a/tests/main/inc/lib/document.lib.test.php b/tests/main/inc/lib/document.lib.test.php index f1c91ef24a..4c76430ee3 100755 --- a/tests/main/inc/lib/document.lib.test.php +++ b/tests/main/inc/lib/document.lib.test.php @@ -4,8 +4,12 @@ require_once(api_get_path(LIBRARY_PATH).'document.lib.php'); class TestDocumentManager extends UnitTestCase { + public function __construct() { + $this->UnitTestCase('Document Manager library tests'); + } + /** - * This check if a document has the readonly property checked, then see if + * This checks 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. * * @param array $_course @@ -94,13 +98,13 @@ class TestDocumentManager extends UnitTestCase { * (bool) */ function testfile_visible_to_user() { - global $_course,$tbl_document; - $tbl_document = Database::get_course_table(TABLE_DOCUMENT); - $this_course= $_course['dbName'].'.'; - $dirurl = api_get_path(WEB_COURSE_PATH); - $doc_url= $dirurl.'COURSETEST/document/video/painting.mpg?cidReq=COURSETEST'; - $res=DocumentManager::file_visible_to_user($this_course, $doc_url); - $this->assertTrue(is_bool($res)); + global $_course,$tbl_document; + $tbl_document = Database::get_course_table(TABLE_DOCUMENT); + $this_course= $_course['dbName'].'.'; + $dirurl = api_get_path(WEB_COURSE_PATH); + $doc_url= $dirurl.'COURSETEST/document/video/painting.mpg?cidReq=COURSETEST'; + $res=DocumentManager::file_visible_to_user($this_course, $doc_url); + $this->assertTrue(is_bool($res)); } /** @@ -119,9 +123,13 @@ class TestDocumentManager extends UnitTestCase { $to_group_id = 0; $to_user_id = NULL; $can_see_invisible = false; - $res=DocumentManager::get_all_document_data($_course, $path, $to_group_id, - $to_user_id, $can_see_invisible); - $this->assertTrue(is_array($_course)); + $res=DocumentManager::get_all_document_data($_course, $path, + $to_group_id, $to_user_id, $can_see_invisible); + if (empty($_course['dbName'])) { + $this->assertFalse($res); + } else { + $this->assertTrue(is_array($res)); + } } /** @@ -136,8 +144,12 @@ class TestDocumentManager extends UnitTestCase { global $_course; $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)); + $res = DocumentManager::get_all_document_folders($_course, $to_group_id, $can_see_invisible); + if (empty($_course['dbName'])) { + $this->assertFalse($res); + } else { + $this->assertTrue(is_array($res)); + } } /**