Feature #347 - Quality tests: Removing the parameters __FILE__ and __LINE__ in the Database::query() calls.

skala
Ivan Tcholakov 16 years ago
parent c2c757eed0
commit 0dba37654b
  1. 22
      tests/main/chat/chat_functions.lib.test.php
  2. 16
      tests/main/exercice/hotpotatoes.lib.test.php
  3. 62
      tests/main/inc/lib/course.lib.test.php
  4. 14
      tests/main/inc/lib/database.lib.test.php
  5. 6
      tests/main/inc/lib/surveymanager.lib.test.php
  6. 2
      tests/main/inc/lib/usermanager.lib.test.php
  7. 72
      tests/test_suite.php

@ -7,7 +7,7 @@ class TestChatFunctions extends UnitTestCase {
public function setUp() {
$this->tcourse = new CourseManager();
}
public function tearDown() {
$this->tcourse = null;
}
@ -16,13 +16,13 @@ class TestChatFunctions extends UnitTestCase {
function testuser_connected_in_chat () {
$course_code = 'COURSETEST';
$user_id=1;
$user_id=1;
$course_info = api_get_course_info($course_code);
$database_name = $course_info['dbName'];
$res = user_connected_in_chat($user_id,$database_name);
$this->assertTrue(is_bool($res));
$this->assertTrue(is_bool($res));
}
function testUsersListInChat () {
$course_code = 'COURSETEST';
@ -32,7 +32,7 @@ class TestChatFunctions extends UnitTestCase {
$this->assertTrue(is_array($res));
//var_dump($res);
}
function CreateChatConnection($database_name) {
$session_id = 1;
$tbl_chat_connected = Database::get_course_chat_connected_table($database_name);
@ -45,9 +45,9 @@ class TestChatFunctions extends UnitTestCase {
} else {
$query="UPDATE $tbl_chat_connected set last_connection='".$current_time."' WHERE user_id=1 AND session_id='$session_id'";
}
Database::query($query,__FILE__,__LINE__);
Database::query($query);
}
function testExitOfChat () {
$course_code = 'COURSETEST';
@ -60,16 +60,16 @@ class TestChatFunctions extends UnitTestCase {
$this->assertTrue(is_null($res));
//var_dump($res);
}
function testDisconnectUserOfChat() {
$_SESSION['is_courseAdmin'] = 1;
$course_code = 'COURSETEST';
$course_info = api_get_course_info($course_code);
$database_name = $course_info['dbName'];
$this->CreateChatConnection($database_name);
$this->CreateChatConnection($database_name);
$res = disconnect_user_of_chat($database_name);
$this->assertTrue(is_null($res));
}
}
}
?>

@ -34,7 +34,7 @@ class TestHotpotatoes extends UnitTestCase {
$this->assertTrue(is_string($res));
//var_dump($res);
}
function testGenerateHpFolder() {
@ -45,14 +45,14 @@ class TestHotpotatoes extends UnitTestCase {
}
function testGetComment() {
$course_code = 'COURSETEST';
$course_code = 'COURSETEST';
$path = 'exercice_submit.php';
$query ="select comment from $dbTable where path='$path'";
$res=GetComment($path,$course_code);
$this->assertTrue(is_string($res));
//var_dump($res);
}
/* Deprecated
@ -95,7 +95,7 @@ class TestHotpotatoes extends UnitTestCase {
}
function testGetQuizName() {
$course_code = 'COURSETEST';
$course_code = 'COURSETEST';
$fname='exercice_submit.php';
$fpath='main/exercice/exercice_submit.php';
$res=GetQuizName($fname,$fpath);
@ -156,17 +156,17 @@ class TestHotpotatoes extends UnitTestCase {
$comment='testing this function';
$comment = Database::escape_string($comment);
$query = "UPDATE $dbTable set comment='$comment' where path='$path'";
$result = Database::query($query,__FILE__,__LINE__);
$result = Database::query($query);
$res=SetComment($path,$comment);
$this->assertTrue(is_string($res));
//var_dump($resu);
}
function testWriteFileCont() {
$course_code = 'COURSETEST';
$course_code = 'COURSETEST';
$full_file_path='/main/exercice/';
$content='test test test';
$res=WriteFileCont($full_file_path,$content);
$res=WriteFileCont($full_file_path,$content);
$this->assertTrue(is_bool($res));
//var_dump($res);
}

@ -19,11 +19,11 @@ class TestCourse extends UnitTestCase{
$this->UnitTestCase('All main course function tests');
}
public function setUp(){
global $_configuration;
$this->tcourse = new CourseManager();
$course_datos = array(
'wanted_code'=> 'COURSE1',
'title'=>'COURSE1',
@ -37,27 +37,27 @@ class TestCourse extends UnitTestCase{
$res = create_course($course_datos['wanted_code'], $course_datos['title'],
$course_datos['tutor_name'], $course_datos['category_code'],
$course_datos['course_language'],$course_datos['course_admin_id'],
$course_datos['db_prefix'], $course_datos['firstExpirationDelay']);
$course_datos['db_prefix'], $course_datos['firstExpirationDelay']);
}
public function tearDown(){
$this->tcourse = null;
$this->dbase = null;
$code = 'COURSE1';
$res = CourseManager::delete_course($code);
$path = api_get_path(SYS_PATH).'archive';
$code = 'COURSE1';
$res = CourseManager::delete_course($code);
$path = api_get_path(SYS_PATH).'archive';
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if (strpos($file,$code)!==false) {
if (is_dir($path.'/'.$file)) {
rmdirr($path.'/'.$file);
}
}
while (false !== ($file = readdir($handle))) {
if (strpos($file,$code)!==false) {
if (is_dir($path.'/'.$file)) {
rmdirr($path.'/'.$file);
}
}
}
closedir($handle);
}
}
}
/*
@ -190,9 +190,9 @@ class TestCourse extends UnitTestCase{
}
/** Return a array() but now its empty, with this test is cheking is get the list course
* @author Arthur Portugal <arthur.portugal@dokeos.com> -
* @author Arthur Portugal <arthur.portugal@dokeos.com> -
* doesn't work correctly refactoring by Ricardo Rodriguez <ricardo.rodriguez@beeznest.com>
**/
**/
public function testGetRealCourseList(){
$res = CourseManager::get_real_course_list();
@ -204,7 +204,7 @@ class TestCourse extends UnitTestCase{
public function testGetVirtualCourseList(){
$course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
$sql_query = "SELECT * FROM $course_table WHERE target_course_code IS NOT NULL";
$sql_result = Database::query($sql_query, __FILE__, __LINE__);
$sql_result = Database::query($sql_query);
$result = Database::fetch_array($sql_result);
$virtual_course_list[] = $result;
$res=$this->tcourse->get_virtual_course_list();
@ -254,8 +254,8 @@ class TestCourse extends UnitTestCase{
$user_is_registered_in_real_course = false;
$real_course_name = 'COURSE1';
$virtual_course_list = array();
$res = CourseManager::create_combined_name($user_is_registered_in_real_course,
$real_course_name,
$res = CourseManager::create_combined_name($user_is_registered_in_real_course,
$real_course_name,
$virtual_course_list
);
$this->assertFalse($res);
@ -265,11 +265,11 @@ class TestCourse extends UnitTestCase{
public function testCreateCombinedCode(){
$complete_course_code = array();
$user_is_registered_in_real_course = false;
$real_course_code = 'COURSE1';
$user_is_registered_in_real_course = false;
$real_course_code = 'COURSE1';
$virtual_course_list = array();
$res = CourseManager::create_combined_code($user_is_registered_in_real_course,
$real_course_code,
$res = CourseManager::create_combined_code($user_is_registered_in_real_course,
$real_course_code,
$virtual_course_list);
if(is_array($res)){
$this->assertFalse($res);
@ -345,7 +345,7 @@ class TestCourse extends UnitTestCase{
}
public function testIsCourseTeacher(){
$user_id = 1;
$user_id = 1;
$course_code = 'COURSE1';
$res = CourseManager::is_course_teacher($user_id, $course_code);
$this->assertTrue(is_bool($res));
@ -443,7 +443,7 @@ class TestCourse extends UnitTestCase{
ob_start();
$res = CourseManager::attempt_create_virtual_course($real_course_code, $course_title, $wanted_course_code, $course_language, $course_category);
ob_end_clean();
$this->assertTrue(is_bool($res));
$this->assertTrue(is_bool($res));
}
public function testCreateVirtualCourse(){
@ -462,7 +462,7 @@ class TestCourse extends UnitTestCase{
}
//var_dump($res);
}
public function testCreateDatabaseDump(){
global $_configuration;
$course_code='COURSE1';
@ -559,18 +559,18 @@ class TestCourse extends UnitTestCase{
$this->assertTrue(is_bool($res));
$this->assertFalse(is_null($res));
}
public function testDeleteCourse(){
global $_configuration;
$code = 'COURSE1';
if (!empty($course_code)) {
$code = $course_code;
}
}
$res = CourseManager::delete_course($code);
$this->assertTrue(is_null($res));
$this->assertTrue(is_null($res));
}
}
?>

@ -45,7 +45,7 @@ class TestDatabase extends UnitTestCase {
public function testFetchArray() {
$sql = 'select 1';
$res=Database::query($sql,__FILE__,__LINE__);
$res=Database::query($sql);
$resu=$this->dbase->fetch_array($res);
$this->assertTrue(is_array($resu));
$this->assertFalse(is_null($resu));
@ -53,21 +53,21 @@ class TestDatabase extends UnitTestCase {
public function testFetchArrayError() {
$sql ="SELECT 1";
$res=Database::query($sql,__FILE__,__LINE__);
$res=Database::query($sql);
$resu=$this->dbase->fetch_array($res);
$this->assertTrue(is_array($resu));
}
function testFetchObject() {
$sql ="SELECT 1";
$res=Database::query($sql,__FILE__,__LINE__);
$res=Database::query($sql);
$resu=$this->dbase->fetch_object($res);
$this->assertTrue(is_object($resu));
}
function testFetchRow() {
$sql ="SELECT 1";
$res=Database::query($sql,__FILE__,__LINE__);
$res=Database::query($sql);
$resu=$this->dbase->fetch_row($res);
$this->assertTrue(is_array($resu));
}
@ -282,13 +282,13 @@ class TestDatabase extends UnitTestCase {
function testQuery() {
$sql ="SELECT 1";
$res=$this->dbase->query($sql,__FILE__,__LINE__);
$res=$this->dbase->query($sql);
$this->assertTrue(is_resource($res));
}
function testResult() {
$sql="SELECT * FROM chamilo_main.user";
$resource= Database::query($sql,__FILE__,__LINE__);
$resource= Database::query($sql);
$row= 1;
$res= Database::result($resource, $row);
$this->assertTrue(is_string($res));
@ -297,7 +297,7 @@ class TestDatabase extends UnitTestCase {
function testStoreResult(){
$sql="SELECT 1";
$resource=$this->dbase->query($sql,__FILE__,__LINE__);
$resource=$this->dbase->query($sql);
$res = $this->dbase->store_result($resource);
$this->assertTrue(is_array($res));
//var_dump($res);

@ -40,7 +40,7 @@ class TestSurveyManager extends UnitTestCase {
$this->assertTrue(is_numeric($res));
//var_dump($res);
}
function testattach_survey() {
$surveyid='';
$newsurveyid='';
@ -115,7 +115,7 @@ class TestSurveyManager extends UnitTestCase {
global $_user;
$table_user = Database::get_main_table(TABLE_MAIN_USER);
$sqlm = "SELECT status FROM $table_user WHERE user_id = '".Database::escape_string($_user['user_id'])."'";
$resm = Database::query($sqlm,__FILE__,__LINE__);
$resm = Database::query($sqlm);
$objm=@Database::fetch_object($resm);
$ss = $objm->status ;
$res=SurveyManager::get_status();
@ -131,7 +131,7 @@ class TestSurveyManager extends UnitTestCase {
$user_table = Database :: get_main_table(TABLE_MAIN_USER);
$authorid = Database::escape_string($authorid);
$sql_query = "SELECT * FROM $user_table WHERE user_id='$authorid'";
$res = Database::query($sql_query, __FILE__, __LINE__);
$res = Database::query($sql_query);
$firstname=@Database::result($res,0,'firstname');
$res=SurveyManager::get_survey_author($authorid);
$this->assertTrue(is_null($firstname));

@ -171,7 +171,7 @@ class TestUserManager extends UnitTestCase
function testGetExtraFieldInformationByName() {
$sql="SELECT 1";
$field_variable=Database::query($sql,__FILE__,__LINE__);
$field_variable=Database::query($sql);
$res=UserManager::get_extra_field_information_by_name($field_variable);
//var_dump($res);
$this->assertTrue(is_bool($res));

@ -8,7 +8,7 @@ $maindir = dirname(__FILE__).'/../main/';
$incdir = dirname(__FILE__).'/../main/inc/';
$libdir = dirname(__FILE__).'/../main/inc/lib/';
//Need the ob start and clean else will show the objects
//Need the ob start and clean else will show the objects
require_once $incdir.'global.inc.php';
//List of files than need the tests
@ -28,7 +28,7 @@ require_once $libdir.'xmd.lib.php';
require_once $libdir.'formvalidator/FormValidator.class.php';
//Need the ob start and clean else will show the objects
//Need the ob start and clean else will show the objects
ob_start();
require_once $libdir.'main_api.lib.php';
require_once $libdir.'course_document.lib.php';
@ -58,17 +58,17 @@ require_once $libdir.'fileManage.lib.php';
class TestsSuite extends TestSuite {
function setUp() {
global $_configuration, $_user, $_course, $cidReq;
$cidReq = 'COURSETEST';
// check if course exists
// check if course exists
$table_course = Database::get_main_table(TABLE_MAIN_COURSE);
$sql = "SELECT code FROM $table_course WHERE code = '$cidReq' ";
$rs = Database::query($sql, __FILE__, __LINE__);
$rs = Database::query($sql);
$row = Database::fetch_row($rs);
if (empty($row[0])) {
// create a course
$course_datos = array(
'wanted_code'=> $cidReq,
@ -85,7 +85,7 @@ class TestsSuite extends TestSuite {
$course_datos['course_language'],$course_datos['course_admin_id'],
$course_datos['db_prefix'], $course_datos['firstExpirationDelay']);
}
$course_table = Database::get_main_table(TABLE_MAIN_COURSE);
$course_cat_table = Database::get_main_table(TABLE_MAIN_CATEGORY);
$sql = "SELECT course.*, course_category.code faCode, course_category.name faName
@ -93,10 +93,10 @@ class TestsSuite extends TestSuite {
LEFT JOIN $course_cat_table
ON course.category_code = course_category.code
WHERE course.code = '$cidReq'";
$result = Database::query($sql,__FILE__,__LINE__);
$result = Database::query($sql);
//create the session
if (Database::num_rows($result)>0) {
$cData = Database::fetch_array($result);
$_cid = $cData['code' ];
@ -117,16 +117,16 @@ class TestsSuite extends TestSuite {
$_course['visibility' ] = $cData['visibility'];
$_course['subscribe_allowed'] = $cData['subscribe'];
$_course['unubscribe_allowed'] = $cData['unsubscribe'];
api_session_register('_cid');
api_session_register('_course');
}
$_SESSION['_user']['user_id'] = 1;
$_SESSION['_user']['user_id'] = 1;
$_user['user_id'] = $_SESSION['_user']['user_id'];
$_SESSION['is_courseAdmin'] = 1;
$_SESSION['show'] = showall;
}
function TestsSuite() {
$this->setUp();
@ -143,13 +143,13 @@ class TestsSuite extends TestSuite {
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/classmanager.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/export.lib.inc.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/legal.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/mail.lib.inc.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/mail.lib.inc.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/message.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/online.inc.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/online.inc.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/security.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/specific_fields_manager.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/specific_fields_manager.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/social.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/sortabletable.class.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/sortabletable.class.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/statsUtils.lib.inc.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/tablesort.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/text.lib.test.php');
@ -178,15 +178,15 @@ class TestsSuite extends TestSuite {
$this->addTestFile(dirname(__FILE__).'/main/auth/openid/xrds.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/chat/chat_functions.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/conference/get_translation.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/exercice/hotpotatoes.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/exercice/hotpotatoes.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/newscorm/scorm.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/survey/survey.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/user/userInfoLib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/webservices/user_import/import.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/user/userInfoLib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/webservices/user_import/import.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/work/work.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/glossary.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/notebook.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/permissions/permissions_functions.inc.test.php');
$this->addTestFile(dirname(__FILE__).'/main/permissions/permissions_functions.inc.test.php');
$this->addTestFile(dirname(__FILE__).'/main/resourcelinker/resourcelinker.inc.test.php');
$this->addTestFile(dirname(__FILE__).'/main/survey/survey.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/dropbox/dropbox_class.inc.test.php');
@ -194,17 +194,17 @@ class TestsSuite extends TestSuite {
$this->addTestFile(dirname(__FILE__).'/main/search/search_suggestions.test.php');
$this->addTestFile(dirname(__FILE__).'/main/exercice/export/qti2/qti2_classes.test.php');
$this->addTestFile(dirname(__FILE__).'/main/exercice/export/scorm/scorm_classes.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/usermanager.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/groupmanager.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/image.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/usermanager.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/groupmanager.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/image.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/import.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/internationalization.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/internationalization.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/system_announcements.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/fileUpload.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/main_api.lib.test.php');//this file delete the course
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/main_api.lib.test.php');//this file delete the course
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/debug.lib.inc.test.php');//this file need be to the finish of the tests
*/
*/
//This files has metadata, are deprecated, are not implemented and is not available for the test.
//$this->addTestFile(dirname(__FILE__).'/main/inc/lib/xht.lib.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/inc/lib/xmd.lib.test.php');
@ -212,18 +212,18 @@ class TestsSuite extends TestSuite {
//$this->addTestFile(dirname(__FILE__).'/main/exercice/export/qti2/qti2_export.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/exercice/export/exercise_import.inc.test.php');
//$this->addTestFile(dirname(__FILE__).'/main/exercice/export/scorm/scorm_export.test.php');
/**EJERCICIOS**/
$this->addTestFile(dirname(__FILE__).'/main/exercice/answer.class.test.php');
$this->addTestFile(dirname(__FILE__).'/main/exercice/exercise_result.class.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/exercise_show_functions.lib.test.php');
$this->addTestFile(dirname(__FILE__).'/main/exercice/exercise.class.test.php');
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/main_api.lib.test.php');//this file delete the course
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/main_api.lib.test.php');//this file delete the course
$this->addTestFile(dirname(__FILE__).'/main/inc/lib/debug.lib.inc.test.php');//this file need be to the finish of the tests
}
}
$test = &new TestsSuite();

Loading…
Cancel
Save