database.lib.test.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <?php
  2. require_once(api_get_path(LIBRARY_PATH).'database.lib.php');
  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 TestDatabase extends UnitTestCase {
  6. public $dbase;
  7. public function TestDatabase() {
  8. $this->UnitTestCase('data base test');
  9. }
  10. public function setUp() {
  11. global $_configuration;
  12. $this->dbase = new Database();
  13. }
  14. public function tearDown() {
  15. $this->dbase = null;
  16. }
  17. public function testAffectedRows() {
  18. $res=$this->dbase->affected_rows();
  19. $this->assertTrue(is_numeric($res));
  20. }
  21. public function testCountRows() {
  22. $table='class';
  23. $res=$this->dbase->count_rows($table);
  24. if(!is_string($res)){
  25. $this->assertTrue(is_numeric($res));
  26. }
  27. }
  28. public function testError() {
  29. $res=$this->dbase->error();
  30. $this->assertTrue(is_string($res));
  31. }
  32. public function testEscapeString() {
  33. $string='Lore"May';
  34. $res=$this->dbase->escape_string($string);
  35. //print_r($string);
  36. $this->assertTrue(is_string($res));
  37. }
  38. public function testFetchArray() {
  39. $sql = 'select 1';
  40. $res=Database::query($sql,__FILE__,__LINE__);
  41. $resu=$this->dbase->fetch_array($res);
  42. $this->assertTrue(is_array($resu));
  43. $this->assertFalse(is_null($resu));
  44. }
  45. public function testFetchArrayError() {
  46. $sql ="SELECT 1";
  47. $res=Database::query($sql,__FILE__,__LINE__);
  48. $resu=$this->dbase->fetch_array($res);
  49. $this->assertTrue(is_array($resu));
  50. }
  51. function testFetchObject() {
  52. $sql ="SELECT 1";
  53. $res=Database::query($sql,__FILE__,__LINE__);
  54. $resu=$this->dbase->fetch_object($res);
  55. $this->assertTrue(is_object($resu));
  56. }
  57. function testFetchRow() {
  58. $sql ="SELECT 1";
  59. $res=Database::query($sql,__FILE__,__LINE__);
  60. $resu=$this->dbase->fetch_row($res);
  61. $this->assertTrue(is_array($resu));
  62. }
  63. function testFixDatabaseParameterEmpty() {
  64. $course_info = api_get_course_info();
  65. $database_name= $course_info[""];
  66. $res=$this->dbase->fix_database_parameter($database_name);
  67. if(!is_null($res)) :
  68. $this->assertTrue(is_string($res));
  69. endif;
  70. //var_dump($res);
  71. }
  72. function testFixDatabaseParameterReturnString() {
  73. $course_info = api_get_course_info();
  74. $database_name= $course_info["dbName"];
  75. $res=$this->dbase->fix_database_parameter($course_info);
  76. $this->assertTrue(is_string($res));
  77. }
  78. function testFormatGluedCourseTableName() {
  79. $database_name_with_glue='';
  80. $table='';
  81. $res=$this->dbase->format_glued_course_table_name($database_name_with_glue, $table);
  82. $this->assertTrue(is_string($res));
  83. }
  84. function testFormatTableName() {
  85. $database='';
  86. $table='';
  87. $res=$this->dbase->format_table_name($database, $table);
  88. $this->assertTrue(is_string($res));
  89. }
  90. function testGenerateAbstractCourseFieldNames() {
  91. $result_array='';
  92. $res=$this->dbase->generate_abstract_course_field_names($result_array);
  93. $this->assertTrue(is_array($res));
  94. }
  95. function testGenerateAbstractUserFieldNames() {
  96. $result_array='';
  97. $res=$this->dbase->generate_abstract_user_field_names($result_array);
  98. $this->assertTrue(is_array($res));
  99. }
  100. function get_course_by_category() {
  101. $category_id='1';
  102. $res=$this->dbase->get_course_by_category($category_id);
  103. $this->assertTrue(is_string($res));
  104. }
  105. function testGetCourseChatConnectedTable() {
  106. $database_name='dokeosla';
  107. $res=$this->dbase->get_course_chat_connected_table($database_name);
  108. $this->assertTrue(is_string($res));
  109. }
  110. function testGetCourseInfo() {
  111. $course_code='AYDD';
  112. $res=$this->dbase->get_course_info($course_code);
  113. $this->assertTrue(is_array($res));
  114. }
  115. function testGetCourseList() {
  116. $sql_query = "SELECT * FROM $table";
  117. $res=$this->dbase->get_course_list($sql_query);
  118. $this->assertTrue(is_array($res));
  119. }
  120. function testGetCourseTable() {
  121. $short_table_name='';
  122. $database_name='';
  123. $res=$this->dbase->get_course_table($short_table_name,$database_name);
  124. $this->assertTrue(is_string($res));
  125. }
  126. function testGetCourseTableFromCode() {
  127. $course_code='AYDD';
  128. $table='course';
  129. $ret = NULL;
  130. $res=$this->dbase->get_course_table_from_code($course_code, $table);
  131. $this->assertTrue(is_string($res));
  132. }
  133. function testGetCourseTablePrefix() {
  134. global $_configuration;
  135. $res=$this->dbase->get_course_table_prefix($_configuration);
  136. $this->assertTrue(is_string($res));
  137. }
  138. function testGetCurrentCourseDatabase() {
  139. $res=$this->dbase->get_current_course_database();
  140. if(!is_null($res)) :
  141. $this->assertTrue(is_string($res));
  142. endif;
  143. //var_dump($res);
  144. }
  145. function testGetCurrentCourseGluedDatabase() {
  146. $res=$this->dbase->get_current_course_glued_database();
  147. if(!is_null($res)):
  148. $this->assertTrue(is_string($res));
  149. endif;
  150. //var_dump($res);
  151. }
  152. function testGetDatabaseGlue()
  153. {
  154. global $_configuration;
  155. $res=$this->dbase->get_database_glue($_configuration);
  156. $this->assertTrue(is_string($res));
  157. }
  158. function testGetDatabaseNamePrefix() {
  159. global $_configuration;
  160. $res=$this->dbase->get_database_name_prefix($_configuration);
  161. $this->assertTrue(is_string($res));
  162. }
  163. function testGetMainDatabase() {
  164. global $_configuration;
  165. $res=$this->dbase->get_main_database();
  166. $this->assertTrue(is_string($res));
  167. }
  168. function testGetMainTable() {
  169. $short_table_name='';
  170. $res=$this->dbase->get_main_table($short_table_name);
  171. $this->assertTrue(is_string($res));
  172. }
  173. function testGetScormDatabase() {
  174. global $_configuration;
  175. $res=$this->dbase->get_scorm_database();
  176. $this->assertTrue(is_string($res));
  177. }
  178. function testGetScorm_table() {
  179. $short_table_name='';
  180. $res=$this->dbase->get_scorm_table($short_table_name);
  181. $this->assertTrue(is_string($res));
  182. $this->assertTrue($res);
  183. }
  184. function testGetStatisticDatabase() {
  185. global $_configuration;
  186. $res=$this->dbase->get_statistic_database($_configuration);
  187. $this->assertTrue(is_string($res));
  188. $this->assertTrue($res);
  189. }
  190. function testGetStatisticTable() {
  191. $short_table_name='';
  192. $res=$this->dbase->get_statistic_table($short_table_name);
  193. $this->assertTrue(is_string($res));
  194. $this->assertTrue($res);
  195. }
  196. function testGetUserInfoFromId() {
  197. $user_id = '';
  198. $res=$this->dbase->get_user_info_from_id($user_id);
  199. $this->assertTrue(is_array($res));
  200. $this->assertTrue($res);
  201. //var_dump($res);
  202. }
  203. function testGetUserPersonalDatabase() {
  204. global $_configuration;
  205. $res=$this->dbase->get_user_personal_database($_configuration);
  206. $this->assertTrue(is_string($res));
  207. $this->assertTrue($res);
  208. }
  209. function testGetUserPersonalTable(){
  210. $short_table_name='';
  211. $res=$this->dbase-> get_user_personal_table($short_table_name);
  212. $this->assertTrue(is_string($res));
  213. $this->assertTrue($res);
  214. }
  215. function testGlueCourseDatabaseName() {
  216. $database_name='';
  217. $res=$this->dbase->glue_course_database_name($database_name);
  218. $this->assertTrue(is_string($res));
  219. $this->assertTrue($res);
  220. }
  221. function testInsertId() {
  222. $res=$this->dbase->insert_id();
  223. $this->assertTrue(is_numeric($res));
  224. }
  225. function testNumRows() {
  226. $sql= "SELECT * FROM chamilo_main.user";
  227. $res = Database::query($sql);
  228. $resul=Database::num_rows($res);
  229. $this->assertTrue(is_numeric($resul));
  230. //var_Dump($res);
  231. }
  232. function testQuery() {
  233. $sql ="SELECT 1";
  234. $res=$this->dbase->query($sql,__FILE__,__LINE__);
  235. $this->assertTrue(is_resource($res));
  236. }
  237. function testResult() {
  238. $sql="SELECT * FROM chamilo_main.user";
  239. $resource= Database::query($sql,__FILE__,__LINE__);
  240. $row= 1;
  241. $res= Database::result($resource, $row);
  242. $this->assertTrue(is_string($res));
  243. //var_dump($res);
  244. }
  245. function testStoreResult(){
  246. $sql="SELECT 1";
  247. $resource=$this->dbase->query($sql,__FILE__,__LINE__);
  248. $res = $this->dbase->store_result($resource);
  249. $this->assertTrue(is_array($res));
  250. //var_dump($res);
  251. }
  252. }
  253. ?>