chat_functions.lib.test.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. require_once(api_get_path(SYS_CODE_PATH).'chat/chat_functions.lib.php');
  3. require_once(api_get_path(LIBRARY_PATH).'course.lib.php');
  4. class TestChatFunctions extends UnitTestCase {
  5. public function __construct(){
  6. $this->UnitTestCase('Chat library - main/chat/chat_functions.lib.test.php');
  7. }
  8. public function setUp() {
  9. $this->tcourse = new CourseManager();
  10. }
  11. public function tearDown() {
  12. $this->tcourse = null;
  13. }
  14. function testuser_connected_in_chat () {
  15. $course_code = 'COURSETEST';
  16. $user_id = 1;
  17. $res = user_connected_in_chat($user_id);
  18. $this->assertTrue(is_bool($res));
  19. }
  20. function testUsersListInChat () {
  21. $course_code = 'COURSETEST';
  22. $course_info = api_get_course_info($course_code);
  23. $database_name = $course_info['dbName'];
  24. $res = users_list_in_chat($database_name);
  25. $this->assertTrue(is_array($res));
  26. //var_dump($res);
  27. }
  28. function CreateChatConnection($database_name) {
  29. $session_id = 1;
  30. $tbl_chat_connected = Database::get_main_table(TABLE_MAIN_CHAT);
  31. $sql = "SELECT user_id FROM $tbl_chat_connected WHERE user_id = 1";
  32. $result = Database::query($sql);
  33. //The user_id exists so we must do an UPDATE and not a INSERT
  34. $current_time = date('Y-m-d H:i:s');
  35. if (Database::num_rows($result)==0) {
  36. $query="INSERT INTO $tbl_chat_connected(user_id,last_connection,session_id)
  37. VALUES(1,'$current_time','$session_id')";
  38. } else {
  39. $query="UPDATE $tbl_chat_connected set last_connection='".$current_time."'
  40. WHERE user_id=1 AND session_id='$session_id'";
  41. }
  42. Database::query($query);
  43. }
  44. function testExitOfChat () {
  45. $course_code = 'COURSETEST';
  46. $course_info = api_get_course_info($course_code);
  47. $database_name = $course_info['dbName'];
  48. $this->CreateChatConnection($database_name);
  49. $user_id = 1;
  50. $res = exit_of_chat($user_id);
  51. //$resu = $this->tcourse->delete_course($course_code);
  52. $this->assertTrue(is_null($res));
  53. //var_dump($res);
  54. }
  55. function testDisconnectUserOfChat() {
  56. $_SESSION['is_courseAdmin'] = 1;
  57. $course_code = 'COURSETEST';
  58. $course_info = api_get_course_info($course_code);
  59. $database_name = $course_info['dbName'];
  60. $this->CreateChatConnection($database_name);
  61. $res = disconnect_user_of_chat($database_name);
  62. $this->assertTrue(is_null($res));
  63. }
  64. }
  65. ?>