mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-14 00:39:57 +09:00
Added classes for testing db queries directly on a test database. Fixed a few insert bugs.
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0-DB@8600 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
54ef159878
commit
9606e263e8
9 changed files with 173 additions and 21 deletions
|
|
@ -207,7 +207,7 @@
|
|||
$this->actFinish ();
|
||||
|
||||
// Return the result
|
||||
return $result;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@
|
|||
$dbParser = XmlQueryParser::getDBParser();
|
||||
return $dbParser->parseExpression($value);
|
||||
}
|
||||
if(!isset($value) || $value === '') return null;
|
||||
if(!isset($value)) return null;
|
||||
if(in_array($this->type, array('date', 'varchar', 'char','text', 'bigtext'))){
|
||||
if(!is_array($value))
|
||||
$value = $this->_escapeStringValue ($value);
|
||||
|
|
|
|||
|
|
@ -227,6 +227,22 @@ class ArgumentTest extends CubridTest {
|
|||
|
||||
$this->assertEquals('(3,21)', $member_srl_argument->getValue());
|
||||
}
|
||||
|
||||
public function testEnsureDefaultValueWithEmptyString(){
|
||||
$homepage_argument = new Argument('homepage', '');
|
||||
$homepage_argument->ensureDefaultValue('');
|
||||
$homepage_argument->checkFilter('homepage');
|
||||
if(!$homepage_argument->isValid()) return $homepage_argument->getErrorMessage();
|
||||
$homepage_argument->setColumnType('varchar');
|
||||
|
||||
|
||||
$this->assertEquals('\'\'', $homepage_argument->getValue());
|
||||
}
|
||||
|
||||
public function testDefaultValue() {
|
||||
$default = new DefaultValue("var", '');
|
||||
$this->assertEquals('\'\'', $default->toString());
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -4,20 +4,22 @@
|
|||
define('_TEST_PATH_', _XE_PATH_ . 'test-phpUnit/');
|
||||
|
||||
if(!defined('__DEBUG__')) define('__DEBUG__', 4);
|
||||
define('__ZBXE__', true);
|
||||
|
||||
require_once(_XE_PATH_.'test-phpUnit/Helper.class.php');
|
||||
require_once(_XE_PATH_.'test-phpUnit/QueryTester.class.php');
|
||||
require_once(_XE_PATH_.'test-phpUnit/db/DBTest.php');
|
||||
require_once(_XE_PATH_.'test-phpUnit/db/CubridTest.php');
|
||||
require_once(_XE_PATH_.'test-phpUnit/db/CubridOnlineTest.php');
|
||||
|
||||
|
||||
require_once(_XE_PATH_.'classes/object/Object.class.php');
|
||||
require_once(_XE_PATH_.'classes/handler/Handler.class.php');
|
||||
require_once(_XE_PATH_.'classes/context/Context.class.php');
|
||||
require_once(_XE_PATH_.'classes/file/FileHandler.class.php');
|
||||
require_once(_XE_PATH_.'classes/xml/XmlParser.class.php');
|
||||
require_once(_XE_PATH_.'config/config.inc.php');
|
||||
// require_once(_XE_PATH_.'classes/object/Object.class.php');
|
||||
// require_once(_XE_PATH_.'classes/handler/Handler.class.php');
|
||||
// require_once(_XE_PATH_.'classes/context/Context.class.php');
|
||||
// require_once(_XE_PATH_.'classes/file/FileHandler.class.php');
|
||||
// require_once(_XE_PATH_.'classes/xml/XmlParser.class.php');
|
||||
require_once(_XE_PATH_.'classes/xml/XmlQueryParser.class.php');
|
||||
|
||||
//
|
||||
|
||||
require_once(_XE_PATH_.'classes/db/DB.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/DBCubrid.class.php');
|
||||
|
|
@ -26,6 +28,7 @@
|
|||
require_once(_XE_PATH_.'classes/xml/xmlquery/DBParser.class.php');
|
||||
require_once(_XE_PATH_.'classes/xml/xmlquery/argument/Argument.class.php');
|
||||
require_once(_XE_PATH_.'classes/xml/xmlquery/argument/ConditionArgument.class.php');
|
||||
require_once(_XE_PATH_.'classes/xml/xmlquery/queryargument/DefaultValue.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/expression/Expression.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/expression/SelectExpression.class.php');
|
||||
require_once(_XE_PATH_.'classes/db/queryparts/expression/InsertExpression.class.php');
|
||||
|
|
@ -43,5 +46,4 @@
|
|||
require_once(_XE_PATH_.'classes/xml/xmlquery/tags/table/TableTag.class.php');
|
||||
require_once(_XE_PATH_.'classes/xml/xmlquery/tags/condition/ConditionTag.class.php');
|
||||
require_once(_XE_PATH_.'classes/xml/xmlquery/queryargument/QueryArgument.class.php');
|
||||
|
||||
?>
|
||||
38
test-phpUnit/db/CubridOnlineTest.php
Normal file
38
test-phpUnit/db/CubridOnlineTest.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?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() {
|
||||
$oContext = &Context::getInstance();
|
||||
|
||||
$db_info->db_type = 'cubrid';
|
||||
$db_info->db_port = '33000';
|
||||
$db_info->db_hostname = '10.0.0.206';
|
||||
$db_info->db_userid = 'dba';
|
||||
$db_info->db_password = 'arniarules';
|
||||
$db_info->db_database = 'xe15QA';
|
||||
$db_info->db_table_prefix = 'xe';
|
||||
|
||||
$oContext->setDbInfo($db_info);
|
||||
}
|
||||
|
||||
/**
|
||||
* Free resources - reset static DB and QueryParser
|
||||
*/
|
||||
protected function tearDown() {
|
||||
unset($GLOBALS['__DB__']);
|
||||
XmlQueryParser::setDBParser(null);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,12 +1,14 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
/**
|
||||
* 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();
|
||||
|
||||
|
|
@ -16,6 +18,9 @@
|
|||
$oContext->setDbInfo($db_info);
|
||||
}
|
||||
|
||||
/**
|
||||
* Free resources - reset static DB and QueryParser
|
||||
*/
|
||||
protected function tearDown() {
|
||||
unset($GLOBALS['__DB__']);
|
||||
XmlQueryParser::setDBParser(null);
|
||||
|
|
|
|||
69
test-phpUnit/db/xml_query/cubrid/CubridInsertOnlineTest.php
Normal file
69
test-phpUnit/db/xml_query/cubrid/CubridInsertOnlineTest.php
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
<?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);
|
||||
}
|
||||
|
||||
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, $args->error);
|
||||
$this->assertNotEquals('Missing value for attribute "homepage" with the NOT NULL constraint.', $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->close();
|
||||
|
||||
parent::tearDown();
|
||||
// TODO Delete inserted value
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -50,14 +50,15 @@
|
|||
, \'n\')';
|
||||
$this->_test($xml_file, $argsString, $expected);
|
||||
}
|
||||
function test_module_insertSiteTodayStatus(){
|
||||
|
||||
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"
|
||||
("regdate"
|
||||
, "unique_visitor"
|
||||
, "pageview")
|
||||
values
|
||||
|
|
@ -94,7 +95,6 @@
|
|||
$args->allow_mailing = "Y";
|
||||
$args->allow_message = "Y";
|
||||
$args->denied = "N";
|
||||
$args->limit_date = "";
|
||||
$args->regdate = "20110607121952";
|
||||
$args->change_password_date = "20110607121952";
|
||||
$args->last_login = "20110607121952";
|
||||
|
|
@ -104,10 +104,10 @@
|
|||
';
|
||||
$expected = 'INSERT INTO "xe_member"
|
||||
("member_srl", "user_id", "email_address", "password", "email_id", "email_host", "user_name", "nick_name",
|
||||
"homepage", "allow_mailing", "allow_message", "denied", "limit_date", "regdate", "change_password_date",
|
||||
"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\',
|
||||
\'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);
|
||||
}
|
||||
|
|
|
|||
22
test-phpUnit/db/xml_query/cubrid/CubridSelectOnlineTest.php
Normal file
22
test-phpUnit/db/xml_query/cubrid/CubridSelectOnlineTest.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?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);
|
||||
$this->assertEquals($output->data->module_srl, 111);
|
||||
}
|
||||
|
||||
function test_module_getInfo(){
|
||||
$args->site_srl = 0;
|
||||
$output = executeQuery('module.getSiteInfo', $args);
|
||||
$this->assertTrue(is_a($output, 'Object'));
|
||||
$this->assertEquals(0, $output->error);
|
||||
var_dump($output);
|
||||
}
|
||||
}
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue