statistics.lib.test.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. class TestStatistics extends UnitTestCase
  3. {
  4. public function TestStatistics()
  5. {
  6. $this->UnitTestCase('this File test the provides some function for statistics ');
  7. }
  8. public function setUp()
  9. {
  10. $this->statisc = new Statistics();
  11. }
  12. public function tearDown()
  13. {
  14. $this->statisc = null;
  15. }
  16. public function testMakeSizeString()
  17. {
  18. $size = 20960000;
  19. $res = Statistics::makeSizeString($size);
  20. $this->assertTrue(is_string($res));
  21. //var_dump($res);
  22. }
  23. /**
  24. * Count courses
  25. * @param string $category_code Code of a course category. Default: count
  26. * all courses.
  27. * @return int Number of courses counted
  28. */
  29. public function testCountCourses()
  30. {
  31. $res = Statistics::countCourses();
  32. $this->assertTrue(is_numeric($res));
  33. //var_dump($res);
  34. }
  35. public function testCountUsers()
  36. {
  37. $user_id = '1';
  38. $category_code = null;
  39. $course_code = 'ABC';
  40. $firstName = 'Jhon';
  41. $lastName = 'Doe';
  42. $status = '1';
  43. $email = 'localhost@localhost.com';
  44. $loginName = 'admin';
  45. $password = 'admin';
  46. $count_invisible_courses = true;
  47. $res = Statistics::countUsers($status, $category_code,
  48. $count_invisible_courses);
  49. $this->assertTrue(is_numeric($res));
  50. $this->assertTrue(count($res) === 0 || count($res) !== 0);
  51. }
  52. public function testGetNumberOfActivities()
  53. {
  54. $resu = Statistics::getNumberOfActivities();
  55. if (!is_null($resu)) {
  56. $this->assertTrue(is_numeric($resu));
  57. $this->assertTrue(count($resu) == 0 || count($resu) !== 0);
  58. }
  59. }
  60. /**
  61. * Get activities data to display
  62. */
  63. public function testGetActivitiesData()
  64. {
  65. global $dateTimeFormatLong;
  66. $from = 0;
  67. $number_of_items = 30;
  68. $column = '';
  69. $direction = 'ASC';
  70. $resu = Statistics::getActivitiesData($from, $number_of_items, $column,
  71. $direction);
  72. $this->assertTrue(is_array($resu));
  73. }
  74. /**
  75. * Get all course categories
  76. * @return array All course categories (code => name)
  77. */
  78. public function testGetCourseCategories()
  79. {
  80. $res = Statistics::getCourseCategories();
  81. $this->assertTrue($res);
  82. //var_dump($res);
  83. }
  84. public function testRescale()
  85. {
  86. $data = array('test', 'test2', 'test3');
  87. $max = 500;
  88. $res = Statistics::rescale($data, $max);
  89. $this->assertTrue($res);
  90. $this->assertTrue(is_array($res));
  91. //var_dump($res);
  92. }
  93. public function testPrintStats()
  94. {
  95. ob_start();
  96. $title = 'testing';
  97. $stats = array('test', 'test2', 'test3');
  98. $show_total = true;
  99. $is_file_size = false;
  100. $res = Statistics::printStats(
  101. $title,
  102. $stats,
  103. $show_total = true,
  104. $is_file_size = false
  105. );
  106. ob_end_clean();
  107. $this->assertTrue(is_null($res));
  108. //var_dump($res);
  109. }
  110. public function testPrintLoginStats()
  111. {
  112. ob_start();
  113. $type = 'month';
  114. $resu = Statistics::printLoginStats($type);
  115. ob_end_clean();
  116. $this->assertTrue(is_null($resu));
  117. //var_dump($resu);
  118. }
  119. public function testPrintRecentLoginStats()
  120. {
  121. ob_start();
  122. $res = Statistics::printRecentLoginStats();
  123. ob_end_clean();
  124. $this->assertTrue(is_null($res));
  125. //var_dump($res);
  126. }
  127. public function testPrintToolStats()
  128. {
  129. ob_start();
  130. $resu = Statistics::printToolStats();
  131. ob_end_clean();
  132. $this->assertTrue(is_null($resu));
  133. }
  134. public function testPrintCourseByLanguageStats()
  135. {
  136. ob_start();
  137. $resu = Statistics::printCourseByLanguageStats();
  138. ob_end_clean();
  139. $this->assertTrue(is_null($resu));
  140. //var_dump($resu);
  141. }
  142. public function testPrintUserPicturesStats()
  143. {
  144. ob_start();
  145. $resu = Statistics::printUserPicturesStats();
  146. ob_end_clean();
  147. $this->assertTrue(is_null($resu));
  148. }
  149. public function testPrintActivitiesStats()
  150. {
  151. ob_start();
  152. $res = Statistics::printActivitiesStats();
  153. ob_end_clean();
  154. $this->assertTrue(is_null($res));
  155. //var_dump($res);
  156. }
  157. public function testPrintCourseLastVisit()
  158. {
  159. ob_start();
  160. $column = '';
  161. $direction = '';
  162. $parameters['action'] = 'courselastvisit';
  163. $res = Statistics::printCourseLastVisit();
  164. ob_end_clean();
  165. $this->assertTrue(is_null($res));
  166. }
  167. }
  168. ?>