mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-28 23:03:25 +09:00
add some unit tests for CUBRID
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0-DB@8456 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
d7cf3cb731
commit
e41c45433e
10 changed files with 814 additions and 9 deletions
38
test-phpUnit/DeleteXmlTest_Cubrid.php
Normal file
38
test-phpUnit/DeleteXmlTest_Cubrid.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
require('config.inc.php');
|
||||
|
||||
class DeleteXmlTest_Cubrid extends PHPUnit_Framework_TestCase {
|
||||
|
||||
function _test($xml_file, $argsString, $expected){
|
||||
$tester = new QueryTester();
|
||||
$outputString = $tester->getNewParserOutputString($xml_file, '"', $argsString);
|
||||
echo $outputString;
|
||||
$output = eval($outputString);
|
||||
|
||||
if(!is_a($output, 'Query')){
|
||||
if(!$output->toBool()) $querySql = "Date incorecte! Query-ul nu a putut fi executat.";
|
||||
}else {
|
||||
$db = new DBCubrid();
|
||||
$querySql = $db->getDeleteSql($output);
|
||||
|
||||
// Remove whitespaces, tabs and all
|
||||
$querySql = Helper::cleanQuery($querySql);
|
||||
$expected = Helper::cleanQuery($expected);
|
||||
}
|
||||
|
||||
// Test
|
||||
$this->assertEquals($expected, $querySql);
|
||||
}
|
||||
|
||||
function test_module_deleteActionForward(){
|
||||
$xml_file = _XE_PATH_ . "modules/module/queries/deleteActionForward.xml";
|
||||
$argsString = '$args->module = "page";
|
||||
$args->type = "page";
|
||||
$args->act = "tata";';
|
||||
$expected = 'delete from "xe_action_forward" as "action_forward"
|
||||
where "module" = \'page\'
|
||||
and "type" = \'page\'
|
||||
and "act" = \'tata\'';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
<?php
|
||||
define('_XE_PATH_', str_replace('test-phpUnit/ExpressionParserTest.php', '', str_replace('\\', '/', __FILE__)));
|
||||
require(_XE_PATH_.'classes/xml/xmlquery/DBParser.class.php');
|
||||
require('config.inc.php');
|
||||
|
||||
class ExpressionParserTest extends PHPUnit_Framework_TestCase {
|
||||
/* Escape char for:
|
||||
|
|
@ -8,7 +7,6 @@
|
|||
* MySql ``
|
||||
* SqlServer []
|
||||
*/
|
||||
|
||||
var $dbLeftEscapeChar = '[';
|
||||
var $dbRightEscapeChar = ']';
|
||||
|
||||
|
|
|
|||
14
test-phpUnit/Helper.class.php
Normal file
14
test-phpUnit/Helper.class.php
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
class Helper {
|
||||
function cleanQuery($query){
|
||||
$query = trim(preg_replace('/\s+/', ' ',$query));
|
||||
$query = str_replace(" , ", ', ', $query);
|
||||
$query = str_replace("( ", '(', $query);
|
||||
$query = str_replace(" )", ')', $query);
|
||||
$query = strtolower($query);
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
140
test-phpUnit/InsertXmlTest_Cubrid.php
Normal file
140
test-phpUnit/InsertXmlTest_Cubrid.php
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
<?php
|
||||
require('config.inc.php');
|
||||
|
||||
class InsertXmlTest_Cubrid extends PHPUnit_Framework_TestCase {
|
||||
|
||||
function _test($xml_file, $argsString, $expected){
|
||||
$tester = new QueryTester();
|
||||
$outputString = $tester->getNewParserOutputString($xml_file, '"', $argsString);
|
||||
//echo $outputString;
|
||||
$output = eval($outputString);
|
||||
|
||||
if(!is_a($output, 'Query')){
|
||||
if(!$output->toBool()) $querySql = "Date incorecte! Query-ul nu a putut fi executat.";
|
||||
}else {
|
||||
$db = new DBCubrid();
|
||||
$querySql = $db->getInsertSql($output);
|
||||
|
||||
// Remove whitespaces, tabs and all
|
||||
$querySql = Helper::cleanQuery($querySql);
|
||||
$expected = Helper::cleanQuery($expected);
|
||||
}
|
||||
|
||||
// Test
|
||||
$this->assertEquals($expected, $querySql);
|
||||
}
|
||||
|
||||
function test_module_insertModule(){
|
||||
$xml_file = _XE_PATH_ . "modules/module/queries/insertModule.xml";
|
||||
$argsString = ' $args->module_category_srl = 0;
|
||||
$args->browser_title = "test";
|
||||
$args->layout_srl = 0;
|
||||
$args->mlayout_srl = 0;
|
||||
$args->module = "page";
|
||||
$args->mid = "test";
|
||||
$args->site_srl = 0;
|
||||
$args->module_srl = 47374;';
|
||||
$expected = 'insert into "xe_modules"
|
||||
("site_srl"
|
||||
, "module_srl"
|
||||
, "module_category_srl"
|
||||
, "mid"
|
||||
, "browser_title"
|
||||
, "layout_srl"
|
||||
, "module"
|
||||
, "is_default"
|
||||
, "open_rss"
|
||||
, "regdate"
|
||||
, "mlayout_srl"
|
||||
, "use_mobile")
|
||||
values
|
||||
(0
|
||||
, 47374
|
||||
, 0
|
||||
, \'test\'
|
||||
, \'test\'
|
||||
, 0
|
||||
, \'page\'
|
||||
, \'n\'
|
||||
, \'y\'
|
||||
, \''.date("YmdHis").'\'
|
||||
, 0
|
||||
, \'n\')';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_module_insertSiteTodayStatus(){
|
||||
//\''.date("YmdHis").'\'
|
||||
$xml_file = _XE_PATH_ . "modules/counter/queries/insertTodayStatus.xml";
|
||||
$argsString = ' $args->regdate = 0;
|
||||
$args->unique_visitor = 0;
|
||||
$args->pageview = 0;';
|
||||
$expected = 'insert into "xe_counter_status"
|
||||
("regdate"
|
||||
, "unique_visitor"
|
||||
, "pageview")
|
||||
values
|
||||
(0
|
||||
, 0
|
||||
, 0)';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_module_insertCounterLog(){
|
||||
$xml_file = _XE_PATH_ . "modules/counter/queries/insertCounterLog.xml";
|
||||
$argsString = ' $args->site_srl = 0;
|
||||
$args->regdate = "20110607120619";
|
||||
$args->ipaddress = "127.0.0.1";
|
||||
$args->user_agent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.77 Safari/534.24";';
|
||||
$expected = 'insert into "xe_counter_log"
|
||||
("site_srl", "regdate", "ipaddress", "user_agent")
|
||||
VALUES (0, \'20110607120619\', \'127.0.0.1\', \'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.77 Safari/534.24\')
|
||||
';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_module_insertMember(){
|
||||
$xml_file = _XE_PATH_ . "modules/member/queries/insertMember.xml";
|
||||
$argsString = ' $args->member_srl = 203;
|
||||
$args->user_id = "cacao";
|
||||
$args->email_address = "teta@ar.ro";
|
||||
$args->password = "23e5484cb88f3c07bcce2920a5e6a2a7";
|
||||
$args->email_id = "teta";
|
||||
$args->email_host = "ar.ro";
|
||||
$args->user_name = "trident";
|
||||
$args->nick_name = "aloha";
|
||||
$args->homepage = "http://jkgjfk./ww";
|
||||
$args->allow_mailing = "Y";
|
||||
$args->allow_message = "Y";
|
||||
$args->denied = "N";
|
||||
$args->limit_date = "";
|
||||
$args->regdate = "20110607121952";
|
||||
$args->change_password_date = "20110607121952";
|
||||
$args->last_login = "20110607121952";
|
||||
$args->is_admin = "N";
|
||||
$args->extra_vars = "O:8:\"stdClass\":2:{s:4:\"body\";s:0:\"\";s:7:\"_filter\";s:6:\"insert\";}";
|
||||
$args->list_order = -203;
|
||||
';
|
||||
$expected = 'INSERT INTO "xe_member"
|
||||
("member_srl", "user_id", "email_address", "password", "email_id", "email_host", "user_name", "nick_name",
|
||||
"homepage", "allow_mailing", "allow_message", "denied", "limit_date", "regdate", "change_password_date",
|
||||
"last_login", "is_admin", "extra_vars", "list_order")
|
||||
VALUES (203, \'cacao\', \'teta@ar.ro\', \'23e5484cb88f3c07bcce2920a5e6a2a7\', \'teta\', \'ar.ro\', \'trident\',
|
||||
\'aloha\', \'http://jkgjfk./ww\', \'Y\', \'Y\', \'N\', \'\', \'20110607121952\', \'20110607121952\',
|
||||
\'20110607121952\', \'N\', \'O:8:"stdClass":2:{s:4:"body";s:0:"";s:7:"_filter";s:6:"insert";}\', -203)';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_module_insertModuleExtraVars(){
|
||||
$xml_file = _XE_PATH_ . "modules/module/queries/insertModuleExtraVars.xml";
|
||||
$argsString = ' $args->module_srl = 202;
|
||||
$args->name = "_filter";
|
||||
$args->value = "insert_page";
|
||||
';
|
||||
$expected = 'INSERT INTO "xe_module_extra_vars"
|
||||
("module_srl", "name", "value")
|
||||
VALUES (202, \'_filter\', \'insert_page\')
|
||||
';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
}
|
||||
322
test-phpUnit/QueryTester.class.php
Normal file
322
test-phpUnit/QueryTester.class.php
Normal file
|
|
@ -0,0 +1,322 @@
|
|||
<?php
|
||||
|
||||
// Only supports queries inside modules for now
|
||||
|
||||
class QueryTester {
|
||||
|
||||
function QueryTester(){
|
||||
|
||||
}
|
||||
|
||||
function getQueryPath($type, $name, $query_name){
|
||||
return _XE_PATH_ . $type ."/".$name."/queries/" . $query_name . ".xml";
|
||||
}
|
||||
|
||||
function getNewParserOutput($xml_file, $escape_char = '"'){
|
||||
$newXmlQueryParser = new XmlQueryParser();
|
||||
$xml_obj = $newXmlQueryParser->getXmlFileContent($xml_file);
|
||||
|
||||
$dbParser = new DBParser($escape_char);
|
||||
$parser = new QueryParser($xml_obj->query, $dbParser);
|
||||
return $parser->toString();
|
||||
}
|
||||
|
||||
function getOldParserOutput($query_id, $xml_file){
|
||||
$cache_file = _TEST_PATH_ . "cache/".$query_id.'.cache.php';
|
||||
$parser = new OldXmlQueryParser();
|
||||
$parser->parse($query_id, $xml_file, $cache_file);
|
||||
$buff = FileHandler::readFile($cache_file);
|
||||
return $buff;
|
||||
}
|
||||
|
||||
function cleanOutputAndAddArgs($outputString, $argsString = ''){
|
||||
$outputString = str_replace("<?php if(!defined('__ZBXE__')) exit();", "", $outputString);
|
||||
$outputString = str_replace("?>", "", $outputString);
|
||||
$outputString = $argsString . $outputString;
|
||||
return $outputString;
|
||||
}
|
||||
|
||||
function getXmlFileContent($xml_file){
|
||||
return FileHandler::readFile($xml_file);
|
||||
}
|
||||
|
||||
function printOutput($output){
|
||||
if(is_object($output)) {
|
||||
var_dump($output); return;
|
||||
}
|
||||
$output = htmlspecialchars($output);
|
||||
|
||||
$output = preg_replace('/select/i', 'SELECT', $output);
|
||||
$output = preg_replace('/from/i', '<br/>FROM', $output);
|
||||
$output = preg_replace('/where/i', '<br/>WHERE', $output);
|
||||
$output = preg_replace('/group by/i', '<br/>GROUP BY', $output);
|
||||
$output = preg_replace('/order by/i', '<br/>ORDER BY', $output);
|
||||
|
||||
$output = str_replace("\n", "<br/>", $output);
|
||||
|
||||
echo '<pre class=prettyprint>'
|
||||
.$output
|
||||
.'</pre>';
|
||||
}
|
||||
|
||||
function getNewParserOutputString($xml_file, $escape_char, $argsString){
|
||||
$outputString = '';
|
||||
$outputString = $this->getNewParserOutput($xml_file, $escape_char);
|
||||
$outputString = $this->cleanOutputAndAddArgs($outputString, $argsString);
|
||||
return $outputString;
|
||||
}
|
||||
|
||||
function getNewParserQuery($outputString){
|
||||
//echo $outputString;
|
||||
//exit(0);
|
||||
$output = eval($outputString);
|
||||
if(is_a($output, 'Object'))
|
||||
if(!$output->toBool()) return("Date incorecte! Query-ul nu a putut fi executat.");
|
||||
$db = new DBCubrid();
|
||||
if($output->getAction() == 'select')
|
||||
return $db->getSelectSql($output);
|
||||
else if($output->getAction() == 'insert')
|
||||
return $db->getInsertSql($output);
|
||||
else if($output->getAction() == 'update')
|
||||
return $db->getUpdateSql($output);
|
||||
else if($output->getAction() == 'delete')
|
||||
return $db->getDeleteSql($output);
|
||||
}
|
||||
|
||||
function testNewParser($xml_file, $escape_char, $argsString, $show_output_string){
|
||||
$outputString = $this->getNewParserOutputString($xml_file, $escape_char, $argsString);
|
||||
$query = $this->getNewParserQuery($outputString);
|
||||
|
||||
echo '<tr>';
|
||||
if($show_output_string){
|
||||
echo '<td>';
|
||||
$this->printOutput($outputString);
|
||||
echo '</td>';
|
||||
}
|
||||
|
||||
echo '<td>';
|
||||
$this->printOutput($query);
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
|
||||
function getOldParserOutputString($query_id, $xml_file, $argsString){
|
||||
$outputString = $this->getOldParserOutput($query_id, $xml_file);
|
||||
$outputString = $this->cleanOutputAndAddArgs($outputString, $argsString);
|
||||
return $outputString;
|
||||
}
|
||||
|
||||
function getOldParserQuery($outputString){
|
||||
$output = eval($outputString);
|
||||
if(is_a($output, 'Object'))
|
||||
if(!$output->toBool()) exit("Date incorecte! Query-ul nu a putut fi executat.");
|
||||
|
||||
/* SQL Server
|
||||
*
|
||||
$db = new DBMssql(false);
|
||||
if($output->action == "select")
|
||||
return $db->_executeSelectAct($output);
|
||||
else if($output->action == "insert")
|
||||
return $db->_executeInsertAct($output);
|
||||
else if($output->action == "delete")
|
||||
return $db->_executeDeleteAct($output);
|
||||
else if($output->action == "update")
|
||||
return $db->_executeUpdateAct($output);
|
||||
*/
|
||||
|
||||
/*
|
||||
* Mysql
|
||||
*/
|
||||
$db = new DBMysql(false);
|
||||
if($output->action == "select")
|
||||
$db->_executeSelectAct($output);
|
||||
else if($output->action == "insert")
|
||||
$db->_executeInsertAct($output);
|
||||
else if($output->action == "delete")
|
||||
$db->_executeDeleteAct($output);
|
||||
else if($output->action == "update")
|
||||
$db->_executeUpdateAct($output);
|
||||
return $db->getLatestQuery();
|
||||
}
|
||||
|
||||
function testOldParser($query_id, $xml_file, $argsString, $show_output_string){
|
||||
$outputString = $this->getOldParserOutputString($query_id, $xml_file, $argsString);
|
||||
$query = $this->getOldParserQuery($outputString);
|
||||
|
||||
|
||||
echo '<tr>';
|
||||
if($show_output_string){
|
||||
echo '<td>';
|
||||
$this->printOutput($outputString);
|
||||
echo '</td>';
|
||||
}
|
||||
|
||||
echo '<td>';
|
||||
$this->printOutput($query);
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
|
||||
function showXmlInputFile($xml_file){
|
||||
echo '<tr colspan=2>';
|
||||
echo '<td>';
|
||||
$xml_file_content = $this->getXmlFileContent($xml_file);
|
||||
$this->printOutput($xml_file_content);
|
||||
echo '</td></tr>';
|
||||
}
|
||||
|
||||
function test($query_id, $xml_file, $argsString, $show_output_string, $escape_char = '"'){
|
||||
echo "<h3>$query_id</h3>";
|
||||
echo '<table border=1 cellpadding=5 cellspacing=0 width=50%>';
|
||||
|
||||
$this->showXmlInputFile($xml_file);
|
||||
|
||||
$this->testNewParser($xml_file, $escape_char, $argsString, $show_output_string);
|
||||
|
||||
//$this->testOldParser($query_id, $xml_file, $argsString, $show_output_string);
|
||||
|
||||
echo '</table>';
|
||||
}
|
||||
|
||||
function test_addon_getAddonInfo($show_output_string = false){
|
||||
$argsString = '$args->addon = "captcha";';
|
||||
$this->test("modules.addon.getAddonInfo"
|
||||
, $this->getQueryPath("modules", "addon", "getAddonInfo")
|
||||
, $argsString
|
||||
, $show_output_string);
|
||||
}
|
||||
|
||||
function test_addon_getAddons($show_output_string = false){
|
||||
$argsString = '';
|
||||
$this->test("modules.addon.getAddons"
|
||||
, $this->getQueryPath("modules", "addon", "getAddons")
|
||||
, $argsString
|
||||
, $show_output_string);
|
||||
}
|
||||
|
||||
function test_admin_getCommentCount($show_output_string = false){
|
||||
$argsString = '';
|
||||
$this->test("modules.admin.getCommentCount"
|
||||
, $this->getQueryPath("modules", "admin", "getCommentCount")
|
||||
, $argsString
|
||||
, $show_output_string);
|
||||
}
|
||||
|
||||
function test_admin_getCommentDeclaredStatus($show_output_string = false){
|
||||
$argsString = '$args->date = "20110411";';
|
||||
$this->test("modules.admin.getCommentDeclaredStatus"
|
||||
, $this->getQueryPath("modules", "admin", "getCommentDeclaredStatus")
|
||||
, $argsString
|
||||
, $show_output_string);
|
||||
}
|
||||
|
||||
function test_module_getDefaultModules($show_output_string = false){
|
||||
$argsString = '';
|
||||
$this->test("modules.module.getDefaultModules"
|
||||
, $this->getQueryPath("modules", "module", "getDefaultModules")
|
||||
, $argsString
|
||||
, $show_output_string);
|
||||
}
|
||||
|
||||
function test_module_getModuleCategories($show_output_string = false){
|
||||
$argsString = '';
|
||||
$this->test("modules.module.getModuleCategories"
|
||||
, $this->getQueryPath("modules", "module", "getModuleCategories")
|
||||
, $argsString
|
||||
, $show_output_string);
|
||||
}
|
||||
|
||||
function test_module_getNonuniqueDomains($show_output_string = false){
|
||||
$argsString = '';
|
||||
$this->test("modules.module.getNonuniqueDomains"
|
||||
, $this->getQueryPath("modules", "module", "getNonuniqueDomains")
|
||||
, $argsString
|
||||
, $show_output_string);
|
||||
}
|
||||
|
||||
function test_module_getAdminId($show_output_string = false){
|
||||
$argsString = '$args->module_srl = 23;';
|
||||
$this->test("modules.module.getAdminId"
|
||||
, $this->getQueryPath("modules", "module", "getAdminId")
|
||||
, $argsString
|
||||
, $show_output_string);
|
||||
}
|
||||
function test_module_getSiteInfo($show_output_string = false){
|
||||
$argsString = '$args->site_srl = 0;';
|
||||
$this->test("modules.module.getSiteInfo"
|
||||
, $this->getQueryPath("modules", "module", "getSiteInfo")
|
||||
, $argsString
|
||||
, $show_output_string);
|
||||
}
|
||||
function test_module_insertModule($show_output_string = false){
|
||||
$argsString = ' $args->module_category_srl = 0;
|
||||
$args->browser_title = "test";
|
||||
$args->layout_srl = 0;
|
||||
$args->mlayout_srl = 0;
|
||||
$args->module = "page";
|
||||
$args->mid = "test";
|
||||
$args->site_srl = 0;
|
||||
$args->module_srl = 47374;';
|
||||
$this->test("modules.module.insertModule"
|
||||
, $this->getQueryPath("modules", "module", "insertModule")
|
||||
, $argsString
|
||||
, $show_output_string);
|
||||
}
|
||||
function test_module_updateModule($show_output_string = false){
|
||||
$argsString = ' $args->module_category_srl = 0;
|
||||
$args->browser_title = "test";
|
||||
$args->layout_srl = 0;
|
||||
$args->mlayout_srl = 0;
|
||||
$args->module = "page";
|
||||
$args->mid = "test";
|
||||
$args->use_mobile = "";
|
||||
$args->site_srl = 0;
|
||||
$args->module_srl = 47374;';
|
||||
$this->test("modules.module.updateModule"
|
||||
, $this->getQueryPath("modules", "module", "updateModule")
|
||||
, $argsString
|
||||
, $show_output_string);
|
||||
}
|
||||
function test_admin_deleteActionForward($show_output_string = false){
|
||||
$argsString = '$args->module = "page";
|
||||
$args->type = "page";
|
||||
$args->act = "tata";';
|
||||
$this->test("modules.admin.deleteActionForward"
|
||||
, $this->getQueryPath("modules", "module", "deleteActionForward")
|
||||
, $argsString
|
||||
, $show_output_string);
|
||||
}
|
||||
|
||||
function test_member_getAutologin($show_output_string = false){
|
||||
$argsString = '$args->autologin_key = 10;';
|
||||
$this->test("modules.member.getAutologin"
|
||||
, $this->getQueryPath("modules", "member", "getAutologin")
|
||||
, $argsString
|
||||
, $show_output_string);
|
||||
}
|
||||
|
||||
function test_opage_getOpageList($show_output_string = false){
|
||||
$argsString = '$args->s_title = "yuhuu";
|
||||
$args->module = 12;';
|
||||
$this->test("modules.opage.getOpageList"
|
||||
, $this->getQueryPath("modules", "opage", "getOpageList")
|
||||
, $argsString
|
||||
, $show_output_string);
|
||||
}
|
||||
function test_getPageList($show_output_string = false){
|
||||
$argsString = '$args->sort_index = "module_srl";
|
||||
$args->page_count = 10;
|
||||
$args->s_module_category_srl = 0;
|
||||
$args->s_mid = "test";
|
||||
$args->s_browser_title = "caca";';
|
||||
|
||||
$this->test("modules.page.getPageList"
|
||||
, $this->getQueryPath("modules", "page", "getPageList")
|
||||
, $argsString
|
||||
, $show_output_string);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
170
test-phpUnit/SelectXmlTest_Cubrid.php
Normal file
170
test-phpUnit/SelectXmlTest_Cubrid.php
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
<?php
|
||||
require('config.inc.php');
|
||||
|
||||
class SelectXmlTest_Cubrid extends PHPUnit_Framework_TestCase {
|
||||
|
||||
function _test($xml_file, $argsString, $expected){
|
||||
$tester = new QueryTester();
|
||||
$outputString = $tester->getNewParserOutputString($xml_file, '"', $argsString);
|
||||
$output = eval($outputString);
|
||||
if(!is_a($output, 'Query')){
|
||||
if(!$output->toBool()) $querySql = "Date incorecte! Query-ul nu a putut fi executat.";
|
||||
}else {
|
||||
$db = new DBCubrid();
|
||||
$querySql = $db->getSelectSql($output);
|
||||
|
||||
// Remove whitespaces, tabs and all
|
||||
$querySql = Helper::cleanQuery($querySql);
|
||||
$expected = Helper::cleanQuery($expected);
|
||||
}
|
||||
|
||||
// Test
|
||||
$this->assertEquals($expected, $querySql);
|
||||
}
|
||||
|
||||
function testSelectStar(){
|
||||
$xml_file = _XE_PATH_ . "modules/module/queries/getAdminId.xml";
|
||||
$argsString = '$args->module_srl = 10;';
|
||||
$expected = 'SELECT * FROM "xe_module_admins" as "module_admins" , "xe_member" as "member" WHERE "module_srl" = 10 and "member"."member_srl" = "module_admins"."member_srl"';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function testRquiredParameter(){
|
||||
$xml_file = _XE_PATH_ . "modules/module/queries/getAdminId.xml";
|
||||
$argsString = '';
|
||||
$expected = 'Date incorecte! Query-ul nu a putut fi executat.';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function testWithoutCategoriesTag(){
|
||||
$xml_file = _XE_PATH_ . "modules/module/queries/getModuleCategories.xml";
|
||||
$argsString = '';
|
||||
$expected = 'SELECT * FROM "xe_module_categories" as "module_categories" ORDER BY "title" asc';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_module_getDefaultModules(){
|
||||
$xml_file = _XE_PATH_ . "modules/module/queries/getDefaultModules.xml";
|
||||
$argsString = '';
|
||||
$expected = 'SELECT "modules"."site_srl"
|
||||
, "modules"."module"
|
||||
, "modules"."mid"
|
||||
, "modules"."browser_title"
|
||||
, "module_categories"."title" as "category"
|
||||
, "modules"."module_srl"
|
||||
FROM "xe_modules" as "modules"
|
||||
left join "xe_module_categories" as "module_categories"
|
||||
on "module_categories"."module_category_srl" = "modules"."module_category_srl"
|
||||
WHERE "modules"."site_srl" = 0
|
||||
ORDER BY "modules"."module" asc, "module_categories"."title" asc, "modules"."mid" asc';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_module_getSiteInfo(){
|
||||
$xml_file = _XE_PATH_ . "modules/module/queries/getSiteInfo.xml";
|
||||
$argsString = '$args->site_srl = 0;';
|
||||
$expected = 'SELECT "modules"."site_srl" as "module_site_srl"
|
||||
, "modules"."module_srl" as "module_srl"
|
||||
, "modules"."module" as "module"
|
||||
, "modules"."module_category_srl" as "module_category_srl"
|
||||
, "modules"."layout_srl" as "layout_srl"
|
||||
, "modules"."mlayout_srl" as "mlayout_srl"
|
||||
, "modules"."use_mobile" as "use_mobile"
|
||||
, "modules"."menu_srl" as "menu_srl"
|
||||
, "modules"."mid" as "mid"
|
||||
, "modules"."skin" as "skin"
|
||||
, "modules"."mskin" as "mskin"
|
||||
, "modules"."browser_title" as "browser_title"
|
||||
, "modules"."description" as "description"
|
||||
, "modules"."is_default" as "is_default"
|
||||
, "modules"."content" as "content"
|
||||
, "modules"."mcontent" as "mcontent"
|
||||
, "modules"."open_rss" as "open_rss"
|
||||
, "modules"."header_text" as "header_text"
|
||||
, "modules"."footer_text" as "footer_text"
|
||||
, "modules"."regdate" as "regdate"
|
||||
, "sites"."site_srl" as "site_srl"
|
||||
, "sites"."domain" as "domain"
|
||||
, "sites"."index_module_srl" as "index_module_srl"
|
||||
, "sites"."default_language" as "default_language"
|
||||
FROM "xe_sites" as "sites"
|
||||
left join "xe_modules" as "modules" on "modules"."module_srl" = "sites"."index_module_srl"
|
||||
WHERE "sites"."site_srl" = 0 ';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_addon_getAddonInfo(){
|
||||
$xml_file = _XE_PATH_ . "modules/addon/queries/getAddonInfo.xml";
|
||||
$argsString = '$args->addon = "captcha";';
|
||||
$expected = 'SELECT *
|
||||
FROM "xe_addons" as "addons"
|
||||
WHERE "addon" = \'captcha\' ';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_addon_getAddons(){
|
||||
$xml_file = _XE_PATH_ . "modules/addon/queries/getAddons.xml";
|
||||
$argsString = '';
|
||||
$expected = 'SELECT *
|
||||
FROM "xe_addons" as "addons"
|
||||
ORDER BY "addon" asc';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_admin_getCommentCount(){
|
||||
$xml_file = _XE_PATH_ . "modules/admin/queries/getCommentCount.xml";
|
||||
$argsString = '';
|
||||
$expected = 'SELECT count(*) as "count"
|
||||
FROM "xe_comments" as "comments"';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_admin_getCommentDeclaredStatus(){
|
||||
$xml_file = _XE_PATH_ . "modules/admin/queries/getCommentDeclaredStatus.xml";
|
||||
$argsString = '$args->date = "20110411";';
|
||||
$expected = 'SELECT substr("regdate",1,8) as "date", count(*) as "count"
|
||||
FROM "xe_comment_declared_log" as "comment_declared_log"
|
||||
WHERE "regdate" >= \'20110411\'
|
||||
GROUP BY substr("regdate",1,8)
|
||||
ORDER BY substr("regdate",1,8) asc limit 2';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_member_getAutoLogin(){
|
||||
$xml_file = _XE_PATH_ . "modules/member/queries/getAutoLogin.xml";
|
||||
$argsString = '$args->autologin_key = 10;';
|
||||
$expected = 'SELECT "member"."user_id" as "user_id"
|
||||
, "member"."password" as "password"
|
||||
, "member_autologin"."autologin_key" as "autologin_key"
|
||||
FROM "xe_member" as "member" , "xe_member_autologin" as "member_autologin"
|
||||
WHERE "member_autologin"."autologin_key" = \'10\'
|
||||
and "member"."member_srl" = "member_autologin"."member_srl"';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_opage_getOpageList(){
|
||||
$xml_file = _XE_PATH_ . "modules/opage/queries/getOpageList.xml";
|
||||
$argsString = '$args->s_title = "yuhuu";
|
||||
$args->module = \'opage\';';
|
||||
$expected = 'SELECT *
|
||||
FROM "xe_modules" as "modules"
|
||||
WHERE "module" = \'opage\' and ("browser_title" like \'%yuhuu%\')
|
||||
ORDER BY "module_srl" desc
|
||||
LIMIT 0, 20';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_syndication_getGrantedModules(){
|
||||
$xml_file = _XE_PATH_ . "modules/syndication/queries/getGrantedModules.xml";
|
||||
$argsString = '$args->module_srl = 12;
|
||||
$args->name = array(\'access\',\'view\',\'list\');';
|
||||
$expected = 'select "module_srl"
|
||||
from "xe_module_grants" as "module_grants"
|
||||
where "name" in (\'access\',\'view\',\'list\')
|
||||
and ("group_srl" >= -2
|
||||
or "group_srl" = -2
|
||||
or "group_srl" = -2)
|
||||
group by "module_srl"';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
}
|
||||
84
test-phpUnit/UpdateXmlTest_Cubrid.php
Normal file
84
test-phpUnit/UpdateXmlTest_Cubrid.php
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
require('config.inc.php');
|
||||
|
||||
class UpdateXmlTest_Cubrid extends PHPUnit_Framework_TestCase {
|
||||
|
||||
function _test($xml_file, $argsString, $expected){
|
||||
$tester = new QueryTester();
|
||||
$outputString = $tester->getNewParserOutputString($xml_file, '"', $argsString);
|
||||
$output = eval($outputString);
|
||||
if(!is_a($output, 'Query')){
|
||||
if(!$output->toBool()) $querySql = "Date incorecte! Query-ul nu a putut fi executat.";
|
||||
}else {
|
||||
$db = new DBCubrid();
|
||||
$querySql = $db->getUpdateSql($output);
|
||||
|
||||
// Remove whitespaces, tabs and all
|
||||
$querySql = Helper::cleanQuery($querySql);
|
||||
$expected = Helper::cleanQuery($expected);
|
||||
}
|
||||
|
||||
// Test
|
||||
$this->assertEquals($expected, $querySql);
|
||||
}
|
||||
|
||||
function test_module_updateModule(){
|
||||
$xml_file = _XE_PATH_ . "modules/module/queries/updateModule.xml";
|
||||
$argsString = ' $args->module_category_srl = 0;
|
||||
$args->browser_title = "test";
|
||||
$args->layout_srl = 0;
|
||||
$args->mlayout_srl = 0;
|
||||
$args->module = "page";
|
||||
$args->mid = "test";
|
||||
$args->use_mobile = "";
|
||||
$args->site_srl = 0;
|
||||
$args->module_srl = 47374;';
|
||||
$expected = 'UPDATE "xe_modules"
|
||||
SET "module" = \'page\'
|
||||
, "mid" = \'test\'
|
||||
, "browser_title" = \'test\'
|
||||
, "description" = \'\'
|
||||
, "is_default" = \'N\'
|
||||
, "open_rss" = \'Y\'
|
||||
, "header_text" = \'\'
|
||||
, "footer_text" = \'\'
|
||||
, "use_mobile" = \'\'
|
||||
WHERE "site_srl" = 0
|
||||
AND "module_srl" = 47374';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_module_updateMember(){
|
||||
$xml_file = _XE_PATH_ . "modules/member/queries/updateLastLogin.xml";
|
||||
$argsString = ' $args->member_srl = 4;
|
||||
$args->last_login = "20110607120549";';
|
||||
$expected = 'UPDATE "xe_member" SET "member_srl" = 4, "last_login" = \'20110607120549\' WHERE "member_srl" = 4';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_module_updatePoint(){
|
||||
$xml_file = _XE_PATH_ . "modules/point/queries/updatePoint.xml";
|
||||
$argsString = ' $args->member_srl = 4;
|
||||
$args->point = 105;';
|
||||
$expected = 'UPDATE "xe_point" SET "point" = 105 WHERE "member_srl" = 4';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_module_updateCounterUnique(){
|
||||
$xml_file = _XE_PATH_ . "modules/counter/queries/updateCounterUnique.xml";
|
||||
$argsString = '$args->regdate = 20110607;
|
||||
';
|
||||
$expected = 'UPDATE "xe_counter_status" SET "unique_visitor" = unique_visitor+1,
|
||||
"pageview" = pageview+1 WHERE "regdate" = 20110607 ';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
|
||||
function test_module_updateMenu(){
|
||||
$xml_file = _XE_PATH_ . "modules/menu/queries/updateMenu.xml";
|
||||
$argsString = '$args->menu_srl = 204;
|
||||
$args->title = "test_menu";
|
||||
';
|
||||
$expected = 'UPDATE "xe_menu" SET "title" = \'test_menu\' WHERE "menu_srl" = 204';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
}
|
||||
35
test-phpUnit/config.inc.php
Normal file
35
test-phpUnit/config.inc.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
// Report all errors except E_NOTICE
|
||||
// This is the default value set in php.ini
|
||||
error_reporting(E_ALL ^ E_NOTICE);
|
||||
define('_XE_PATH_', str_replace('test-phpUnit/config.inc.php', '', str_replace('\\', '/', __FILE__)));
|
||||
|
||||
require_once('QueryTester.class.php');
|
||||
require_once('Helper.class.php');
|
||||
if(!defined('__DEBUG__')) define('__DEBUG__', 4);
|
||||
|
||||
require_once(_XE_PATH_.'classes/object/Object.class.php');
|
||||
require_once(_XE_PATH_.'classes/handler/Handler.class.php');
|
||||
require_once(_XE_PATH_.'classes/context/Context.class.php');
|
||||
require_once(_XE_PATH_.'classes/file/FileHandler.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/DB.class.php');
|
||||
|
||||
require_once(_XE_PATH_.'classes/xml/XmlParser.class.php');
|
||||
require_once(_XE_PATH_.'classes/xml/XmlQueryParser.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/DBCubrid.class.php');
|
||||
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/Query.class.php');
|
||||
require_once(_XE_PATH_.'classes/xml/xmlquery/argument/Argument.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/expression/Expression.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/expression/InsertExpression.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/expression/UpdateExpression.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/table/Table.class.php');
|
||||
require_once(_XE_PATH_.'classes/xml/xmlquery/argument/ConditionArgument.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/condition/Condition.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/condition/ConditionGroup.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/expression/SelectExpression.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/expression/StarExpression.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/order/OrderByColumn.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/table/JoinTable.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/limit/Limit.class.php');
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue