database.lib.test.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. /* // Contains a private unaccessible method, Database::fix_database_parameter().
  64. function testFixDatabaseParameterEmpty() {
  65. $course_info = api_get_course_info();
  66. $database_name= $course_info[""];
  67. $res=$this->dbase->fix_database_parameter($database_name);
  68. if(!is_null($res)) :
  69. $this->assertTrue(is_string($res));
  70. endif;
  71. //var_dump($res);
  72. }
  73. */
  74. /* // Contains a private unaccessible method, Database::fix_database_parameter().
  75. function testFixDatabaseParameterReturnString() {
  76. $course_info = api_get_course_info();
  77. $database_name= $course_info["dbName"];
  78. $res=$this->dbase->fix_database_parameter($course_info);
  79. $this->assertTrue(is_string($res));
  80. }
  81. */
  82. /* // Contains a private unaccessible method, Database::format_glued_course_table_name().
  83. function testFormatGluedCourseTableName() {
  84. $database_name_with_glue='';
  85. $table='';
  86. $res=$this->dbase->format_glued_course_table_name($database_name_with_glue, $table);
  87. $this->assertTrue(is_string($res));
  88. }
  89. */
  90. /* // Contains a private unaccessible method, Database::format_table_name().
  91. function testFormatTableName() {
  92. $database='';
  93. $table='';
  94. $res=$this->dbase->format_table_name($database, $table);
  95. $this->assertTrue(is_string($res));
  96. }
  97. */
  98. function testGenerateAbstractCourseFieldNames() {
  99. $result_array='';
  100. $res=$this->dbase->generate_abstract_course_field_names($result_array);
  101. $this->assertTrue(is_array($res));
  102. }
  103. function testGenerateAbstractUserFieldNames() {
  104. $result_array='';
  105. $res=$this->dbase->generate_abstract_user_field_names($result_array);
  106. $this->assertTrue(is_array($res));
  107. }
  108. function get_course_by_category() {
  109. $category_id='1';
  110. $res=$this->dbase->get_course_by_category($category_id);
  111. $this->assertTrue(is_string($res));
  112. }
  113. function testGetCourseChatConnectedTable() {
  114. $database_name='dokeosla';
  115. $res=$this->dbase->get_course_chat_connected_table($database_name);
  116. $this->assertTrue(is_string($res));
  117. }
  118. function testGetCourseInfo() {
  119. $course_code='AYDD';
  120. $res=$this->dbase->get_course_info($course_code);
  121. $this->assertTrue(is_array($res));
  122. }
  123. function testGetCourseList() {
  124. $sql_query = "SELECT * FROM $table";
  125. $res=$this->dbase->get_course_list($sql_query);
  126. $this->assertTrue(is_array($res));
  127. }
  128. function testGetCourseTable() {
  129. $short_table_name='';
  130. $database_name='';
  131. $res=$this->dbase->get_course_table($short_table_name,$database_name);
  132. $this->assertTrue(is_string($res));
  133. }
  134. function testGetCourseTableFromCode() {
  135. $course_code='AYDD';
  136. $table='course';
  137. $ret = NULL;
  138. $res=$this->dbase->get_course_table_from_code($course_code, $table);
  139. $this->assertTrue(is_string($res));
  140. }
  141. function testGetCourseTablePrefix() {
  142. global $_configuration;
  143. $res=$this->dbase->get_course_table_prefix($_configuration);
  144. $this->assertTrue(is_string($res));
  145. }
  146. function testGetCurrentCourseDatabase() {
  147. $res=$this->dbase->get_current_course_database();
  148. if(!is_null($res)) :
  149. $this->assertTrue(is_string($res));
  150. endif;
  151. //var_dump($res);
  152. }
  153. function testGetCurrentCourseGluedDatabase() {
  154. $res=$this->dbase->get_current_course_glued_database();
  155. if(!is_null($res)):
  156. $this->assertTrue(is_string($res));
  157. endif;
  158. //var_dump($res);
  159. }
  160. function testGetDatabaseGlue()
  161. {
  162. global $_configuration;
  163. $res=$this->dbase->get_database_glue($_configuration);
  164. $this->assertTrue(is_string($res));
  165. }
  166. function testGetDatabaseNamePrefix() {
  167. global $_configuration;
  168. $res=$this->dbase->get_database_name_prefix($_configuration);
  169. $this->assertTrue(is_string($res));
  170. }
  171. function testGetMainDatabase() {
  172. global $_configuration;
  173. $res=$this->dbase->get_main_database();
  174. $this->assertTrue(is_string($res));
  175. }
  176. function testGetMainTable() {
  177. $short_table_name='';
  178. $res=$this->dbase->get_main_table($short_table_name);
  179. $this->assertTrue(is_string($res));
  180. }
  181. function testGetScormDatabase() {
  182. global $_configuration;
  183. $res=$this->dbase->get_scorm_database();
  184. $this->assertTrue(is_string($res));
  185. }
  186. function testGetScorm_table() {
  187. $short_table_name='';
  188. $res=$this->dbase->get_scorm_table($short_table_name);
  189. $this->assertTrue(is_string($res));
  190. $this->assertTrue($res);
  191. }
  192. function testGetStatisticDatabase() {
  193. global $_configuration;
  194. $res=$this->dbase->get_statistic_database($_configuration);
  195. $this->assertTrue(is_string($res));
  196. $this->assertTrue($res);
  197. }
  198. function testGetStatisticTable() {
  199. $short_table_name='';
  200. $res=$this->dbase->get_statistic_table($short_table_name);
  201. $this->assertTrue(is_string($res));
  202. $this->assertTrue($res);
  203. }
  204. function testGetUserInfoFromId() {
  205. $user_id = '';
  206. $res=$this->dbase->get_user_info_from_id($user_id);
  207. $this->assertTrue(is_array($res));
  208. $this->assertTrue($res);
  209. //var_dump($res);
  210. }
  211. function testGetUserPersonalDatabase() {
  212. global $_configuration;
  213. $res=$this->dbase->get_user_personal_database($_configuration);
  214. $this->assertTrue(is_string($res));
  215. $this->assertTrue($res);
  216. }
  217. function testGetUserPersonalTable(){
  218. $short_table_name='';
  219. $res=$this->dbase-> get_user_personal_table($short_table_name);
  220. $this->assertTrue(is_string($res));
  221. $this->assertTrue($res);
  222. }
  223. /* // Contains a private unaccessible method, Database::glue_course_database_name().
  224. function testGlueCourseDatabaseName() {
  225. $database_name='';
  226. $res=$this->dbase->glue_course_database_name($database_name);
  227. $this->assertTrue(is_string($res));
  228. $this->assertTrue($res);
  229. }
  230. */
  231. function testInsertId() {
  232. $res=$this->dbase->insert_id();
  233. $this->assertTrue(is_numeric($res));
  234. }
  235. function testNumRows() {
  236. $sql= "SELECT * FROM chamilo_main.user";
  237. $res = Database::query($sql);
  238. $resul=Database::num_rows($res);
  239. $this->assertTrue(is_numeric($resul));
  240. //var_Dump($res);
  241. }
  242. function testQuery() {
  243. $sql ="SELECT 1";
  244. $res=$this->dbase->query($sql,__FILE__,__LINE__);
  245. $this->assertTrue(is_resource($res));
  246. }
  247. function testResult() {
  248. $sql="SELECT * FROM chamilo_main.user";
  249. $resource= Database::query($sql,__FILE__,__LINE__);
  250. $row= 1;
  251. $res= Database::result($resource, $row);
  252. $this->assertTrue(is_string($res));
  253. //var_dump($res);
  254. }
  255. function testStoreResult(){
  256. $sql="SELECT 1";
  257. $resource=$this->dbase->query($sql,__FILE__,__LINE__);
  258. $res = $this->dbase->store_result($resource);
  259. $this->assertTrue(is_array($res));
  260. //var_dump($res);
  261. }
  262. }
  263. ?>