diff --git a/tests/main/admin/statistics/statistics.lib.test.php b/tests/main/admin/statistics/statistics.lib.test.php index 7951089b86..2915a3863f 100644 --- a/tests/main/admin/statistics/statistics.lib.test.php +++ b/tests/main/admin/statistics/statistics.lib.test.php @@ -145,7 +145,172 @@ class TestStatistics extends UnitTestCase{ } public function testGetCourseCategories(){ - + $user_id =002; + $category_code = NULL; + $course_code='ABCDE'; + $real_course_code='00001'; + $course_title='test1'; + $wanted_course_code='test2'; + $course_language='es'; + $course_category='primary'; + $code='00001'; + $session_id = SessionManager::create_session($course_code,2009,07,20,2010,07,20,0,0,1,'coach'); + CourseManager::create_virtual_course ($real_course_code, $course_title, $wanted_course_code, $course_language, $course_category); + $res = Statistics::get_course_categories(); + $this->assertTrue($res); + CourseManager::delete_course($code); + //var_dump($res); + } + + public function testRescale(){ + $data=array('aas','aaa'.'aab'); + $max = 500; + $res = Statistics::rescale($data, $max); + $this->assertTrue($res); + $this->assertTrue(is_array($res)); + //var_dump($res); + } + + public function testPrintStats(){ + ob_start(); + $title='testing'; + $stats=array('aa','bb','cc'); + $show_total = true; + $is_file_size = false; + $res = Statistics::print_stats($title, $stats, $show_total = true, $is_file_size = false); + ob_end_clean(); + $this->assertTrue(is_null($res)); + //var_dump($res); + } + + public function testPrintLoginStats(){ + ob_start(); + $instans = new MockDatabase(); + $type='january'; + $table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN); + if($type === 'month'){ + $sql = "SELECT DATE_FORMAT( login_date, '%Y %b' ) AS stat_date , count( login_id ) AS number_of_logins FROM ".$table." GROUP BY stat_date ORDER BY login_date "; + }if($type === 'hour'){ + $sql = "SELECT DATE_FORMAT( login_date, '%H' ) AS stat_date , count( login_id ) AS number_of_logins FROM ".$table." GROUP BY stat_date ORDER BY stat_date "; + }else{ + $sql = "SELECT DATE_FORMAT( login_date, '%a' ) AS stat_date , count( login_id ) AS number_of_logins FROM ".$table." GROUP BY stat_date ORDER BY DATE_FORMAT( login_date, '%w' ) "; + } + $res = api_sql_query($sql,__FILE__,__LINE__); + $obj = Database::fetch_object($res); + $result[$obj->stat_date] = $obj->number_of_logins; + $login_stats[] = $result; + $resu = Statistics::print_login_stats($type); + ob_end_clean(); + $instans->expectOnce($login_stats); + $this->assertTrue(is_null($resu)); + $this->assertTrue($result); + //var_dump($resu); + //var_dump($result); + } + + public function testPrintRecenLoginStats(){ + ob_start(); + $instans = new MockDatabase(); + $total_logins = array(); + $table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN); + $query[get_lang('Total')] = "SELECT count(login_user_id) AS number FROM $table"; + $res = api_sql_query($query,__FILE__,__LINE__); + $obj = Database::fetch_object($res); + $total_logins[] = $obj->number; + $res = Statistics::print_recent_login_stats(); + ob_end_clean(); + $instans->expectCallCount($total_logins); + $this->assertTrue(is_null($res)); + $this->assertTrue(count($total_logins)); + //var_dump($res); + //var_dump($total_logins); + } + + public function testPrintToolStats(){ + ob_start(); + $instans = new MockDatabase(); + $table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS); + $tools = array('announcement','assignment','calendar_event','chat','conference','course_description','document','dropbox','group','learnpath','link','quiz','student_publication','user','bb_forum'); + $sql = "SELECT access_tool, count( access_id ) AS number_of_logins FROM $table WHERE access_tool IN ('".implode("','",$tools)."') GROUP BY access_tool "; + $res = api_sql_query($sql,__FILE__,__LINE__); + $result = array(); + $obj = Database::fetch_object($res); + $result[$obj->access_tool] = $obj->number_of_logins; + $resu = Statistics::print_tool_stats(); + ob_end_clean(); + $instans->expectCallCount($result); + $this->assertTrue(is_null($resu)); + //var_dump($resu); + //var_dump($result); } + + public function testPrintCourseByLanguageStats(){ + ob_start(); + $instans = new MockDatabase(); + $table = Database::get_main_table(TABLE_MAIN_COURSE); + $sql = "SELECT course_language, count( code ) AS number_of_courses FROM $table GROUP BY course_language "; + $res = api_sql_query($sql,__FILE__,__LINE__); + $result = array(); + $obj = Database::fetch_object($res); + $result[$obj->course_language] = $obj->number_of_courses; + $instans->expectOnce($result); + $resu = Statistics::print_course_by_language_stats(); + ob_end_clean(); + $this->assertTrue(is_null($resu)); + $this->assertTrue(is_array($result)); + //var_dump($resu); + //var_dump($result); + } + + public function testPrintUserPicturesStats(){ + ob_start(); + $instans = new MockDatabase(); + $user_table = Database :: get_main_table(TABLE_MAIN_USER); + $sql = "SELECT COUNT(*) AS n FROM $user_table"; + $res = api_sql_query($sql,__FILE__,__LINE__); + $count1 = Database::fetch_object($res); + $instans_print[]= $count1; + $instans->expectOnce($instans_print); + $instans->expectCallCount($instans_print); + $resu = Statistics::print_user_pictures_stats(); + ob_end_clean(); + $this->assertTrue(is_null($resu)); + $this->assertTrue($instans_print); + //var_dump($resu); + //var_dump($instans_print); + } + + public function testPrintActivitiesStats(){ + ob_start(); + $res = Statistics::print_activities_stats(); + ob_end_clean(); + $this->assertTrue(is_null($res)); + //var_dump($res); + } + + public function testPrintCourseLastVisit(){ + ob_start(); + $instans = new MockDatabase(); + $instans1 = new MockDisplay(); + $table_header[] = array ("Coursecode", true); + $course = array (); + $courses[] = $course; + $column=''; + $direction=''; + $parameters['action'] = 'courselastvisit'; + $instans->expectCallCount('Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS)'); + $instans1->expectOnce(Display :: display_sortable_table($table_header, $courses, array('column'=>$column,'direction'=>$direction), array (), $parameters)); + $res = Statistics::print_course_last_visit(); + ob_end_clean(); + $this->assertTrue(is_null($res)); + //var_dump($res); + } + + + + + + + } ?>