stats.lib.inc.test.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. require_once(api_get_path(LIBRARY_PATH).'stats.lib.inc.php');
  3. class TestStats extends UnitTestCase {
  4. public function __construct() {
  5. $this->UnitTestCase('System stats library - main/inc/lib/stats.lib.test.php');
  6. }
  7. function testaddBrowser() {
  8. $browser='';
  9. $browsers_array=array();
  10. $res=addBrowser($browser,$browsers_array);
  11. $this->assertTrue(is_array($res));
  12. }
  13. function testaddCountry(){
  14. $country='';
  15. $countries_array=array();
  16. $res=addCountry($country,$countries_array);
  17. $this->assertTrue(is_array($res));
  18. //var_dump($res);
  19. }
  20. function testaddOs() {
  21. $os='';
  22. $os_array=array();
  23. $res=addOs($os,$os_array);
  24. $this->assertTrue(is_array($res));
  25. //var_dump($res);
  26. }
  27. function testaddProvider() {
  28. $provider='';
  29. $providers_array=array();
  30. $res=addProvider($provider,$providers_array);
  31. $this->assertTrue(is_array($res));
  32. //var_dump($res);
  33. }
  34. function testaddReferer() {
  35. $referer='';
  36. $referers_array=array();
  37. $res=addReferer($referer,$referers_array);
  38. $this->assertTrue(is_array($res));
  39. //var_dump($res);
  40. }
  41. function testcleanProcessedRecords() {
  42. global $TABLETRACK_OPEN;
  43. $limit='';
  44. $res=cleanProcessedRecords($limit);
  45. if(!is_null($res)) $this->assertTrue(is_string($res));
  46. //var_dump($res);
  47. }
  48. function testdecodeOpenInfos() { // 3 excepciones
  49. //ob_start();
  50. global $_course, $TABLETRACK_OPEN, $_configuration;
  51. $TABLETRACK_OPEN = $_configuration['statistics_database'].".track_e_open";
  52. $ignore = ignore_user_abort();
  53. $res=decodeOpenInfos();
  54. //ob_end_clean();
  55. if (!is_null($res)){
  56. $this->assertTrue(is_null($res));
  57. $this->assertTrue(is_numeric($ignore));
  58. //var_dump($res);
  59. }
  60. }
  61. function testextractAgent() {
  62. $user_agent=$_SERVER['HTTP_USER_AGENT'];
  63. $list_browsers=array();
  64. $list_os=array();
  65. $res=extractAgent($user_agent, $list_browsers, $list_os );
  66. $this->assertTrue(is_string($res));
  67. //var_dump($res);
  68. }
  69. function testextractCountry() {
  70. $remhost= @getHostByAddr($_SERVER['REMOTE_ADDR']);
  71. $list_countries=array();
  72. $res=extractCountry($remhost,$list_countries);
  73. if(!is_null($res))$this->assertTrue(is_string($res));
  74. //var_dump($res);
  75. }
  76. function testextractProvider() {
  77. $remhost=@getHostByAddr($_SERVER['REMOTE_ADDR']);
  78. $res=extractProvider($remhost);
  79. if(!is_null($res))$this->assertTrue(is_string($res));
  80. //var_dump($res);
  81. }
  82. function testfillBrowsersTable() {
  83. global $TABLESTATS_BROWSERS;
  84. $browsers_array=array();
  85. $res=fillBrowsersTable($browsers_array);
  86. if(!is_null($res)) $this->assertTrue(is_array($res));
  87. //var_dump($res);
  88. }
  89. function testfillCountriesTable() {
  90. global $TABLESTATS_COUNTRIES,$_configuration;
  91. $TABLESTATS_COUNTRIES = $_configuration['statistics_database'].".track_c_countries";
  92. $countries_array=array();
  93. $res=fillCountriesTable($countries_array);
  94. $this->assertTrue(is_null($res));
  95. //var_dump($res);
  96. }
  97. function testfillOsTable() {
  98. global $TABLESTATS_OS;
  99. $os_array=array();
  100. $res=fillOsTable($os_array);
  101. $this->assertTrue(is_null($res));
  102. //var_dump($res);
  103. }
  104. function testfillProvidersTable() {
  105. global $TABLESTATS_PROVIDERS;
  106. $providers_array=array();
  107. $res=fillProvidersTable($providers_array);
  108. $this->assertTrue(is_null($res));
  109. //var_dump($res);
  110. }
  111. function testfillReferersTable() {
  112. global $TABLESTATS_REFERERS;
  113. $referers_array=array();
  114. $res=fillReferersTable($referers_array);
  115. $this->assertTrue(is_null($res));
  116. //var_dump($res);
  117. }
  118. function testloadBrowsers() {
  119. $res=loadBrowsers();
  120. $this->assertTrue(is_array($res));
  121. //var_dump($res);
  122. }
  123. function testloadCountries() {
  124. global $TABLESTATS_COUNTRIES,$_configuration;
  125. $TABLESTATS_COUNTRIES = $_configuration['statistics_database'].".track_c_countries";
  126. $res=loadCountries();
  127. if (!is_null($res)){
  128. $this->assertTrue(is_array($res));
  129. }
  130. //var_dump($res);
  131. }
  132. function testloadOs() {
  133. $res=loadOs();
  134. $this->assertTrue(is_array($res));
  135. //var_dump($res);
  136. }
  137. }
  138. ?>