add_course.lib.inc.test.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once api_get_path(LIBRARY_PATH).'add_course.lib.inc.php';
  4. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  5. class TestAddCourse extends UnitTestCase {
  6. function TestAddCourse() {
  7. $this->UnitTestCase('Courses creation - main/inc/lib/add_course.lib.inc.test.php');
  8. }
  9. /*
  10. function TestCreateCourse(){
  11. global $_configuration;
  12. $course_datos = array(
  13. 'wanted_code'=> 'testcourse',
  14. 'title'=>'prueba01',
  15. 'tutor_name'=>'John Doe',
  16. 'category_code'=>'Lang',
  17. 'course_language'=>'english',
  18. 'course_admin_id'=>'1',
  19. 'db_prefix'=> $_configuration['db_prefix'],
  20. 'firstExpirationDelay'=>'120'
  21. );
  22. $res = create_course($course_datos['wanted_code'], $course_datos['title'],
  23. $course_datos['tutor_name'], $course_datos['category_code'],
  24. $course_datos['course_language'],$course_datos['course_admin_id'],
  25. $course_datos['db_prefix'], $course_datos['firstExpirationDelay']);
  26. //should be code string if succeeded (false if failed)
  27. $this->assertTrue(is_string($res));
  28. }*/
  29. function testRegisterCourse() {
  30. global $_configuration;
  31. $course = array(
  32. 'courseSysCode'=> 'testcourse',
  33. 'courseScreenCode' =>'testcourse',
  34. 'courseRepository' =>'testcourse',
  35. 'courseDbName' => $_configuration['db_prefix'].'testcourse',
  36. 'titular' =>'John Doe',
  37. 'category' =>'Lang',
  38. 'title' =>'test course',
  39. 'course_language' =>'english',
  40. 'uidCreator'=> '1',
  41. );
  42. $res = AddCourse::register_course($course['courseSysCode'],$course['courseScreenCode'],
  43. $course['courseRepository'],$course['courseDbName'],
  44. $course['titular'],$course['category'],$course['title'],
  45. $course['course_language'],$course['uidCreator'],
  46. null,null
  47. );
  48. $this->assertTrue($res === 0);
  49. $res = CourseManager::delete_course($course['courseSysCode']);
  50. }
  51. function TestGenerateCourseCode(){
  52. global $charset;
  53. $course_title = 'testcourse';
  54. $res = CourseManager::generate_course_code($course_title);
  55. $this->assertTrue($res);
  56. }
  57. function TestDefineCourseKeys(){
  58. global $prefixAntiNumber, $_configuration;
  59. $wantedCode = CourseManager::generate_course_code($wantedCode);
  60. $res = AddCourse::define_course_keys(CourseManager::generate_course_code($wantedCode), null, null, null,null, null);
  61. $this->assertTrue($res);
  62. }
  63. function TestBrowseFolders(){
  64. $browse = array('path'=>'','file'=>'','media'=>'');
  65. $res = AddCourse::browse_folders($browse['path'], $browse['files'],$browse['media']);
  66. $this->assertFalse($res);
  67. }
  68. /*
  69. // 1 excepcion
  70. function TestSortPictures(){
  71. $picture = array('files'=>'science.jpg', 'type'=>'jpg');
  72. $res = sort_pictures($picture['file'],$picture['type']);
  73. $this->assertTrue(is_array($res));
  74. //var_dump($res);
  75. }
  76. */
  77. /*
  78. function TestFillCourseRepository(){
  79. $courseRepository = 'testcourse';
  80. $res = fill_course_repository($courseRepository);
  81. $this->assertTrue($res);
  82. }
  83. */
  84. function TestLang2db(){
  85. $string = 'test';
  86. $res = AddCourse::lang2db($string);
  87. $this->assertTrue($res);
  88. }
  89. function TestFillDbCourse(){
  90. global $_configuration, $_user;
  91. $courseDbName = $_configuration['table_prefix'].$courseDbName.$_configuration['db_glue'];
  92. $courseRepository = (api_get_path(SYS_COURSE_PATH).$courseRepository . "/dropbox/.htaccess");
  93. $language = 'english';
  94. $language_interface = $language;
  95. $default_document_array = array();
  96. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  97. $courseDbName = $_configuration['db_prefix'].$courseDbName.$_configuration['db_glue'];
  98. $courseRepository = 'testcourse';
  99. $language = 'english';
  100. $default_document_array ='testdocument';
  101. $res = AddCourse::fill_db_course($courseDbName, $courseRepository, $language);
  102. $this->assertTrue($res === 0);
  103. }
  104. function TestString2Binary(){
  105. $variable = true;
  106. $res = AddCourse::string2binary($variable);
  107. $this->assertTrue($res);
  108. }
  109. public function TestDeleteCourse(){
  110. $code = 'testcourse';
  111. $res = CourseManager::delete_course($code);
  112. $path = api_get_path(SYS_PATH).'archive';
  113. if ($handle = opendir($path)) {
  114. while (false !== ($file = readdir($handle))) {
  115. if (strpos($file,$code)!==false) {
  116. if (is_dir($path.'/'.$file)) {
  117. rmdirr($path.'/'.$file);
  118. }
  119. }
  120. }
  121. closedir($handle);
  122. }
  123. }
  124. }