Moved DB unit tests from .\test-phpUnit to .\tests folder.

git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@9788 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
ucorina 2011-11-01 19:04:38 +00:00
parent aada2366d1
commit 97470e4d40
99 changed files with 53 additions and 85 deletions

View file

@ -0,0 +1,49 @@
<?php
/**
* Base class for tests for CUBRID SQL syntax
*/
class CubridOnlineTest extends PHPUnit_Framework_TestCase {
protected $backupGlobals = FALSE;
protected $backupStaticAttributes = FALSE;
protected $preserveGlobalState = FALSE;
/**
* Prepare runtime context - tell DB class that current DB is CUBRID
*/
protected function setUp() {
$this->markTestSkipped();
$oContext = &Context::getInstance();
$db_info->master_db = array('db_type' => 'cubrid'
,'db_port' => '33000'
,'db_hostname' => '10.0.0.206'
,'db_userid' => 'dba'
,'db_password' => 'arniarules'
,'db_database' => 'xe15QA'
,'db_table_prefix' => 'xe_');
$db_info->slave_db = array(array('db_type' => 'cubrid'
,'db_port' => '33000'
,'db_hostname' => '10.0.0.206'
,'db_userid' => 'dba'
,'db_password' => 'arniarules'
,'db_database' => 'xe15QA'
,'db_table_prefix' => 'xe_'));
$oContext->setDbInfo($db_info);
// remove cache dir
FileHandler::removeDir( _XE_PATH_ . 'files/cache');
DB::getParser(true);
}
/**
* Free resources - reset static DB and QueryParser
*/
protected function tearDown() {
unset($GLOBALS['__DB__']);
}
}
?>

View file

@ -0,0 +1,31 @@
<?php
/**
* Base class for tests for CUBRID SQL syntax
*/
class CubridTest extends DBTest {
/**
* Prepare runtime context - tell DB class that current DB is CUBRID
*/
protected function setUp() {
$oContext = &Context::getInstance();
$db_info->master_db = array('db_type' => 'cubrid','db_table_prefix' => 'xe_');
$db_info->slave_db = array(array('db_type' => 'cubrid','db_table_prefix' => 'xe_'));
$oContext->setDbInfo($db_info);
$db = new MockDb();
$db->getParser(true);
}
/**
* Free resources - reset static DB and QueryParser
*/
protected function tearDown() {
unset($GLOBALS['__DB__']);
}
}
?>

View file

@ -0,0 +1,70 @@
<?php
class DBTest extends PHPUnit_Framework_TestCase {
function _testQuery($xml_file, $argsString, $expected, $methodName, $columnList = null){
echo PHP_EOL . ' ----------------------------------- ' .PHP_EOL;
echo $xml_file;
echo PHP_EOL . ' ----------------------------------- ' .PHP_EOL;
$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 = &DB::getInstance();
if($columnList) $output->setColumnList($columnList);
$querySql = $db->{$methodName}($output);
// Remove whitespaces, tabs and all
$querySql = Helper::cleanString($querySql);
$expected = Helper::cleanString($expected);
}
$this->assertEquals($expected, $querySql);
}
function _testPreparedQuery($xml_file, $argsString, $expected, $methodName, $expectedArgs = NULL){
echo PHP_EOL . ' ----------------------------------- ' .PHP_EOL;
echo $xml_file;
echo PHP_EOL . ' ----------------------------------- ' .PHP_EOL;
$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 = &DB::getInstance();
$querySql = $db->{$methodName}($output, false);
$queryArguments = $output->getArguments();
// Remove whitespaces, tabs and all
$querySql = Helper::cleanString($querySql);
$expected = Helper::cleanString($expected);
}
// Test
$this->assertEquals($expected, $querySql);
// Test query arguments
$argCount = count($expectedArgs);
for($i = 0; $i < $argCount; $i++){
$this->assertEquals($expectedArgs[$i], $queryArguments[$i]->getEscapedValue());
}
}
function _testCachedOutput($expected, $actual){
$expected = Helper::cleanString($expected);
$actual = Helper::cleanString($actual);
$this->assertEquals($expected, $actual);
}
}
?>

View file

@ -0,0 +1,109 @@
<?php
class ExpressionParserTest extends PHPUnit_Framework_TestCase {
/* Escape char for:
* CUBRID ""
* MySql ``
* SqlServer []
*/
var $dbLeftEscapeChar = '[';
var $dbRightEscapeChar = ']';
function _test($column_name, $alias, $expected){
$expressionParser = new DBParser($this->dbLeftEscapeChar,$this->dbRightEscapeChar);
$actual = $expressionParser->parseExpression($column_name);
if($alias) $actual .= " as $alias";
$this->assertEquals($expected, $actual);
}
function testStarExpressionIsNotEscaped(){
$this->_test("*", NULL, '*');
}
function testSimpleColumnNameGetsEscaped(){
$this->_test("member_srl", NULL
, $this->dbLeftEscapeChar.'member_srl'.$this->dbRightEscapeChar );
}
function testUnqualifiedAliasedColumnNameGetsEscaped(){
$this->_test("member_srl", "id"
, $this->dbLeftEscapeChar.'member_srl'.$this->dbRightEscapeChar.' as id');
}
function testQualifiedColumnNameGetsEscaped(){
$this->_test("xe_members.member_srl", NULL
, $this->dbLeftEscapeChar.'xe_members'.$this->dbRightEscapeChar.'.'.$this->dbLeftEscapeChar.'member_srl'.$this->dbRightEscapeChar);
}
function testQualifiedAliasedColumnNameGetsEscaped(){
$this->_test("xe_members.member_srl","id"
,$this->dbLeftEscapeChar.'xe_members'.$this->dbRightEscapeChar.'.'.$this->dbLeftEscapeChar.'member_srl'.$this->dbRightEscapeChar.' as id');
}
function testCountDoesntGetEscaped(){
$this->_test("count(*)", NULL, 'count(*)');
}
function testAliasedCountDoesntGetEscaped(){
$this->_test("count(*)", "count", 'count(*) as count');
}
function testUnqualifiedColumnExpressionWithOneParameterLessFunction(){
$this->_test("substring(regdate)", NULL
, 'substring('.$this->dbLeftEscapeChar.'regdate'.$this->dbRightEscapeChar.')');
}
function testAliasedUnqualifiedColumnExpressionWithOneParameterLessFunction(){
$this->_test("substring(regdate)", "regdate"
, 'substring('.$this->dbLeftEscapeChar.'regdate'.$this->dbRightEscapeChar.') as regdate');
}
function testQualifiedColumnExpressionWithOneParameterLessFunction(){
$this->_test("substring(xe_member.regdate)", NULL
, 'substring('.$this->dbLeftEscapeChar.'xe_member'.$this->dbRightEscapeChar.'.'.$this->dbLeftEscapeChar.'regdate'.$this->dbRightEscapeChar.')');
}
function testAliasedQualifiedColumnExpressionWithOneParameterLessFunction(){
$this->_test("substring(xe_member.regdate)", "regdate"
, 'substring('.$this->dbLeftEscapeChar.'xe_member'.$this->dbRightEscapeChar.'.'.$this->dbLeftEscapeChar.'regdate'.$this->dbRightEscapeChar.') as regdate');
}
function testUnqualifiedColumnExpressionWithTwoParameterLessFunctions(){
$this->_test("lpad(rpad(regdate))", NULL
, 'lpad(rpad('.$this->dbLeftEscapeChar.'regdate'.$this->dbRightEscapeChar.'))');
}
function testAliasedUnqualifiedColumnExpressionWithTwoParameterLessFunctions(){
$this->_test("lpad(rpad(regdate))", "regdate"
, 'lpad(rpad('.$this->dbLeftEscapeChar.'regdate'.$this->dbRightEscapeChar.')) as regdate');
}
function testQualifiedColumnExpressionWithTwoParameterLessFunctions(){
$this->_test("lpad(rpad(xe_member.regdate))", NULL
, 'lpad(rpad('.$this->dbLeftEscapeChar.'xe_member'.$this->dbRightEscapeChar.'.'.$this->dbLeftEscapeChar.'regdate'.$this->dbRightEscapeChar.'))');
}
function testAliasedQualifiedColumnExpressionWithTwoParameterLessFunctions(){
$this->_test("lpad(rpad(xe_member.regdate))", "regdate"
, 'lpad(rpad('.$this->dbLeftEscapeChar.'xe_member'.$this->dbRightEscapeChar.'.'.$this->dbLeftEscapeChar.'regdate'.$this->dbRightEscapeChar.')) as regdate');
}
function testColumnAddition(){
$this->_test("score1 + score2", "total"
, $this->dbLeftEscapeChar.'score1'.$this->dbRightEscapeChar.' + '.$this->dbLeftEscapeChar.'score2'.$this->dbRightEscapeChar.' as total');
}
function testMultipleParameterFunction(){
$this->_test("substring(regdate, 1, 8)", NULL
, 'substring('.$this->dbLeftEscapeChar.'regdate'.$this->dbRightEscapeChar.', 1, 8)');
$this->_test("substring(regdate, 1, 8)", "regdate"
, 'substring('.$this->dbLeftEscapeChar.'regdate'.$this->dbRightEscapeChar.', 1, 8) as regdate');
$this->_test("substring(xe_member.regdate, 1, 8)", NULL
, 'substring('.$this->dbLeftEscapeChar.'xe_member'.$this->dbRightEscapeChar.'.'.$this->dbLeftEscapeChar.'regdate'.$this->dbRightEscapeChar.', 1, 8)');
}
function testFunctionAddition(){
$this->_test("abs(score) + abs(totalscore)", NULL
, 'abs('.$this->dbLeftEscapeChar.'score'.$this->dbRightEscapeChar.') + abs('.$this->dbLeftEscapeChar.'totalscore'.$this->dbRightEscapeChar.')');
}
}

View file

@ -0,0 +1,81 @@
<?php
/**
* @brief Mock database base class
*
* Used to load mock classes instead of actual ones,
* so that connect methods can be skipped
*/
class MockDb extends DB {
function &getParser($force = false){
static $dbParser = null;
if(!$dbParser || $force) {
$oDB = &MockDb::getInstance();
$dbParser = $oDB->getParser();
DB::getParser(true);
}
return $dbParser;
}
function &getInstance(){
$db_type = Context::getDBType();
if(!isset($GLOBALS['__DB__'])) $GLOBALS['__DB__'] = array();
if(!isset($GLOBALS['__DB__'][$db_type])) {
switch($db_type){
case 'mssql' :
$GLOBALS['__DB__'][$db_type] = new MockDBMssql; break;
case 'mysql' :
$GLOBALS['__DB__'][$db_type] = new MockDBMysql; break;
case 'cubrid' :
$GLOBALS['__DB__'][$db_type] = new MockDBCubrid; break;
}
}
return $GLOBALS['__DB__'][$db_type];
}
}
/**
* @brief Mock up for MS SQL class
*
* Overrides default constructor in order to skip connect method
*/
class MockDBMssql extends DBMssql {
function MockDBMssql(){
$this->_setDBInfo();
}
}
/**
* @brief Mock up for CUBRID class
*
* Overrides default constructor in order to skip connect method
*/
class MockDBCubrid extends DBCubrid {
function MockDBCubrid(){
$this->_setDBInfo();
}
}
/**
* @brief Mock up for Mysql class
*
* Overri des default constructor in order to skip connect method.
*/
class MockDBMysql extends DBMysql {
function MockDBMysql(){
$this->_setDBInfo();
}
/**
* Overrides mysql_real_escape_string, that returns null when no connection is present
*/
function addQuotes($string){
return $string;
}
}
?>

View file

@ -0,0 +1,49 @@
<?php
/**
* Base class for tests for MSSQL SQL syntax
*/
class MssqlOnlineTest extends PHPUnit_Framework_TestCase {
protected $backupGlobals = FALSE;
protected $backupStaticAttributes = FALSE;
protected $preserveGlobalState = FALSE;
/**
* Prepare runtime context - tell DB class that current DB is MSSQL
*/
protected function setUp() {
$this->markTestSkipped();
$oContext = &Context::getInstance();
$db_info->master_db = array('db_type' => 'mssql'
,'db_port' => '3306'
,'db_hostname' => 'PHENOMII\SQL2008EXPRESS'
,'db_userid' => 'dba'
,'db_password' => 'arniarules'
,'db_database' => 'xe-15-db'
,'db_table_prefix' => 'xe_');
$db_info->slave_db = array(array('db_type' => 'mssql'
,'db_port' => '3306'
,'db_hostname' => 'PHENOMII\SQL2008EXPRESS'
,'db_userid' => 'dba'
,'db_password' => 'arniarules'
,'db_database' => 'xe-15-db'
,'db_table_prefix' => 'xe_'));
$oContext->setDbInfo($db_info);
// remove cache dir
FileHandler::removeDir( _XE_PATH_ . 'files/cache');
DB::getParser(true);
}
/**
* Free resources - reset static DB and QueryParser
*/
protected function tearDown() {
unset($GLOBALS['__DB__']);
}
}
?>

View file

@ -0,0 +1,26 @@
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
class MssqlTest extends DBTest {
protected function setUp() {
$oContext = &Context::getInstance();
$db_info->master_db = array('db_type' => 'mssql','db_table_prefix' => 'xe_');
$db_info->slave_db = array(array('db_type' => 'mssql','db_table_prefix' => 'xe_'));
$oContext->setDbInfo($db_info);
$db = new MockDb();
$db->getParser(true);
}
protected function tearDown() {
unset($GLOBALS['__DB__']);
}
}
?>

View file

@ -0,0 +1,31 @@
<?php
/**
* Base class for tests for Mysql SQL syntax
*/
class MysqlTest extends DBTest {
/**
* Prepare runtime context - tell DB class that current DB is CUBRID
*/
protected function setUp() {
$oContext = &Context::getInstance();
$db_info->master_db = array('db_type' => 'mysql','db_table_prefix' => 'xe_');
$db_info->slave_db = array(array('db_type' => 'mysql','db_table_prefix' => 'xe_'));
$oContext->setDbInfo($db_info);
$db = new MockDb();
$db->getParser(true);
}
/**
* Free resources - reset static DB and QueryParser
*/
protected function tearDown() {
unset($GLOBALS['__DB__']);
}
}
?>

View file

@ -0,0 +1,32 @@
<?php
/**
* Base class for tests for Sqlite SQL syntax
*
* See syntax reference:
* http://www.sqlite.org/lang.html
*/
class SqliteTest extends DBTest {
/**
* Prepare runtime context - tell DB class that current DB is CUBRID
*/
protected function setUp() {
$oContext = &Context::getInstance();
$db_info->master_db = array('db_type' => 'sqlite3_pdo','db_table_prefix' => 'xe_');
$db_info->slave_db = array(array('db_type' => 'sqlite3_pdo','db_table_prefix' => 'xe_'));
$oContext->setDbInfo($db_info);
DB::getParser(true);
}
/**
* Free resources - reset static DB and QueryParser
*/
protected function tearDown() {
unset($GLOBALS['__DB__']);
}
}
?>

View file

@ -0,0 +1,20 @@
<?php
class CubridDeleteTest extends CubridTest {
function _test($xml_file, $argsString, $expected){
$this->_testQuery($xml_file, $argsString, $expected, 'getDeleteSql');
}
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 "action_forward" from "xe_action_forward" as "action_forward"
where "module" = \'page\'
and "type" = \'page\'
and "act" = \'tata\'';
$this->_test($xml_file, $argsString, $expected);
}
}

View file

@ -0,0 +1,85 @@
<?php
class CubridIndexHintTest extends CubridTest {
var $xmlPath = 'data/';
function CubridIndexHintTest(){
$this->xmlPath = str_replace('CubridIndexHintTest.php', '', str_replace('\\', '/', __FILE__)) . $this->xmlPath;
}
function _test($xml_file, $argsString, $expected){
var_dump($xml_file);
$this->_testQuery($xml_file, $argsString, $expected, 'getSelectSql');
}
function testOneUseIndexHintAndOneTable(){
$xml_file = $this->xmlPath . "one_index_hint_one_table.xml";
$argsString = '';
$expected = 'select * from "xe_member" as "member" using index "member"."xe_idx_member_list_order"';
$this->_test($xml_file, $argsString, $expected);
}
function testTwoUseIndexHintsAndOneTable(){
$xml_file = $this->xmlPath . "two_index_hints_one_table.xml";
$argsString = '';
$expected = 'select * from "xe_member" as "member" using index "member"."xe_idx_member_list_order", "member"."xe_idx_member_srl"';
$this->_test($xml_file, $argsString, $expected);
}
function testThreeUseIndexHintsAndTwoTables(){
$xml_file = $this->xmlPath . "three_index_hints_two_tables.xml";
$argsString = '';
$expected = 'select * from "xe_member" as "member", "xe_document" as "document"
using index "member"."xe_idx_member_list_order", "member"."xe_idx_member_srl", "document"."xe_idx_document_srl"';
$this->_test($xml_file, $argsString, $expected);
}
function testThreeUseIndexHintsAndTwoTablesCombined(){
$xml_file = $this->xmlPath . "three_index_hints_two_tables_combined.xml";
$argsString = '';
$expected = 'select * from "xe_member" as "member", "xe_document" as "document"
using index "member"."xe_idx_member_list_order", "member"."xe_idx_member_srl"(+), "document"."xe_idx_document_srl"';
$this->_test($xml_file, $argsString, $expected);
}
function testIgnoreIndexHintIsSkipped(){
$xml_file = $this->xmlPath . "ignore_index_hint.xml";
$argsString = '';
$expected = 'select * from "xe_member" as "member"';
$this->_test($xml_file, $argsString, $expected);
}
function testMysqlIndexHintIsSkipped(){
$xml_file = $this->xmlPath . "mysql_index_hint.xml";
$argsString = '';
$expected = 'select * from "xe_member" as "member"';
$this->_test($xml_file, $argsString, $expected);
}
/**
* If CUBRID database is used, indexes are created with prefix.
*
* e.g.: xe_indx_list_order
*/
function testPrefixIsAddedToIndexName(){
$xml_file = $this->xmlPath . "one_index_hint_one_table.xml";
$argsString = '';
$expected = 'select * from "xe_member" as "member" using index "member"."xe_idx_member_list_order"';
$this->_test($xml_file, $argsString, $expected);
}
/**
* Tests that index is added if "for" attribute is "ALL"
*
* example: <index_hint for="ALL"> ... </index_hint>
*/
function testIndexHintForAll(){
$xml_file = $this->xmlPath . "index_hint_for_all.xml";
$argsString = '';
$expected = 'select * from "xe_member" as "member" using index "member"."xe_idx_member_list_order"';
$this->_test($xml_file, $argsString, $expected);
}
}
?>

View file

@ -0,0 +1,85 @@
<?php
class CubridInsertOnlineTest extends CubridOnlineTest {
/**
* Note: this test can fail when comaparing regdate from the $args with
* regdate from the expected string - a few seconds difference
*/
function test_module_insertModule_escapeContent(){
$xml_file = _XE_PATH_ . "modules/module/queries/insertModule.xml";
$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;
$args->content = "hello \' moto";
$output = executeQuery('module.insertModule', $args);
$this->assertTrue(!$output->error, $output->message);
}
function test_document_insertDocument_defaultVarcharValue(){
$args->module_srl = 102;
$args->content = '<p>yuhuuuuu</p>';
$args->document_srl = 9200;
$args->is_secret = 'N';
$args->allow_comment = 'N';
$args->lock_comment = 'N';
$args->allow_trackback = 'N';
$args->notify_message = 'N';
$args->ipaddress = '127.0.0.1';
$args->extra_vars = 'N;';
$args->readed_count = 0;
$args->list_order = -9201;
$args->update_order = -9201;
$args->member_srl = 4;
$args->user_id = 'admin';
$args->user_name = 'admin';
$args->nick_name = 'admin';
$args->email_address = 'admin@admin.admin';
$args->homepage = '';
$args->title = 'yuhuu';
$args->lang_code;
$output = executeQuery('document.insertDocument', $args);
$this->assertNotEquals(-225, $output->error);
$this->assertNotEquals('Missing value for attribute "homepage" with the NOT NULL constraint.', $output->message);
}
function test_communication_addFriendGroup(){
$args->member_srl = 202;
$args->title = "Grup";
$output = executeQuery("communication.addFriendGroup", $args);
$this->assertEquals(0, $output->error, $output->message);
}
function test_communication_addFriendGroup_NullId(){
$args->member_srl = 202;
$args->title = "Grup";
$args->friend_group_srl = trim(null);
$output = executeQuery("communication.addFriendGroup", $args);
$this->assertEquals(0, $output->error, $output->message);
}
protected function tearDown() {
$db = &DB::getInstance();
$db->_query("DELETE FROM xe_modules WHERE module_srl = 47374");
$db->_query("DELETE FROM xe_documents WHERE document_srl = 9200");
$db->_query("DELETE FROM xe_member_friend_group WHERE member_srl = 202");
$db->close();
parent::tearDown();
}
}

View file

@ -0,0 +1,127 @@
<?php
class CubridInsertTest extends CubridTest {
function _test($xml_file, $argsString, $expected){
$this->_testQuery($xml_file, $argsString, $expected, 'getInsertSql');
}
/**
* Note: this test can fail when comaparing regdate from the $args with
* regdate from the expected string - a few seconds difference
*/
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
('.date("YmdHis").'
, 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->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", "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);
}
}

View file

@ -0,0 +1,76 @@
<?php
class CubridSelectOnlineTest extends CubridOnlineTest {
function test_get_module_by_mid(){
$args->mid = 'test_4l8ci4vv0n';
$args->site_srl = 0;
$output = executeQuery('module.getMidInfo', $args);
$this->assertNotNull($output);
$this->assertNotNull($output->data, $output->message . PHP_EOL . $output->variables["_query"]);
$this->assertEquals($output->data->module_srl, 111);
}
/**
* Tests that when a column list is given, the query only selects those columns from the database
* insetad of retrieving all table columns (as specified in the xml query file)
*/
function test_get_module_by_mid_columnList(){
$args->mid = 'test_4l8ci4vv0n';
$args->site_srl = 0;
$output = executeQuery('module.getMidInfo', $args, array('module_srl'));
$this->assertNotNull($output);
$this->assertNotNull($output->data, $output->message . PHP_EOL . $output->variables["_query"]);
$this->assertEquals($output->data->module_srl, 111);
$this->assertEquals($output->data->module, null);
}
function test_module_getInfo(){
$args->site_srl = 0;
$output = executeQuery('module.getSiteInfo', $args);
$this->assertTrue(is_a($output, 'Object'));
$this->assertEquals(0, $output->error, $output->message . PHP_EOL . $output->variables["_query"]);
}
function test_document_getDocumentList_pagination(){
$args->sort_index = 'list_order';
$args->order_type = 'asc';
$args->page = 1;
$args->list_count = 30;
$args->page_count = 10;
$args->s_member_srl = 4;
$output = executeQuery('document.getDocumentList', $args);
$this->assertEquals(0, $output->error, $output->message . PHP_EOL . $output->variables["_query"]);
}
function test_syndication_getDocumentList(){
$args->module_srl = NULL;
$args->exclude_module_srl = NULL;
$args->category_srl = NULL;
$args->sort_index = 'list_order';
$args->order_type = 'asc';
$args->page = 5;
$args->list_count = 30;
$args->page_count = 10;
$args->start_date = NULL;
$args->end_date = NULL;
$args->member_srl = NULL;
$output = executeQuery('document.getDocumentList', $args);
$this->assertTrue(is_int($output->page), $output->message . PHP_EOL . $output->variables["_query"]);
}
function test_member_getMemberList(){
$args->is_admin = '';
$args->is_denied = '';
$args->sort_index = "list_order";
$args->sort_order = 'asc';
$args->list_count = 40;
$args->page_count = 10;
$output = executeQuery('member.getMemberList', $args);
$this->assertEquals(0, $output->error, $output->message . PHP_EOL . $output->variables["_query"]);
}
}
?>

View file

@ -0,0 +1,396 @@
<?php
class CubridSelectTest extends CubridTest {
function _test($xml_file, $argsString, $expected, $columnList = null){
$this->_testQuery($xml_file, $argsString, $expected, 'getSelectSql', $columnList);
}
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 testRequiredParameter(){
$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 = '$args->site_srl = 0;';
$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 = _TEST_PATH_ . "db/xml_query/cubrid/data/opage.getOpageList.xml";
$argsString = '$args->s_title = "yuhuu";
$args->module = \'opage\';';
$expected = 'SELECT *
FROM "xe_modules" as "modules"
WHERE "module" = \'opage\' and ("title" like \'%yuhuu%\')
ORDER BY "module_srl" desc
LIMIT 0, 20';
$this->_test($xml_file, $argsString, $expected);
}
function test_syndication_getGrantedModules(){
$xml_file = _TEST_PATH_ . "db/xml_query/cubrid/data/syndication.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" >= 1
or "group_srl" = -1
or "group_srl" = -2)
group by "module_srl"';
$this->_test($xml_file, $argsString, $expected);
}
function test_document_getDocumentList(){
$xml_file = _XE_PATH_ . "modules/document/queries/getDocumentList.xml";
$argsString = '$args->sort_index = \'list_order\';
$args->order_type = \'asc\';
$args->page = 1;
$args->list_count = 30;
$args->page_count = 10;
$args->s_member_srl = 4;';
$expected = 'select *
from "xe_documents" as "documents"
where ("member_srl" = 4)
and "list_order" <= 2100000000
order by "list_order" asc
limit 0, 30';
$this->_test($xml_file, $argsString, $expected);
}
/**
* Test column list
*/
function test_session_getSession(){
$xml_file = _XE_PATH_ . "modules/session/queries/getSession.xml";
$argsString = '$args->session_key = \'session_key\';';
$columnList = array('session_key', 'cur_mid', 'val');
$expected = 'select "session_key", "cur_mid", "val"
from "xe_session" as "session"
where "session_key" = \'session_key\'';
$this->_test($xml_file, $argsString, $expected, $columnList);
}
function test_module_getModuleInfoByDocument(){
$xml_file = _XE_PATH_ . "modules/module/queries/getModuleInfoByDocument.xml";
$argsString = '$args->document_srl = 10;';
$expected = 'SELECT "modules".*
FROM "xe_modules" as "modules"
, "xe_documents" as "documents"
WHERE "documents"."document_srl" = 10
and "modules"."module_srl" = "documents"."module_srl"';
$this->_test($xml_file, $argsString, $expected);
}
function test_member_getMemberList(){
$xml_file = _XE_PATH_ . "modules/member/queries/getMemberList.xml";
$argsString = '$args->is_admin = \'\';
$args->is_denied = \'\';
$args->sort_index = "list_order";
$args->sort_order = \'asc\';
$args->list_count = 40;
$args->page_count = 10;';
$expected = 'select *
from "xe_member" as "member"
where "list_order" <= 2100000000
order by "list_order" asc
limit 0, 40';
$this->_test($xml_file, $argsString, $expected);
}
/**
* Tests "not in" query condition
* Query argument is a single value - not in (12)
*/
function test_module_getModules_Notin_Single_Value(){
$xml_file = _TEST_PATH_ . "db/xml_query/cubrid/data/syndication.getModules.xml";
$argsString = '$args->except_module_srls = 12;';
$expected = 'select "modules"."site_srl" as "site_srl"
, "modules"."module_srl" as "module_srl"
, "sites"."domain" as "domain"
, "modules"."mid" as "mid"
, "modules"."module" as "module"
, "modules"."browser_title" as "browser_title"
, "modules"."description" as "description"
from "xe_sites" as "sites"
, "xe_modules" as "modules"
left join "xe_syndication_except_modules" as "except_modules"
on "modules"."module_srl" = "except_modules"."module_srl"
where "modules"."module_srl" not in (12)
and "sites"."site_srl" = "modules"."site_srl"
and "except_modules"."module_srl" is null';
$this->_test($xml_file, $argsString, $expected);
}
function test_module_getModules_Notin_Multiple_Value_String(){
$xml_file = _TEST_PATH_ . "db/xml_query/cubrid/data/syndication.getModules.xml";
$argsString = '$args->except_module_srls = "12, 13, 14";';
$expected = 'select "modules"."site_srl" as "site_srl"
, "modules"."module_srl" as "module_srl"
, "sites"."domain" as "domain"
, "modules"."mid" as "mid"
, "modules"."module" as "module"
, "modules"."browser_title" as "browser_title"
, "modules"."description" as "description"
from "xe_sites" as "sites"
, "xe_modules" as "modules"
left join "xe_syndication_except_modules" as "except_modules"
on "modules"."module_srl" = "except_modules"."module_srl"
where "modules"."module_srl" not in (12,13,14)
and "sites"."site_srl" = "modules"."site_srl"
and "except_modules"."module_srl" is null';
$this->_test($xml_file, $argsString, $expected);
}
function test_module_getModules_Notin_Multiple_Value_Array(){
$xml_file = _TEST_PATH_ . "db/xml_query/cubrid/data/syndication.getModules.xml";
$argsString = '$args->except_module_srls = array(12, 13, 14);';
$expected = 'select "modules"."site_srl" as "site_srl"
, "modules"."module_srl" as "module_srl"
, "sites"."domain" as "domain"
, "modules"."mid" as "mid"
, "modules"."module" as "module"
, "modules"."browser_title" as "browser_title"
, "modules"."description" as "description"
from "xe_sites" as "sites"
, "xe_modules" as "modules"
left join "xe_syndication_except_modules" as "except_modules"
on "modules"."module_srl" = "except_modules"."module_srl"
where "modules"."module_srl" not in (12,13,14)
and "sites"."site_srl" = "modules"."site_srl"
and "except_modules"."module_srl" is null';
$this->_test($xml_file, $argsString, $expected);
}
function test_module_getModules_In_Single_Value(){
$xml_file = _TEST_PATH_ . "db/xml_query/cubrid/data/syndication.getModules.xml";
$argsString = '$args->module_srls = 12;';
$expected = 'select "modules"."site_srl" as "site_srl"
, "modules"."module_srl" as "module_srl"
, "sites"."domain" as "domain"
, "modules"."mid" as "mid"
, "modules"."module" as "module"
, "modules"."browser_title" as "browser_title"
, "modules"."description" as "description"
from "xe_sites" as "sites"
, "xe_modules" as "modules"
left join "xe_syndication_except_modules" as "except_modules"
on "modules"."module_srl" = "except_modules"."module_srl"
where "modules"."module_srl" in (12)
and "sites"."site_srl" = "modules"."site_srl"
and "except_modules"."module_srl" is null';
$this->_test($xml_file, $argsString, $expected);
}
function test_module_getModules_In_Multiple_Value_String(){
$xml_file = _TEST_PATH_ . "db/xml_query/cubrid/data/syndication.getModules.xml";
$argsString = '$args->module_srls = "12, 13, 14";';
$expected = 'select "modules"."site_srl" as "site_srl"
, "modules"."module_srl" as "module_srl"
, "sites"."domain" as "domain"
, "modules"."mid" as "mid"
, "modules"."module" as "module"
, "modules"."browser_title" as "browser_title"
, "modules"."description" as "description"
from "xe_sites" as "sites"
, "xe_modules" as "modules"
left join "xe_syndication_except_modules" as "except_modules"
on "modules"."module_srl" = "except_modules"."module_srl"
where "modules"."module_srl" in (12,13,14)
and "sites"."site_srl" = "modules"."site_srl"
and "except_modules"."module_srl" is null';
$this->_test($xml_file, $argsString, $expected);
}
function test_module_getModules_In_Multiple_Value_Array(){
$xml_file = _TEST_PATH_ . "db/xml_query/cubrid/data/syndication.getModules.xml";
$argsString = '$args->module_srls = array(12, 13, 14);';
$expected = 'select "modules"."site_srl" as "site_srl"
, "modules"."module_srl" as "module_srl"
, "sites"."domain" as "domain"
, "modules"."mid" as "mid"
, "modules"."module" as "module"
, "modules"."browser_title" as "browser_title"
, "modules"."description" as "description"
from "xe_sites" as "sites"
, "xe_modules" as "modules"
left join "xe_syndication_except_modules" as "except_modules"
on "modules"."module_srl" = "except_modules"."module_srl"
where "modules"."module_srl" in (12,13,14)
and "sites"."site_srl" = "modules"."site_srl"
and "except_modules"."module_srl" is null';
$this->_test($xml_file, $argsString, $expected);
}
function test_module_getModuleSrlByMid_In_Multiple_Value_Array_Strings(){
$xml_file = _XE_PATH_ . "modules/module/queries/getModuleSrlByMid.xml";
$argsString = '$args->mid = "\'mid1\', \'mid2\'";';
$expected = 'select "module_srl" from "xe_modules" as "modules" where "mid" in (\'mid1\',\'mid2\')';
$this->_test($xml_file, $argsString, $expected);
}
function test_file_getFileList_In_Empty_Array_Value(){
$xml_file = _XE_PATH_ . "modules/file/queries/getFileList.xml";
$argsString = '$args->exclude_module_srl = 12; $args->s_module_srl = array(); ';
$expected = 'select "files".*
from "xe_files" as "files"
left join "xe_member" as "member" on "files"."member_srl" = "member"."member_srl"
where "files"."module_srl" not in (12)
order by "files"."file_srl" desc
limit 0, 20';
$this->_test($xml_file, $argsString, $expected);
}
function test_file_getFileList_Not_In_Empty_String_Value(){
$xml_file = _XE_PATH_ . "modules/file/queries/getFileList.xml";
$argsString = '$args->exclude_module_srl = ""; $args->s_module_srl = array(12); ';
$expected = 'select "files".*
from "xe_files" as "files"
left join "xe_member" as "member" on "files"."member_srl" = "member"."member_srl"
where "files"."module_srl" in (12)
order by "files"."file_srl" desc
limit 0, 20';
$this->_test($xml_file, $argsString, $expected);
}
function test_document_getDeclaredList_In_Query(){
$xml_file = _XE_PATH_ . "modules/document/queries/getDeclaredList.xml";
$argsString = "\$args->list_count = 30;
\$args->page_count = 10;
\$args->sort_index = 'document_declared.declared_count';
\$args->order_type = 'desc';";
$expected = 'select * from "xe_documents" as "documents"
, "xe_document_declared" as "document_declared"
where "documents"."document_srl"
in ("document_declared"."document_srl")
order by "document_declared"."declared_count" desc
limit 0, 30';
$this->_test($xml_file, $argsString, $expected);
}
function test_getExpiredSession_curdate(){
$xml_file = _XE_PATH_ . "modules/session/queries/getExpiredSessions.xml";
$argsString = '';
$expected = 'select "session_key"
from "xe_session" as "session"
where "expired" <= \'' . date("YmdHis") . '\'';
$this->_test($xml_file, $argsString, $expected);
}
}

View file

@ -0,0 +1,191 @@
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
class CubridSubqueryTest extends CubridTest {
var $xmlPath = 'data/';
function CubridSubqueryTest(){
$this->xmlPath = str_replace('CubridSubqueryTest.php', '', str_replace('\\', '/', __FILE__)) . $this->xmlPath;
}
function _test($xml_file, $argsString, $expected){
$this->_testQuery($xml_file, $argsString, $expected, 'getSelectSql');
}
function testSelectUncorrelated1(){
$xml_file = $this->xmlPath . "select_uncorrelated1.xml";
$argsString = '$args->user_id = 4;
';
$expected = 'select "column_a" as "value_a"
, (select max("column_b") as "count"
from "xe_table_b" as "table_b"
) as "value_b"
from "xe_table_a" as "table_a"
where "column_a" = 4';
$this->_test($xml_file, $argsString, $expected);
}
function testSelectUncorrelated2(){
$xml_file = $this->xmlPath . "select_uncorrelated2.xml";
$argsString = '$args->user_id = 4;
$args->user_name = 7;
';
$expected = 'SELECT "column_a" as "value_a"
, "column_b" as "value_b"
, "column_c" as "value_c"
, (SELECT max("column_b") as "count"
FROM "xe_table_b" as "table_b"
WHERE "column_ab" = 7) as "value_b"
FROM "xe_table_a" as "table_a"
WHERE "column_a" = 4';
$this->_test($xml_file, $argsString, $expected);
}
function testFromUncorrelated1(){
$xml_file = $this->xmlPath . "from_uncorrelated1.xml";
$argsString = '$args->user_id = 4;
$args->user_name = 7;
';
$expected = 'select max("documentcountbymember"."count") as "maxcount"
from (
select "member_srl" as "member_srl"
, count(*) as "count"
from "xe_documents" as "documents"
group by "member_srl"
) as "documentcountbymember"';
$this->_test($xml_file, $argsString, $expected);
}
// function testFromUncorrelated2(){
// $xml_file = $this->xmlPath . "from_uncorrelated1.xml";
// $argsString = '$args->user_id = 4;
// $args->user_name = 7;
// ';
// $expected = 'select max("documentcountbymember"."count") as "maxcount"
// from (
// select "member_srl" as "member_srl"
// , count(*) as "count"
// from "xe_documents" as "documents"
// group by "member_srl"
// ) as "documentcountbymember"';
// $this->_test($xml_file, $argsString, $expected);
// }
function testFromUncorrelated2(){
$xml_file = $this->xmlPath . "from_uncorrelated2.xml";
$argsString = '$args->member_srl = 4;
$args->module_srl = 7;
';
$expected = 'select max("documentcountbymember"."count") as "maxcount"
from (
select "member_srl" as "member_srl"
, count(*) as "count"
from "xe_documents" as "documents"
where "module_srl" = 7
group by "member_srl"
) as "documentcountbymember"
where "member_srl" = 4
';
$this->_test($xml_file, $argsString, $expected);
}
function testSelectCorrelated1(){
$xml_file = $this->xmlPath . "select_correlated1.xml";
$argsString = '$args->user_id = 7;';
$expected = 'select *,
(select count(*) as "count"
from "xe_documents" as "documents"
where "documents"."user_id" = "member"."user_id"
) as "totaldocumentcount"
from "xe_member" as "member"
where "user_id" = \'7\'';
$this->_test($xml_file, $argsString, $expected);
}
function testSelectCorrelated2(){
$xml_file = $this->xmlPath . "select_correlated2.xml";
$argsString = '$args->user_id = 7;
$args->module_srl = 17;
';
$expected = 'select *,
(select count(*) as "count"
from "xe_documents" as "documents"
where "documents"."user_id" = "member"."user_id"
and "module_srl" = 17
) as "totaldocumentcount"
from "xe_member" as "member"
where "user_id" = \'7\'';
$this->_test($xml_file, $argsString, $expected);
}
function testWhereCorrelated1(){
$xml_file = $this->xmlPath . "where_correlated1.xml";
$argsString = '';
$expected = 'select *
from "xe_member" as "member"
where "regdate" = (
select max("regdate") as "maxregdate"
from "xe_documents" as "documents"
where "documents"."user_id" = "member"."user_id"
)';
$this->_test($xml_file, $argsString, $expected);
}
function testWhereCorrelated2(){
$xml_file = $this->xmlPath . "where_correlated2.xml";
$argsString = '$args->module_srl = 12; $args->member_srl = 19;';
$expected = 'select *
from "xe_member" as "member"
where "member_srl" = 19
and "regdate" = (
select max("regdate") as "maxregdate"
from "xe_documents" as "documents"
where "documents"."user_id" = "member"."user_id"
and "module_srl" = 12
)
';
$this->_test($xml_file, $argsString, $expected);
}
function testFromCorrelated1(){
$xml_file = $this->xmlPath . "from_correlated1.xml";
$argsString = '';
$expected = 'select "m"."member_srl"
, "m"."nickname"
, "m"."regdate"
, "a"."count"
from (
select "member_srl" as "member_srl"
, count(*) as "count"
from "xe_documents" as "documents"
group by "member_srl"
) as "a"
left join "xe_member" as "m" on "m"."member" = "a"."member_srl"';
$this->_test($xml_file, $argsString, $expected);
}
function testFromCorrelated2(){
$xml_file = $this->xmlPath . "from_correlated2.xml";
$argsString = '$args->module_srl = 12; $args->count = 20;';
$expected = 'select "m"."member_srl"
, "m"."nickname"
, "m"."regdate"
, "a"."count"
from (
select "member_srl" as "member_srl"
, count(*) as "count"
from "xe_documents" as "documents"
where "module_srl" = 12
group by "member_srl"
) as "a"
left join "xe_member" as "m" on "m"."member" = "a"."member_srl"
where "a"."count" >= 20
';
$this->_test($xml_file, $argsString, $expected);
}
}
?>

View file

@ -0,0 +1,97 @@
<?php
class CubridUpdateTest extends CubridTest {
function _test($xml_file, $argsString, $expected){
$this->_testQuery($xml_file, $argsString, $expected, 'getUpdateSql');
}
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" as "modules"
set "module" = \'page\'
, "module_category_srl" = 0
, "layout_srl" = 0
, "mid" = \'test\'
, "browser_title" = \'test\'
, "description" = \'\'
, "is_default" = \'n\'
, "open_rss" = \'y\'
, "header_text" = \'\'
, "footer_text" = \'\'
, "mlayout_srl" = 0
, "use_mobile" = \'n\'
where "site_srl" = 0 and "module_srl" = 47374';
// $expected = 'UPDATE "xe_modules" as "modules"
// SET "module" = \'page\'
// , "mid" = \'test\'
// , "browser_title" = \'test\'
// , "description" = \'\'
// , "is_default" = \'N\'
// , "open_rss" = \'Y\'
// , "header_text" = \'\'
// , "footer_text" = \'\'
// , "use_mobile" = \'n\'
// WHERE "site_srl" = 0
// AND "module_srl" = 47374';
$this->_test($xml_file, $argsString, $expected);
}
function test_member_updateLastLogin(){
$xml_file = _XE_PATH_ . "modules/member/queries/updateLastLogin.xml";
$argsString = ' $args->member_srl = 4;
$args->last_login = "20110607120549";';
$expected = 'UPDATE "xe_member" as "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" as "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" as "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" as "menu" SET "title" = \'test_menu\' WHERE "menu_srl" = 204';
$this->_test($xml_file, $argsString, $expected);
}
function test_menu_updateMenuItemNode(){
$xml_file = _XE_PATH_ . "modules/menu/queries/updateMenuItemNode.xml";
$argsString = '$args->parent_srl = 0;
$args->menu_srl = 237423;
$args->listorder = -8;
$args->menu_item_srl = 237431;';
$expected = 'UPDATE "xe_menu_item" as "menu_item" SET "parent_srl" = 0, "listorder" = -8 WHERE "menu_item_srl" = 237431';
$this->_test($xml_file, $argsString, $expected);
}
// $queryTester->test_admin_deleteActionForward();
// $queryTester->test_module_insertModule();
}

View file

@ -0,0 +1,27 @@
<query id="getMemberInfo" action="select">
<tables>
<table query="true" alias="a">
<tables>
<table name="documents" alias="documents" />
</tables>
<columns>
<column name="member_srl" alias="member_srl" />
<column name="count(*)" alias="count" />
</columns>
<groups>
<group column="member_srl" />
</groups>
</table>
<table name="member" alias="m" type="left join">
<conditions>
<condition operation="equal" column="m.member" default="a.member_srl" />
</conditions>
</table>
</tables>
<columns>
<column name="m.member_srl" />
<column name="m.nickname" />
<column name="m.regdate" />
<column name="a.count" />
</columns>
</query>

View file

@ -0,0 +1,33 @@
<query id="getMemberInfo" action="select">
<tables>
<table query="true" alias="a">
<tables>
<table name="documents" alias="documents" />
</tables>
<columns>
<column name="member_srl" alias="member_srl" />
<column name="count(*)" alias="count" />
</columns>
<conditions>
<condition operation="equal" column="module_srl" var="module_srl" notnull="notnull" />
</conditions>
<groups>
<group column="member_srl" />
</groups>
</table>
<table name="member" alias="m" type="left join">
<conditions>
<condition operation="equal" column="m.member" default="a.member_srl" />
</conditions>
</table>
</tables>
<columns>
<column name="m.member_srl" />
<column name="m.nickname" />
<column name="m.regdate" />
<column name="a.count" />
</columns>
<conditions>
<condition operation="more" column="a.count" var="count" notnull="notnull" />
</conditions>
</query>

View file

@ -0,0 +1,19 @@
<query id="getMemberInfo" action="select">
<tables>
<table query="true" alias="documentCountByMember">
<tables>
<table name="documents" alias="documents" />
</tables>
<columns>
<column name="member_srl" alias="member_srl" />
<column name="count(*)" alias="count" />
</columns>
<groups>
<group column="member_srl" />
</groups>
</table>
</tables>
<columns>
<column name="MAX(documentCountByMember.count)" alias="maxCount" />
</columns>
</query>

View file

@ -0,0 +1,25 @@
<query id="getMemberInfo" action="select">
<tables>
<table query="true" alias="documentCountByMember">
<tables>
<table name="documents" alias="documents" />
</tables>
<columns>
<column name="member_srl" alias="member_srl" />
<column name="count(*)" alias="count" />
</columns>
<conditions>
<condition operation="equal" column="module_srl" var="module_srl" notnull="notnull" />
</conditions>
<groups>
<group column="member_srl" />
</groups>
</table>
</tables>
<columns>
<column name="MAX(documentCountByMember.count)" alias="maxCount" />
</columns>
<conditions>
<condition operation="equal" column="member_srl" var="member_srl" notnull="notnull" />
</conditions>
</query>

View file

@ -0,0 +1,11 @@
<query id="index_hint" action="select">
<tables>
<table name="member" alias="member" />
</tables>
<columns>
<column name="*" />
</columns>
<index_hint for="CUBRID">
<index table="member" name="idx_member_list_order" type="IGNORE" />
</index_hint>
</query>

View file

@ -0,0 +1,11 @@
<query id="index_hint" action="select">
<tables>
<table name="member" alias="member" />
</tables>
<columns>
<column name="*" />
</columns>
<index_hint for="ALL">
<index table="member" name="idx_member_list_order" type="USE" />
</index_hint>
</query>

View file

@ -0,0 +1,11 @@
<query id="index_hint" action="select">
<tables>
<table name="member" alias="member" />
</tables>
<columns>
<column name="*" />
</columns>
<index_hint for="MYSQL">
<index table="member" name="idx_member_list_order" type="IGNORE" />
</index_hint>
</query>

View file

@ -0,0 +1,11 @@
<query id="index_hint" action="select">
<tables>
<table name="member" alias="member" />
</tables>
<columns>
<column name="*" />
</columns>
<index_hint for="CUBRID">
<index table="member" name="idx_member_list_order" type="USE" />
</index_hint>
</query>

View file

@ -0,0 +1,24 @@
<query id="getOpageList" action="select">
<tables>
<table name="modules" />
</tables>
<columns>
<column name="*" />
</columns>
<conditions>
<condition operation="equal" column="module" default="opage" />
<group pipe="and">
<condition operation="like" column="mid" var="s_mid" pipe="or" />
<condition operation="like" column="title" var="s_title" pipe="or" />
<condition operation="like" column="comment" var="s_comment" pipe="or" />
<condition operation="equal" column="module" var="s_module" pipe="or" />
<condition operation="equal" column="module_category_srl" var="s_module_category_srl" pipe="or" />
</group>
</conditions>
<navigation>
<index var="sort_index" default="module_srl" order="desc" />
<list_count var="list_count" default="20" />
<page_count var="page_count" default="10" />
<page var="page" default="1" />
</navigation>
</query>

View file

@ -0,0 +1,22 @@
<query id="getStatistics" action="select">
<tables>
<table name="member" alias="member" />
</tables>
<columns>
<column name="*" />
<query id="getMemberDocumentCount" alias="totalDocumentCount">
<tables>
<table name="documents" alias="documents" />
</tables>
<columns>
<column name="count(*)" alias="count" />
</columns>
<conditions>
<condition operation="equal" column="documents.user_id" default="member.user_id" />
</conditions>
</query>
</columns>
<conditions>
<condition operation="equal" column="user_id" var="user_id" notnull="notnull" />
</conditions>
</query>

View file

@ -0,0 +1,23 @@
<query id="getStatistics" action="select">
<tables>
<table name="member" alias="member" />
</tables>
<columns>
<column name="*" />
<query id="getMemberDocumentCount" alias="totalDocumentCount">
<tables>
<table name="documents" alias="documents" />
</tables>
<columns>
<column name="count(*)" alias="count" />
</columns>
<conditions>
<condition operation="equal" column="documents.user_id" default="member.user_id" />
<condition operation="equal" column="module_srl" var="module_srl" notnull="notnull" pipe="and" />
</conditions>
</query>
</columns>
<conditions>
<condition operation="equal" column="user_id" var="user_id" notnull="notnull" />
</conditions>
</query>

View file

@ -0,0 +1,19 @@
<query id="select_uncorrelated" action="select">
<tables>
<table name="table_a" />
</tables>
<columns>
<column name="column_a" alias="value_a" />
<query alias="value_b">
<tables>
<table name="table_b" />
</tables>
<columns>
<column name="max(column_b)" alias="count" />
</columns>
</query>
</columns>
<conditions>
<condition operation="equal" column="column_a" var="user_id" notnull="notnull" />
</conditions>
</query>

View file

@ -0,0 +1,24 @@
<query id="select_uncorrelated" action="select">
<tables>
<table name="table_a" />
</tables>
<columns>
<column name="column_a" alias="value_a" />
<column name="column_b" alias="value_b" />
<query alias="value_b">
<tables>
<table name="table_b" />
</tables>
<columns>
<column name="max(column_b)" alias="count" />
</columns>
<conditions>
<condition operation="equal" column="column_ab" var="user_name" notnull="notnull" />
</conditions>
</query>
<column name="column_c" alias="value_c" />
</columns>
<conditions>
<condition operation="equal" column="column_a" var="user_id" notnull="notnull" />
</conditions>
</query>

View file

@ -0,0 +1,19 @@
<query id="getGrantedModules" action="select">
<tables>
<table name="module_grants" />
</tables>
<columns>
<column name="module_srl" />
</columns>
<conditions>
<condition operation="in" column="name" default="'access','view','list'" notnull="notnull" />
<group pipe="and">
<condition operation="more" column="group_srl" default="1" notnull="notnull" />
<condition operation="equal" column="group_srl" default="-1" notnull="notnull" pipe="or" />
<condition operation="equal" column="group_srl" default="-2" notnull="notnull" pipe="or" />
</group>
</conditions>
<groups>
<group column="module_srl" />
</groups>
</query>

View file

@ -0,0 +1,26 @@
<query id="getModules" action="select">
<tables>
<table name="sites" />
<table name="modules" />
<table name="syndication_except_modules" alias="except_modules" type="left join">
<conditions>
<condition operation="equal" column="modules.module_srl" default="except_modules.module_srl" />
</conditions>
</table>
</tables>
<columns>
<column name="modules.site_srl" alias="site_srl" />
<column name="modules.module_srl" alias="module_srl" />
<column name="sites.domain" alias="domain" />
<column name="modules.mid" alias="mid" />
<column name="modules.module" alias="module" />
<column name="modules.browser_title" alias="browser_title" />
<column name="modules.description" alias="description" />
</columns>
<conditions>
<condition operation="in" column="modules.module_srl" var="module_srls" />
<condition operation="notin" column="modules.module_srl" var="except_module_srls" pipe="and" />
<condition operation="equal" column="sites.site_srl" default="modules.site_srl" notnull="notnull" pipe="and" />
<condition operation="null" column="except_modules.module_srl" default="1" pipe="and" />
</conditions>
</query>

View file

@ -0,0 +1,14 @@
<query id="index_hint" action="select">
<tables>
<table name="member" alias="member" />
<table name="document" alias="document" />
</tables>
<columns>
<column name="*" />
</columns>
<index_hint for="CUBRID">
<index table="member" name="idx_member_list_order" type="USE" />
<index table="member" name="idx_member_srl" type="USE" />
<index table="document" name="idx_document_srl" type="USE" />
</index_hint>
</query>

View file

@ -0,0 +1,14 @@
<query id="index_hint" action="select">
<tables>
<table name="member" alias="member" />
<table name="document" alias="document" />
</tables>
<columns>
<column name="*" />
</columns>
<index_hint for="CUBRID">
<index table="member" name="idx_member_list_order" type="USE" />
<index table="member" name="idx_member_srl" type="FORCE" />
<index table="document" name="idx_document_srl" type="USE" />
</index_hint>
</query>

View file

@ -0,0 +1,12 @@
<query id="index_hint" action="select">
<tables>
<table name="member" alias="member" />
</tables>
<columns>
<column name="*" />
</columns>
<index_hint for="CUBRID">
<index table="member" name="idx_member_list_order" type="USE" />
<index table="member" name="idx_member_srl" type="USE" />
</index_hint>
</query>

View file

@ -0,0 +1,21 @@
<query id="getMemberInfo" action="select">
<tables>
<table name="member" alias="member" />
</tables>
<columns>
<column name="*" />
</columns>
<conditions>
<query alias="documentMaxRegdate" operation="equal" column="regdate" notnull="notnull">
<tables>
<table name="documents" alias="documents" />
</tables>
<columns>
<column name="max(regdate)" alias="maxregdate" />
</columns>
<conditions>
<condition operation="equal" column="documents.user_id" default="member.user_id" notnull="notnull" />
</conditions>
</query>
</conditions>
</query>

View file

@ -0,0 +1,23 @@
<query id="getMemberInfo" action="select">
<tables>
<table name="member" alias="member" />
</tables>
<columns>
<column name="*" />
</columns>
<conditions>
<condition operation="equal" column="member_srl" var="member_srl" notnull="notnull"/>
<query alias="documentMaxRegdate" operation="equal" column="regdate" notnull="notnull" pipe="and" >
<tables>
<table name="documents" alias="documents" />
</tables>
<columns>
<column name="max(regdate)" alias="maxregdate" />
</columns>
<conditions>
<condition operation="equal" column="documents.user_id" default="member.user_id" notnull="notnull" />
<condition operation="equal" column="module_srl" var="module_srl" notnull="notnull" pipe="and" />
</conditions>
</query>
</conditions>
</query>

View file

@ -0,0 +1,18 @@
<query id="getMemberInfo" action="select">
<tables>
<table name="member" />
</tables>
<columns>
<column name="*" />
</columns>
<conditions>
<query operation="equal" column="regdate" alias="documentMaxRegdate">
<tables>
<table name="documents" />
</tables>
<columns>
<column name="max(regdate)" alias="maxregdate" />
</columns>
</query>
</conditions>
</query>

View file

@ -0,0 +1,64 @@
<?php
class MssqlIndexHintTest extends MssqlTest {
var $xmlPath = 'data/';
function MssqlIndexHintTest(){
$this->xmlPath = str_replace('MssqlIndexHintTest.php', '', str_replace('\\', '/', __FILE__)) . $this->xmlPath;
}
function _test($xml_file, $argsString, $expected){
$this->_testQuery($xml_file, $argsString, $expected, 'getSelectSql');
}
function testOneUseIndexHintAndOneTable(){
$xml_file = $this->xmlPath . "one_index_hint_one_table.xml";
$argsString = '';
$expected = 'select * from [xe_member] as [member] with(index([idx_member_list_order]))';
$this->_test($xml_file, $argsString, $expected);
}
function testTwoUseIndexHintsAndOneTable(){
$xml_file = $this->xmlPath . "two_index_hints_one_table.xml";
$argsString = '';
$expected = 'select * from [xe_member] as [member] with(index([idx_member_list_order]), index([idx_member_srl]))';
$this->_test($xml_file, $argsString, $expected);
}
function testThreeUseIndexHintsAndTwoTables(){
$xml_file = $this->xmlPath . "three_index_hints_two_tables.xml";
$argsString = '';
$expected = 'select * from [xe_member] as [member] with(index([idx_member_list_order]), index([idx_member_srl]))
, [xe_document] as [document] with(index([idx_document_srl]))';
$this->_test($xml_file, $argsString, $expected);
}
/**
* Tests that index is added if "for" attribute is "ALL"
*
* example: <index_hint for="ALL"> ... </index_hint>
*/
function testIndexHintForAll(){
$xml_file = $this->xmlPath . "index_hint_for_all.xml";
$argsString = '';
$expected = 'select * from [xe_member] as [member] with(index([idx_member_list_order]))';
$this->_test($xml_file, $argsString, $expected);
}
function testIgnoreIndexHintIsSkipped(){
$xml_file = $this->xmlPath . "ignore_index_hint.xml";
$argsString = '';
$expected = 'select * from [xe_member] as [member]';
$this->_test($xml_file, $argsString, $expected);
}
function testMysqlIndexHintIsSkipped(){
$xml_file = $this->xmlPath . "mysql_index_hint.xml";
$argsString = '';
$expected = 'select * from [xe_member] as [member]';
$this->_test($xml_file, $argsString, $expected);
}
}
?>

View file

@ -0,0 +1,11 @@
<?php
class MssqlSelectOnlineTest extends MssqlOnlineTest {
function test_syndication_getGrantedModule(){
$args->module_srl = 67;
$output = executeQuery("syndication.getGrantedModule", $args);
$this->assertEquals(0, $output->error, $output->error + ' ' + $output->message);
}
}
?>

View file

@ -0,0 +1,170 @@
<?php
class MssqlSelectTest extends MssqlTest {
function _test($xml_file, $argsString, $expected, $expectedArgs = NULL){
$this->_testPreparedQuery($xml_file, $argsString, $expected, 'getSelectSql', $expectedArgs);
}
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] = ? and [member].[member_srl] = [module_admins].[member_srl]';
$this->_test($xml_file, $argsString, $expected, array(10));
}
function testRequiredParameter(){
$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 = '$args->site_srl = 0;';
$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] = ?
ORDER BY [modules].[module] asc, [module_categories].[title] asc, [modules].[mid] asc';
$this->_test($xml_file, $argsString, $expected, array(0));
}
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] = ? ';
$this->_test($xml_file, $argsString, $expected, array(0));
}
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] = ? ';
$this->_test($xml_file, $argsString, $expected, array("'captcha'"));
}
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 TOP 2 substr([regdate],1,8) as [date], count(*) as [count]
FROM [xe_comment_declared_log] as [comment_declared_log]
WHERE [regdate] >= ?
GROUP BY substr([regdate],1,8)
ORDER BY substr([regdate],1,8) asc';
$this->_test($xml_file, $argsString, $expected, array("'20110411'"));
}
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] = ?
and [member].[member_srl] = [member_autologin].[member_srl]';
$this->_test($xml_file, $argsString, $expected, array("'10'"));
}
/**
* Query fails because XML is wrong - title column does not exist
* in xe_modules. Maybe the developer ment "browser_title"
*/
function test_opage_getOpageList(){
$xml_file = _TEST_PATH_ . "db/xml_query/mssql/data/opage.getOpageList.xml";
$argsString = '$args->s_title = "yuhuu";
$args->module = \'opage\';';
$expected = 'SELECT TOP 20 *
FROM [xe_modules] as [modules]
WHERE [module] = \'opage\' and ([title] like ?)
ORDER BY [module_srl] desc';
$this->_test($xml_file, $argsString, $expected, array("'%yuhuu%'"));
}
function test_module_getExtraVars(){
$xml_file = _XE_PATH_ . "modules/module/queries/getModuleExtraVars.xml";
$argsString = '$args->module_srl = 25;';
$expected = 'SELECT * FROM [xe_module_extra_vars] as [module_extra_vars] WHERE [module_srl] in (?)';
$this->_test($xml_file, $argsString, $expected, array(array(25)));
}
function test_module_getModuleSites(){
$xml_file = _XE_PATH_ . "modules/module/queries/getModuleSites.xml";
$argsString = '$args->module_srls = "67, 65";';
$expected = 'SELECT [modules].[module_srl] as [module_srl], [sites].[domain] as [domain] FROM [xe_modules] as [modules] , [xe_sites] as [sites] WHERE [modules].[module_srl] in (?,?) and [sites].[site_srl] = [modules].[site_srl]';
$this->_test($xml_file, $argsString, $expected, array(array(67, 65)));
}
function test_syndication_getGrantedModule(){
$xml_file = _TEST_PATH_ . "db/xml_query/mssql/data/syndication.getGrantedModule.xml";
$argsString = '$args->module_srl = 67;';
$expected = 'select count(*) as [count]
from [xe_module_grants] as [module_grants]
where [module_srl] = ?
and [name] in (\'access\',\'view\',\'list\')
and ([group_srl] >= 1
or [group_srl] = -1
or [group_srl] = -2)';
$this->_test($xml_file, $argsString, $expected, array(67));
}
}

View file

@ -0,0 +1,12 @@
<?php
class MssqlUpdateOnlineTest extends MssqlOnlineTest {
function test_counter_updateCounterUnique(){
$args->regdate = 20110211;
$output = executeQuery("counter.updateCounterUnique", $args);
$this->assertEquals(0, $output->error, $output->error + ' ' + $output->message);
}
}
?>

View file

@ -0,0 +1,16 @@
<?php
class MssqlUpdateTest extends MssqlTest {
function _test($xml_file, $argsString, $expected, $expectedArgs = NULL){
$this->_testPreparedQuery($xml_file, $argsString, $expected, 'getUpdateSql', $expectedArgs = NULL);
}
function test_counter_updateCounterUnique(){
$xml_file = _XE_PATH_ . "modules/counter/queries/updateCounterUnique.xml";
$argsString = '$args->regdate = 25;';
$expected = 'UPDATE [xe_counter_status] as [counter_status] SET [unique_visitor] = [unique_visitor] + ?, [pageview] = [pageview] + ? WHERE [regdate] = ?';
$this->_test($xml_file, $argsString, $expected, array("25", 1, 1));
}
}
?>

View file

@ -0,0 +1,11 @@
<query id="index_hint" action="select">
<tables>
<table name="member" alias="member" />
</tables>
<columns>
<column name="*" />
</columns>
<index_hint for="MSSQL">
<index table="member" name="idx_member_list_order" type="IGNORE" />
</index_hint>
</query>

View file

@ -0,0 +1,11 @@
<query id="index_hint" action="select">
<tables>
<table name="member" alias="member" />
</tables>
<columns>
<column name="*" />
</columns>
<index_hint for="ALL">
<index table="member" name="idx_member_list_order" type="USE" />
</index_hint>
</query>

View file

@ -0,0 +1,11 @@
<query id="index_hint" action="select">
<tables>
<table name="member" alias="member" />
</tables>
<columns>
<column name="*" />
</columns>
<index_hint for="MYSQL">
<index table="member" name="idx_member_list_order" type="IGNORE" />
</index_hint>
</query>

View file

@ -0,0 +1,11 @@
<query id="index_hint" action="select">
<tables>
<table name="member" alias="member" />
</tables>
<columns>
<column name="*" />
</columns>
<index_hint for="MSSQL">
<index table="member" name="idx_member_list_order" type="USE" />
</index_hint>
</query>

View file

@ -0,0 +1,24 @@
<query id="getOpageList" action="select">
<tables>
<table name="modules" />
</tables>
<columns>
<column name="*" />
</columns>
<conditions>
<condition operation="equal" column="module" default="opage" />
<group pipe="and">
<condition operation="like" column="mid" var="s_mid" pipe="or" />
<condition operation="like" column="title" var="s_title" pipe="or" />
<condition operation="like" column="comment" var="s_comment" pipe="or" />
<condition operation="equal" column="module" var="s_module" pipe="or" />
<condition operation="equal" column="module_category_srl" var="s_module_category_srl" pipe="or" />
</group>
</conditions>
<navigation>
<index var="sort_index" default="module_srl" order="desc" />
<list_count var="list_count" default="20" />
<page_count var="page_count" default="10" />
<page var="page" default="1" />
</navigation>
</query>

View file

@ -0,0 +1,17 @@
<query id="getGrantedModule" action="select">
<tables>
<table name="module_grants" />
</tables>
<columns>
<column name="count(*)" alias="count" />
</columns>
<conditions>
<condition operation="equal" column="module_srl" var="module_srl" filter="number" notnull="notnull" />
<condition operation="in" column="name" default="'access','view','list'" notnull="notnull" pipe="and" />
<group pipe="and">
<condition operation="more" column="group_srl" default="1" notnull="notnull" />
<condition operation="equal" column="group_srl" default="-1" notnull="notnull" pipe="or" />
<condition operation="equal" column="group_srl" default="-2" notnull="notnull" pipe="or" />
</group>
</conditions>
</query>

View file

@ -0,0 +1,14 @@
<query id="index_hint" action="select">
<tables>
<table name="member" alias="member" />
<table name="document" alias="document" />
</tables>
<columns>
<column name="*" />
</columns>
<index_hint for="MSSQL">
<index table="member" name="idx_member_list_order" type="USE" />
<index table="member" name="idx_member_srl" type="USE" />
<index table="document" name="idx_document_srl" type="USE" />
</index_hint>
</query>

View file

@ -0,0 +1,12 @@
<query id="index_hint" action="select">
<tables>
<table name="member" alias="member" />
</tables>
<columns>
<column name="*" />
</columns>
<index_hint for="MSSQL">
<index table="member" name="idx_member_list_order" type="USE" />
<index table="member" name="idx_member_srl" type="USE" />
</index_hint>
</query>

View file

@ -0,0 +1,58 @@
<?php
class MysqlIndexHintTest extends MysqlTest {
var $xmlPath = 'data/';
function MysqlIndexHintTest(){
$this->xmlPath = str_replace('MysqlIndexHintTest.php', '', str_replace('\\', '/', __FILE__)) . $this->xmlPath;
}
function _test($xml_file, $argsString, $expected){
$this->_testQuery($xml_file, $argsString, $expected, 'getSelectSql');
}
function testOneUseIndexHintAndOneTable(){
$xml_file = $this->xmlPath . "one_index_hint_one_table.xml";
$argsString = '';
$expected = 'select * from `xe_member` as `member` use index (`idx_member_list_order`)';
$this->_test($xml_file, $argsString, $expected);
}
function testTwoUseIndexHintsAndOneTable(){
$xml_file = $this->xmlPath . "two_index_hints_one_table.xml";
$argsString = '';
$expected = 'select * from `xe_member` as `member` use index (`idx_member_list_order`, `idx_member_srl`)';
$this->_test($xml_file, $argsString, $expected);
}
function testThreeUseIndexHintsAndTwoTables(){
$xml_file = $this->xmlPath . "three_index_hints_two_tables.xml";
$argsString = '';
$expected = 'select * from `xe_member` as `member` use index (`idx_member_list_order`, `idx_member_srl`)
, `xe_document` as `document` use index (`idx_document_srl`)';
$this->_test($xml_file, $argsString, $expected);
}
function testThreeIndexHintsAndTwoTables_ForceAndIgnore(){
$xml_file = $this->xmlPath . "three_index_hints_two_tables_combined.xml";
$argsString = '';
$expected = 'select * from `xe_member` as `member` force index (`idx_member_list_order`, `idx_member_srl`)
, `xe_document` as `document` ignore index (`idx_document_srl`)';
$this->_test($xml_file, $argsString, $expected);
}
/**
* Tests that index is added if "for" attribute is "ALL"
*
* example: <index_hint for="ALL"> ... </index_hint>
*/
function testIndexHintForAll(){
$xml_file = $this->xmlPath . "index_hint_for_all.xml";
$argsString = '';
$expected = 'select * from `xe_member` as `member` use index (`idx_member_list_order`)';
$this->_test($xml_file, $argsString, $expected);
}
}
?>

View file

@ -0,0 +1,193 @@
<?php
class MysqlSelectTest extends MysqlTest {
function _test($xml_file, $argsString, $expected, $columnList = null){
$this->_testQuery($xml_file, $argsString, $expected, 'getSelectSql', $columnList);
}
function testConditionWithVarAndColumnDefaultValue_WithoutArgument(){
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/resource.getLatestItem.xml";
$argsString = '$args->item_srl = "";';
$expected = 'select `package`.`module_srl` as `module_srl`
, `package`.`status` as `status`
, `package`.`category_srl` as `category_srl`
, `package`.`member_srl` as `member_srl`
, `package`.`package_srl` as `package_srl`
, `package`.`path` as `path`
, `package`.`license` as `license`
, `package`.`title` as `title`
, `package`.`homepage` as `homepage`
, `package`.`description` as `package_description`
, `package`.`voter` as `package_voter`
, `package`.`voted` as `package_voted`
, `package`.`downloaded` as `package_downloaded`
, `package`.`regdate` as `package_regdate`
, `package`.`last_update` as `package_last_update`
, `member`.`nick_name` as `nick_name`
, `member`.`user_id` as `user_id`
, `item`.`item_srl` as `item_srl`
, `item`.`document_srl` as `document_srl`
, `item`.`file_srl` as `item_file_srl`
, `item`.`screenshot_url` as `item_screenshot_url`
, `item`.`version` as `item_version`
, `item`.`voter` as `item_voter`
, `item`.`voted` as `item_voted`
, `item`.`downloaded` as `item_downloaded`
, `item`.`regdate` as `item_regdate`
from `xe_resource_packages` as `package`
, `xe_member` as `member`
, `xe_resource_items` as `item`
where `package`.`member_srl` = `member`.`member_srl`
and `item`.`item_srl` = `package`.`latest_item_srl`';
$this->_test($xml_file, $argsString, $expected);
}
function testConditionWithVarAndColumnDefaultValue_WithArgument(){
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/resource.getLatestItem.xml";
$argsString = '$args->item_srl = "10";';
$expected = 'select `package`.`module_srl` as `module_srl`
, `package`.`status` as `status`
, `package`.`category_srl` as `category_srl`
, `package`.`member_srl` as `member_srl`
, `package`.`package_srl` as `package_srl`
, `package`.`path` as `path`
, `package`.`license` as `license`
, `package`.`title` as `title`
, `package`.`homepage` as `homepage`
, `package`.`description` as `package_description`
, `package`.`voter` as `package_voter`
, `package`.`voted` as `package_voted`
, `package`.`downloaded` as `package_downloaded`
, `package`.`regdate` as `package_regdate`
, `package`.`last_update` as `package_last_update`
, `member`.`nick_name` as `nick_name`
, `member`.`user_id` as `user_id`
, `item`.`item_srl` as `item_srl`
, `item`.`document_srl` as `document_srl`
, `item`.`file_srl` as `item_file_srl`
, `item`.`screenshot_url` as `item_screenshot_url`
, `item`.`version` as `item_version`
, `item`.`voter` as `item_voter`
, `item`.`voted` as `item_voted`
, `item`.`downloaded` as `item_downloaded`
, `item`.`regdate` as `item_regdate`
from `xe_resource_packages` as `package`
, `xe_member` as `member`
, `xe_resource_items` as `item`
where `package`.`member_srl` = `member`.`member_srl`
and `item`.`item_srl` = 10';
$this->_test($xml_file, $argsString, $expected);
}
function testSubstring(){
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/substring.xml";
$argsString = '$args->var_start_mmdd = "1102"; ';
$expected = 'select * from `xe_member` as `member` where substr(`extra_vars_t1`.`value`,5,4) >= 1102';
$this->_test($xml_file, $argsString, $expected);
}
function testResource_getLatestItemList(){
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/resource.getLatestItemList.xml";
$argsString = '';
$expected = 'select `package`.`module_srl` as `module_srl`
, `package`.`status` as `status`
, `package`.`category_srl` as `category_srl`
, `package`.`member_srl` as `member_srl`
, `package`.`package_srl` as `package_srl`
, `package`.`path` as `path`
, `package`.`license` as `license`
, `package`.`title` as `title`
, `package`.`homepage` as `homepage`
, `package`.`description` as `package_description`
, `package`.`voter` as `package_voter`
, `package`.`voted` as `package_voted`
, `package`.`downloaded` as `package_downloaded`
, `package`.`regdate` as `package_regdate`
, `package`.`last_update` as `package_last_update`
, `member`.`nick_name` as `nick_name`
, `member`.`user_id` as `user_id`
, `item`.`item_srl` as `item_srl`
, `item`.`document_srl` as `item_document_srl`
, `item`.`file_srl` as `item_file_srl`
, `item`.`screenshot_url` as `item_screenshot_url`
, `item`.`version` as `item_version`
, `item`.`voter` as `item_voter`
, `item`.`voted` as `item_voted`
, `item`.`downloaded` as `item_downloaded`
, `item`.`regdate` as `item_regdate`
, `files`.`source_filename` as `source_filename`
, `files`.`sid` as `sid`
from `xe_resource_packages` as `package`
, `xe_member` as `member`
, `xe_resource_items` as `item`
, `xe_files` as `files`
where (`package`.`status` = \'accepted\'
and `package`.`member_srl` = `member`.`member_srl`
and `item`.`item_srl` = `package`.`latest_item_srl`
and `package`.`update_order` <= 0
and `files`.`file_srl` = `item`.`file_srl`)
and `package`.`update_order` <= 2100000000
order by `package`.`update_order` asc
limit 0, 20';
$this->_test($xml_file, $argsString, $expected);
}
function test_Syndication_getGrantedModules(){
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/syndication.getGrantedModules.xml";
$argsString = '';
$expected = 'select `module_srl`
from `xe_module_grants` as `module_grants`
where `name` in (\'access\',\'view\',\'list\')
and (`group_srl` >= 1 or `group_srl` = -1 or `group_srl` = -2) group by `module_srl`';
$this->_test($xml_file, $argsString, $expected);
}
function test_Like_Clause(){
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/opage.getOpageList.like.xml";
$argsString = '$args->s_mid = "test";';
$expected = 'select *
from `xe_modules` as `modules`
where `module` = \'opage\'
and (`mid` like \'%test%\')
order by `module_srl` desc
limit 0, 20';
$this->_test($xml_file, $argsString, $expected);
}
function test_NotLike_Clause(){
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/opage.getOpageList.notlike.xml";
$argsString = '$args->s_mid = "test";';
$expected = 'select *
from `xe_modules` as `modules`
where `module` = \'opage\'
and (`mid` not like \'%test%\')
order by `module_srl` desc
limit 0, 20';
$this->_test($xml_file, $argsString, $expected);
}
function test_NotLikeTail_Clause(){
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/opage.getOpageList.notliketail.xml";
$argsString = '$args->s_mid = "test";';
$expected = 'select *
from `xe_modules` as `modules`
where `module` = \'opage\'
and (`mid` not like \'%test\')
order by `module_srl` desc
limit 0, 20';
$this->_test($xml_file, $argsString, $expected);
}
function test_NotLikePrefix_Clause(){
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/opage.getOpageList.notlikeprefix.xml";
$argsString = '$args->s_mid = "test";';
$expected = 'select *
from `xe_modules` as `modules`
where `module` = \'opage\'
and (`mid` not like \'test%\')
order by `module_srl` desc
limit 0, 20';
$this->_test($xml_file, $argsString, $expected);
}
}

View file

@ -0,0 +1,75 @@
<?php
class MysqlUpdateTest extends MysqlTest {
function _test($xml_file, $argsString, $expected, $columnList = null){
$this->_testQuery($xml_file, $argsString, $expected, 'getUpdateSql', $columnList);
}
function test_document_updateDocumentStatus(){
$xml_file = _XE_PATH_ . "modules/document/queries/updateDocumentStatus.xml";
$argsString = '$args->is_secret = \'Y\';
$args->status = \'SECRET\';
';
$expected = 'update `xe_documents` as `documents` set `status` = \'secret\' where `is_secret` = \'y\'';
$this->_test($xml_file, $argsString, $expected);
}
/**
* Issue 388 - Query cache error related table alias
* http://code.google.com/p/xe-core/issues/detail?id=388
*/
function test_importer_updateDocumentSync(){
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/importer.updateDocumentSync.xml";
$argsString = '';
$expected = 'UPDATE `xe_documents` as `documents`, `xe_member` as `member`
SET `documents`.`member_srl` = `member`.`member_srl`
WHERE `documents`.`user_id` = `member`.`user_id`
';
$this->_test($xml_file, $argsString, $expected);
}
function test_document_updateItemDownloadedCount(){
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/document.updateItemDownloadedCount.xml";
$argsString = '$args->module_srl = 10; $args->package_srl = 11; $args->item_srl = 12;';
$expected = 'update `xe_resource_items` as `resource_items`
set `downloaded` = `downloaded` + 1
where `module_srl` = 10
and `package_srl` = 11
and `item_srl` = 12
';
$this->_test($xml_file, $argsString, $expected);
}
function test_menu_updateMenuItemListorder(){
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/menu.updateMenuItemListorder.xml";
$argsString = '$args->menu_srl = 10; $args->parent_srl = 11; $args->listorder = 12;';
$expected = 'update `xe_menu_item` as `menu_item`
set `listorder` = `listorder` - 1
where `menu_srl` = 10
and `parent_srl` = 11
and `listorder` <= 12';
$this->_test($xml_file, $argsString, $expected);
}
function test_communication_setMessageReaded(){
$xml_file = _XE_PATH_ . "modules/communication/queries/setMessageReaded.xml";
$argsString = '$args->message_srl = 339321; $args->related_srl = 339321;';
$expected = 'update `xe_member_message` as `member_message`
set `readed` = \'y\'
, `readed_date` = \'' . date("YmdHis") . '\'
where `message_srl` = 339321 or `related_srl` = 339321';
$this->_test($xml_file, $argsString, $expected);
}
function test_session_updateSession(){
$xml_file = _XE_PATH_ . "modules/session/queries/updateSession.xml";
$argsString = '$args->session_key = 339321; $args->val = "yuhuu";';
$expected = 'update `xe_session` as `session`
set `member_srl` = 0, `val` = \'yuhuu\'
, `ipaddress` = \''. $_SERVER['REMOTE_ADDR'] .'\'
, `last_update` = \'' . date("YmdHis") . '\'
where `session_key` = \'339321\'';
$this->_test($xml_file, $argsString, $expected);
}
}

View file

@ -0,0 +1,13 @@
<query id="updateItemDownloadedCount" action="update">
<tables>
<table name="resource_items" />
</tables>
<columns>
<column name="downloaded" default="plus(1)" notnull="notnull" />
</columns>
<conditions>
<condition operation="equal" column="module_srl" var="module_srl" filter="number" notnull="notnull" />
<condition operation="equal" column="package_srl" var="package_srl" filter="number" notnull="notnull" pipe="and" />
<condition operation="equal" column="item_srl" var="item_srl" filter="number" notnull="notnull" pipe="and" />
</conditions>
</query>

View file

@ -0,0 +1,12 @@
<query id="updateDocumentSync" action="update">
<tables>
<table name="documents" alias="documents" />
<table name="member" alias="member" />
</tables>
<columns>
<column name="documents.member_srl" default="member.member_srl" filter="number" />
</columns>
<conditions>
<condition operation="equal" column="documents.user_id" default="member.user_id" />
</conditions>
</query>

View file

@ -0,0 +1,11 @@
<query id="index_hint" action="select">
<tables>
<table name="member" alias="member" />
</tables>
<columns>
<column name="*" />
</columns>
<index_hint for="ALL">
<index table="member" name="idx_member_list_order" type="USE" />
</index_hint>
</query>

View file

@ -0,0 +1,13 @@
<query id="updateMenuItemListorder" action="update">
<tables>
<table name="menu_item" />
</tables>
<columns>
<column name="listorder" default="minus(1)" />
</columns>
<conditions>
<condition operation="equal" column="menu_srl" var="menu_srl" filter="number" notnull="notnull" />
<condition operation="equal" column="parent_srl" var="parent_srl" filter="number" notnull="notnull" pipe="and" />
<condition operation="less" column="listorder" var="listorder" filter="number" notnull="notnull" pipe="and" />
</conditions>
</query>

View file

@ -0,0 +1,11 @@
<query id="index_hint" action="select">
<tables>
<table name="member" alias="member" />
</tables>
<columns>
<column name="*" />
</columns>
<index_hint for="MYSQL">
<index table="member" name="idx_member_list_order" type="USE" />
</index_hint>
</query>

View file

@ -0,0 +1,24 @@
<query id="getOpageList" action="select">
<tables>
<table name="modules" />
</tables>
<columns>
<column name="*" />
</columns>
<conditions>
<condition operation="equal" column="module" default="opage" />
<group pipe="and">
<condition operation="like" column="mid" var="s_mid" pipe="or" />
<condition operation="like" column="title" var="s_title" pipe="or" />
<condition operation="like" column="comment" var="s_comment" pipe="or" />
<condition operation="equal" column="module" var="s_module" pipe="or" />
<condition operation="equal" column="module_category_srl" var="s_module_category_srl" pipe="or" />
</group>
</conditions>
<navigation>
<index var="sort_index" default="module_srl" order="desc" />
<list_count var="list_count" default="20" />
<page_count var="page_count" default="10" />
<page var="page" default="1" />
</navigation>
</query>

View file

@ -0,0 +1,24 @@
<query id="getOpageList" action="select">
<tables>
<table name="modules" />
</tables>
<columns>
<column name="*" />
</columns>
<conditions>
<condition operation="equal" column="module" default="opage" />
<group pipe="and">
<condition operation="notlike" column="mid" var="s_mid" pipe="or" />
<condition operation="like" column="title" var="s_title" pipe="or" />
<condition operation="like" column="comment" var="s_comment" pipe="or" />
<condition operation="equal" column="module" var="s_module" pipe="or" />
<condition operation="equal" column="module_category_srl" var="s_module_category_srl" pipe="or" />
</group>
</conditions>
<navigation>
<index var="sort_index" default="module_srl" order="desc" />
<list_count var="list_count" default="20" />
<page_count var="page_count" default="10" />
<page var="page" default="1" />
</navigation>
</query>

View file

@ -0,0 +1,24 @@
<query id="getOpageList" action="select">
<tables>
<table name="modules" />
</tables>
<columns>
<column name="*" />
</columns>
<conditions>
<condition operation="equal" column="module" default="opage" />
<group pipe="and">
<condition operation="notlike_prefix" column="mid" var="s_mid" pipe="or" />
<condition operation="like" column="title" var="s_title" pipe="or" />
<condition operation="like" column="comment" var="s_comment" pipe="or" />
<condition operation="equal" column="module" var="s_module" pipe="or" />
<condition operation="equal" column="module_category_srl" var="s_module_category_srl" pipe="or" />
</group>
</conditions>
<navigation>
<index var="sort_index" default="module_srl" order="desc" />
<list_count var="list_count" default="20" />
<page_count var="page_count" default="10" />
<page var="page" default="1" />
</navigation>
</query>

View file

@ -0,0 +1,24 @@
<query id="getOpageList" action="select">
<tables>
<table name="modules" />
</tables>
<columns>
<column name="*" />
</columns>
<conditions>
<condition operation="equal" column="module" default="opage" />
<group pipe="and">
<condition operation="notlike_tail" column="mid" var="s_mid" pipe="or" />
<condition operation="like" column="title" var="s_title" pipe="or" />
<condition operation="like" column="comment" var="s_comment" pipe="or" />
<condition operation="equal" column="module" var="s_module" pipe="or" />
<condition operation="equal" column="module_category_srl" var="s_module_category_srl" pipe="or" />
</group>
</conditions>
<navigation>
<index var="sort_index" default="module_srl" order="desc" />
<list_count var="list_count" default="20" />
<page_count var="page_count" default="10" />
<page var="page" default="1" />
</navigation>
</query>

View file

@ -0,0 +1,40 @@
<query id="getLatestItem" action="select">
<tables>
<table name="resource_packages" alias="package" />
<table name="member" alias="member" />
<table name="resource_items" alias="item" />
</tables>
<columns>
<column name="package.module_srl" alias="module_srl"/>
<column name="package.status" alias="status"/>
<column name="package.category_srl" alias="category_srl"/>
<column name="package.member_srl" alias="member_srl"/>
<column name="package.package_srl" alias="package_srl"/>
<column name="package.path" alias="path"/>
<column name="package.license" alias="license"/>
<column name="package.title" alias="title"/>
<column name="package.homepage" alias="homepage"/>
<column name="package.description" alias="package_description"/>
<column name="package.voter" alias="package_voter"/>
<column name="package.voted" alias="package_voted"/>
<column name="package.downloaded" alias="package_downloaded"/>
<column name="package.regdate" alias="package_regdate"/>
<column name="package.last_update" alias="package_last_update"/>
<column name="member.nick_name" alias="nick_name" />
<column name="member.user_id" alias="user_id" />
<column name="item.item_srl" alias="item_srl" />
<column name="item.document_srl" alias="document_srl" />
<column name="item.file_srl" alias="item_file_srl" />
<column name="item.screenshot_url" alias="item_screenshot_url" />
<column name="item.version" alias="item_version" />
<column name="item.voter" alias="item_voter" />
<column name="item.voted" alias="item_voted" />
<column name="item.downloaded" alias="item_downloaded" />
<column name="item.regdate" alias="item_regdate" />
</columns>
<conditions>
<condition operation="equal" column="package.package_srl" var="package_srl" filter="number" />
<condition operation="equal" column="package.member_srl" default="member.member_srl" filter="number" pipe="and" />
<condition operation="equal" column="item.item_srl" var="item_srl" default="package.latest_item_srl" filter="number" pipe="and" />
</conditions>
</query>

View file

@ -0,0 +1,60 @@
<query id="getLatestItemList" action="select">
<tables>
<table name="resource_packages" alias="package" />
<table name="member" alias="member" />
<table name="resource_items" alias="item" />
<table name="files" alias="files" />
</tables>
<columns>
<column name="package.module_srl" alias="module_srl"/>
<column name="package.status" alias="status"/>
<column name="package.category_srl" alias="category_srl"/>
<column name="package.member_srl" alias="member_srl"/>
<column name="package.package_srl" alias="package_srl"/>
<column name="package.path" alias="path"/>
<column name="package.license" alias="license"/>
<column name="package.title" alias="title"/>
<column name="package.homepage" alias="homepage"/>
<column name="package.description" alias="package_description"/>
<column name="package.voter" alias="package_voter"/>
<column name="package.voted" alias="package_voted"/>
<column name="package.downloaded" alias="package_downloaded"/>
<column name="package.regdate" alias="package_regdate"/>
<column name="package.last_update" alias="package_last_update"/>
<column name="member.nick_name" alias="nick_name" />
<column name="member.user_id" alias="user_id" />
<column name="item.item_srl" alias="item_srl" />
<column name="item.document_srl" alias="item_document_srl" />
<column name="item.file_srl" alias="item_file_srl" />
<column name="item.screenshot_url" alias="item_screenshot_url" />
<column name="item.version" alias="item_version" />
<column name="item.voter" alias="item_voter" />
<column name="item.voted" alias="item_voted" />
<column name="item.downloaded" alias="item_downloaded" />
<column name="item.regdate" alias="item_regdate" />
<column name="files.source_filename" alias="source_filename"/>
<column name="files.sid" alias="sid"/>
</columns>
<conditions>
<condition operation="equal" column="package.module_srl" var="module_srl" filter="number" />
<condition operation="equal" column="package.status" default="accepted" pipe="and" />
<condition operation="in" column="package.category_srl" var="category_srl" filter="number" pipe="and" />
<condition operation="more" column="package.category_srl" var="idx_category_srl" pipe="and" />
<condition operation="equal" column="package.member_srl" var="member_srl" filter="number" pipe="and" />
<condition operation="equal" column="package.member_srl" default="member.member_srl" filter="number" pipe="and" />
<condition operation="equal" column="item.item_srl" default="package.latest_item_srl" filter="number" pipe="and" />
<condition operation="less" column="package.update_order" default="0" filter="number" notnull="notnull" pipe="and" />
<condition operation="equal" column="files.file_srl" default="item.file_srl" filter="number" notnull="notnull" pipe="and" />
<group pipe="and">
<condition operation="like" column="package.title" var="search_keyword" pipe="or" />
<condition operation="like" column="package.path" var="search_keyword" pipe="or" />
<condition operation="like" column="package.description" var="search_keyword" pipe="or" />
</group>
</conditions>
<navigation>
<index var="sort_index" default="package.update_order" order="order_type" />
<list_count var="list_count" default="20" />
<page_count var="page_count" default="10" />
<page var="page" default="1" />
</navigation>
</query>

View file

@ -0,0 +1,11 @@
<query id="substringTest" action="select">
<tables>
<table name="member" alias="member" />
</tables>
<columns>
<column name="*" />
</columns>
<conditions>
<condition operation="more" column="substr(extra_vars_t1.value,5,4)" var="var_start_mmdd" notnull="notnull" pipe="and" />
</conditions>
</query>

View file

@ -0,0 +1,19 @@
<query id="getGrantedModules" action="select">
<tables>
<table name="module_grants" />
</tables>
<columns>
<column name="module_srl" />
</columns>
<conditions>
<condition operation="in" column="name" default="'access','view','list'" notnull="notnull" />
<group pipe="and">
<condition operation="more" column="group_srl" default="1" notnull="notnull" />
<condition operation="equal" column="group_srl" default="-1" notnull="notnull" pipe="or" />
<condition operation="equal" column="group_srl" default="-2" notnull="notnull" pipe="or" />
</group>
</conditions>
<groups>
<group column="module_srl" />
</groups>
</query>

View file

@ -0,0 +1,14 @@
<query id="index_hint" action="select">
<tables>
<table name="member" alias="member" />
<table name="document" alias="document" />
</tables>
<columns>
<column name="*" />
</columns>
<index_hint for="MYSQL">
<index table="member" name="idx_member_list_order" type="USE" />
<index table="member" name="idx_member_srl" type="USE" />
<index table="document" name="idx_document_srl" type="USE" />
</index_hint>
</query>

View file

@ -0,0 +1,14 @@
<query id="index_hint" action="select">
<tables>
<table name="member" alias="member" />
<table name="document" alias="document" />
</tables>
<columns>
<column name="*" />
</columns>
<index_hint for="MYSQL">
<index table="member" name="idx_member_list_order" type="FORCE" />
<index table="member" name="idx_member_srl" type="FORCE" />
<index table="document" name="idx_document_srl" type="IGNORE" />
</index_hint>
</query>

View file

@ -0,0 +1,12 @@
<query id="index_hint" action="select">
<tables>
<table name="member" alias="member" />
</tables>
<columns>
<column name="*" />
</columns>
<index_hint for="MYSQL">
<index table="member" name="idx_member_list_order" type="USE" />
<index table="member" name="idx_member_srl" type="USE" />
</index_hint>
</query>

View file

@ -0,0 +1,17 @@
<?php
class SqliteDeleteTest extends SqliteTest {
function _test($xml_file, $argsString, $expected, $columnList = null){
$this->_testQuery($xml_file, $argsString, $expected, 'getDeleteSql', $columnList);
}
function testDeleteIsGeneratedWithoutAlias(){
$xml_file = _TEST_PATH_ . "db/xml_query/sqlite/data/module.deleteModuleConfig.xml";
$argsString = '$args->module = "comment"; $args->site_srl = 0; ';
$expected = 'delete from "xe_module_config"
where "module" = \'comment\' and "site_srl" = 0';
$this->_test($xml_file, $argsString, $expected);
}
}

View file

@ -0,0 +1,21 @@
<?php
class SqliteUpdateTest extends SqliteTest {
function _test($xml_file, $argsString, $expected, $columnList = null){
$this->_testQuery($xml_file, $argsString, $expected, 'getUpdateSql', $columnList);
}
function testUpdateIsGeneratedWithoutAlias(){
$xml_file = _TEST_PATH_ . "db/xml_query/sqlite/data/member.updateLastLogin.xml";
$argsString = '$args->member_srl = 4;
$args->last_login = \'20111014184010\';
';
$expected = 'UPDATE "xe_member"
SET "member_srl" = 4
, "last_login" = \'20111014184010\'
WHERE "member_srl" = 4';
$this->_test($xml_file, $argsString, $expected);
}
}

View file

@ -0,0 +1,12 @@
<query id="updateLastLogin" action="update">
<tables>
<table name="member" />
</tables>
<columns>
<column name="member_srl" var="member_srl" filter="number" notnull="notnull" />
<column name="last_login" var="last_login" notnull="notnull" />
</columns>
<conditions>
<condition operation="equal" column="member_srl" var="member_srl" notnull="notnull" filter="number" />
</conditions>
</query>

View file

@ -0,0 +1,9 @@
<query id="deleteModuleConfig" action="delete">
<tables>
<table name="module_config" />
</tables>
<conditions>
<condition operation="equal" column="module" var="module" notnull="notnull" />
<condition operation="equal" column="site_srl" var="site_srl" notnull="notnull" pipe="and" />
</conditions>
</query>