fileManage.lib.test.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. //require_once(api_get_path(LIBRARY_PATH).'classManager.lib.php');
  3. class TestFileManager extends UnitTestCase {
  4. public $fmanager;
  5. public function TestFileManager(){
  6. $this->UnitTestCase ('File Manager library - main/inc/lib/fileManage.lib.test.php');
  7. }
  8. public function setUp(){
  9. $this->fmanager = new FileManager();
  10. }
  11. public function tearDown(){
  12. $this->fmanager = null;
  13. }
  14. //todo public function testUpdatedbInfo
  15. //todo public function testCheckNameExist
  16. //todo public function testMyDelete
  17. //todo public function testRemoveDir
  18. //todo public function testMyRename
  19. //todo public function testMove
  20. //todo public function testCopyDirTo
  21. //todo public function testIndexDir
  22. //todo public function testIndexAndSortDir
  23. //todo public function testFormDirList
  24. //todo public function testMkpath
  25. //todo public function testGetextension
  26. //todo public function testDirsize
  27. //todo public function testListAllDirectories
  28. //todo public function testListAllFiles
  29. //todo public function testCompatLoadFile
  30. //todo public function testSetDefaultSettings
  31. //todo public function testMkdirs
  32. public function testUpdatedbInfo(){
  33. $action ='';
  34. $oldPath ='';
  35. $res = update_db_info($action, $oldPath, $newPath="");
  36. $this->assertNull($res);
  37. //var_dump($res);
  38. }
  39. public function testCheckNameExist(){
  40. $filePath ='';
  41. $res = check_name_exist($filePath);
  42. $this->assertFalse($res);
  43. $this->assertTrue(is_bool($res));
  44. $this->assertTrue($res === false);
  45. //var_dump($res);
  46. }
  47. public function testMyDelete(){
  48. $file='';
  49. $res = my_delete($file);
  50. $this->assertFalse($res);
  51. $this->assertTrue(is_bool($res));
  52. $this->assertTrue($res===false);
  53. //var_dump($res);
  54. }
  55. public function testRemoveDir(){
  56. $dir='';
  57. $res = removeDir($dir);
  58. $this->assertTrue(is_bool($res));
  59. $this->assertFalse($res === true);
  60. //var_dump($res);
  61. }
  62. public function testMyRename(){
  63. $filePath ='document/';
  64. $newFileName='';
  65. $res = my_rename($filePath, $newFileName);
  66. $this->assertTrue(is_bool($res));
  67. $this->assertTrue($res === false);
  68. //var_dump($res);
  69. }
  70. public function testMove(){
  71. $source ='';
  72. $target ='';
  73. $res = move($source, $target);
  74. $this->assertTrue(is_bool($res));
  75. $this->assertTrue($res === false);
  76. $this->assertFalse($res);
  77. //var_dump($res);
  78. }
  79. public function testCopyDirTo(){
  80. $origDirPath=api_get_path(SYS_COURSE_PATH).'document/audio';
  81. $destination=api_get_path(SYS_COURSE_PATH).'document/flash/audio';
  82. $res = copyDirTo($origDirPath, $destination, $move = false);
  83. $this->assertTrue($res===null);
  84. $this->assertNull($res);
  85. }
  86. public function testIndexDir(){
  87. $path=api_get_path(SYS_COURSE_PATH).'document/';
  88. $res = index_dir($path);
  89. if(!is_null($res)) {
  90. $this->assertTrue(is_array($res));
  91. } else {
  92. $this->assertFalse($res);
  93. }
  94. //var_dump($res);
  95. }
  96. public function testIndexAndSortDir(){
  97. $path=api_get_path(SYS_COURSE_PATH).'document/';
  98. $res = index_and_sort_dir($path);
  99. if(!is_bool($res)) {
  100. $this->assertTrue($res);
  101. $this->assertTrue(is_array($res));
  102. }
  103. //var_dump($res);
  104. }
  105. public function testFormDirList(){
  106. $sourceType = '';
  107. $sourceComponent = '';
  108. $command = '';
  109. $baseWorkDir = api_get_path(SYS_COURSE_PATH).'document/';
  110. $res = form_dir_list($sourceType, $sourceComponent, $command, $baseWorkDir);
  111. $this->assertTrue($res);
  112. $this->assertTrue(is_string($res));
  113. //var_dump($res);
  114. }
  115. public function testMkpath(){
  116. $path=api_get_path(SYS_COURSE_PATH).'document/';
  117. $res =mkpath($path, $verbose=false);
  118. if(!is_null($res)) {
  119. $this->assertTrue(is_bool($res));
  120. }
  121. //var_dump($res);
  122. }
  123. public function testGetextension(){
  124. $filename='documents';
  125. $res =getextension($filename);
  126. $this->assertTrue($res);
  127. $this->assertTrue(is_array($res));
  128. }
  129. public function testDirsize(){
  130. $root='';
  131. $res =dirsize($root,$recursive=true);
  132. $this->assertFalse($res);
  133. $this->assertTrue(is_numeric($res));
  134. $this->assertTrue($res ===0);
  135. //var_dump($res);
  136. }
  137. public function testListAllDirectories(){
  138. $path=api_get_path(SYS_COURSE_PATH).'document/';
  139. $res = $this->fmanager->list_all_directories($path);
  140. if(!is_null($res)) {
  141. $this->assertTrue($res);
  142. $this->assertTrue(is_array($res));
  143. }
  144. //var_dump($res);
  145. }
  146. public function testListAllFiles(){
  147. $dirArray = array('COURSETEST, document, images');
  148. $res = $this->fmanager->list_all_files($dirArray);
  149. $this->assertFalse($res);
  150. $this->assertTrue(is_array($res));
  151. $this->assertTrue($res === array());
  152. //var_dump($res);
  153. }
  154. public function testCompatLoadFile(){
  155. $file_name='README.txt';
  156. $res = $this->fmanager->compat_load_file($file_name);
  157. $this->assertTrue(is_string($res));
  158. //var_dump($res);
  159. }
  160. public function testSetDefaultSettings(){
  161. global $_course, $_configuration;
  162. $upload_path=api_get_path(SYS_COURSE_PATH);
  163. $filename='index.html';
  164. $glue_table = $_course['dbName'].'.document';
  165. $res = $this->fmanager->set_default_settings($upload_path, $filename, $filetype="file", $glue_table, $default_visibility='v');
  166. $this->assertNull($res);
  167. //var_dump($res);
  168. }
  169. }
  170. ?>