mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-09 03:52:15 +09:00
Added unit tests for Table, TableTag and TablesTag classes.
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0-DB@8566 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
d248d70773
commit
7112d518c8
7 changed files with 178 additions and 4 deletions
|
|
@ -1,14 +1,17 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Helper {
|
class Helper {
|
||||||
static function cleanQuery($query){
|
static function cleanString($query){
|
||||||
$query = trim(preg_replace('/\s+/', ' ',$query));
|
$query = trim(preg_replace('/\s+/', ' ',$query));
|
||||||
|
$query = preg_replace('/\t+/', '',$query);
|
||||||
$query = str_replace(" , ", ', ', $query);
|
$query = str_replace(" , ", ', ', $query);
|
||||||
|
$query = str_replace(" ,", ',', $query);
|
||||||
$query = str_replace("( ", '(', $query);
|
$query = str_replace("( ", '(', $query);
|
||||||
$query = str_replace(" )", ')', $query);
|
$query = str_replace(" )", ')', $query);
|
||||||
|
$query = str_replace(array("\r", "\r\n", "\n"), '*', $query);
|
||||||
$query = strtolower($query);
|
$query = strtolower($query);
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function getXmlObject($xml_file){
|
static function getXmlObject($xml_file){
|
||||||
$xmlParser = XmlQueryParser::getInstance();
|
$xmlParser = XmlQueryParser::getInstance();
|
||||||
|
|
|
||||||
42
test-phpUnit/classes/db/queryparts/table/TableTest.php
Normal file
42
test-phpUnit/classes/db/queryparts/table/TableTest.php
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for Table.
|
||||||
|
*/
|
||||||
|
class TableTest extends CubridTest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Table
|
||||||
|
*/
|
||||||
|
protected $object;
|
||||||
|
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
$this->object = new Table('"xe_member"', '"m"');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function tearDown()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testToString()
|
||||||
|
{
|
||||||
|
$this->assertEquals('"xe_member" as "m"', $this->object->toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetName()
|
||||||
|
{
|
||||||
|
$this->assertEquals('"xe_member"', $this->object->getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetAlias()
|
||||||
|
{
|
||||||
|
$this->assertEquals('"m"', $this->object->getAlias());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIsJoinTable()
|
||||||
|
{
|
||||||
|
$this->assertEquals(false, $this->object->isJoinTable());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
@ -63,8 +63,8 @@
|
||||||
new Condition(\'"module_categories"."module_category_srl"\',\'"modules"."module_category_srl"\',"equal")
|
new Condition(\'"module_categories"."module_category_srl"\',\'"modules"."module_category_srl"\',"equal")
|
||||||
))
|
))
|
||||||
))';
|
))';
|
||||||
$actual = Helper::cleanQuery($actual);
|
$actual = Helper::cleanString($actual);
|
||||||
$expected = Helper::cleanQuery($expected);
|
$expected = Helper::cleanString($expected);
|
||||||
|
|
||||||
$this->assertEquals($expected, $actual);
|
$this->assertEquals($expected, $actual);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
114
test-phpUnit/classes/xml/xmlquery/tags/table/TablesTagTest.php
Normal file
114
test-phpUnit/classes/xml/xmlquery/tags/table/TablesTagTest.php
Normal file
|
|
@ -0,0 +1,114 @@
|
||||||
|
<?php
|
||||||
|
require(_XE_PATH_ . 'test-phpUnit/config/config.inc.php');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for TablesTag.
|
||||||
|
*/
|
||||||
|
class TablesTagTest extends CubridTest {
|
||||||
|
|
||||||
|
var $xmlPath = "data/";
|
||||||
|
|
||||||
|
function TablesTagTest(){
|
||||||
|
$this->xmlPath = str_replace('TablesTagTest.php', '', str_replace('\\', '/', __FILE__)) . $this->xmlPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests a simple <tables> tag:
|
||||||
|
* <tables>
|
||||||
|
* <table name="member" />
|
||||||
|
* </tables>
|
||||||
|
*/
|
||||||
|
function testTablesTagWithOneTable(){
|
||||||
|
$xml_file = $this->xmlPath . "tables_one_table.xml";
|
||||||
|
$xml_obj = Helper::getXmlObject($xml_file);
|
||||||
|
$tag = new TablesTag($xml_obj->tables);
|
||||||
|
|
||||||
|
$expected = "array(new Table('\"xe_member\"', '\"member\"'))";
|
||||||
|
$actual = $tag->toString();
|
||||||
|
|
||||||
|
$this->_testCachedOutput($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests a simple <tables> tag:
|
||||||
|
* <tables>
|
||||||
|
* <table name="member_group" alias="a" />
|
||||||
|
* <table name="member_group_member" alias="b" />
|
||||||
|
* </tables>
|
||||||
|
*/
|
||||||
|
function testTablesTagWithTwoTablesNoJoin(){
|
||||||
|
$xml_file = $this->xmlPath . "tables_two_tables_no_join.xml";
|
||||||
|
$xml_obj = Helper::getXmlObject($xml_file);
|
||||||
|
$tag = new TablesTag($xml_obj->tables);
|
||||||
|
|
||||||
|
$expected = "array(
|
||||||
|
new Table('\"xe_member_group\"', '\"a\"')
|
||||||
|
,new Table('\"xe_member_group_member\"', '\"b\"')
|
||||||
|
)";
|
||||||
|
$actual = $tag->toString();
|
||||||
|
|
||||||
|
$this->_testCachedOutput($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests a simple <tables> tag:
|
||||||
|
* <tables>
|
||||||
|
* <table name="files" alias="files" />
|
||||||
|
* <table name="member" alias="member" type="left join">
|
||||||
|
* <conditions>
|
||||||
|
* <condition operation="equal" column="files.member_srl" default="member.member_srl" />
|
||||||
|
* </conditions>
|
||||||
|
* </table>
|
||||||
|
* </tables>
|
||||||
|
*/
|
||||||
|
function testTablesTagWithTwoTablesWithJoin(){
|
||||||
|
$xml_file = $this->xmlPath . "tables_two_tables_with_join.xml";
|
||||||
|
$xml_obj = Helper::getXmlObject($xml_file);
|
||||||
|
$tag = new TablesTag($xml_obj->tables);
|
||||||
|
|
||||||
|
$expected = "array(
|
||||||
|
new Table('\"xe_files\"', '\"files\"')
|
||||||
|
,new JoinTable('\"xe_member\"'
|
||||||
|
, '\"member\"'
|
||||||
|
, \"left join\"
|
||||||
|
, array(
|
||||||
|
new ConditionGroup(
|
||||||
|
array(
|
||||||
|
new Condition(
|
||||||
|
'\"files\".\"member_srl\"'
|
||||||
|
,'\"member\".\"member_srl\"'
|
||||||
|
,\"equal\"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)";
|
||||||
|
$actual = $tag->toString();
|
||||||
|
|
||||||
|
$this->_testCachedOutput($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests a simple <tables> tag:
|
||||||
|
* <tables>
|
||||||
|
* <table name="files" alias="files" />
|
||||||
|
* <table name="member" alias="member" type="left join">
|
||||||
|
* <conditions>
|
||||||
|
* <condition operation="equal" column="files.member_srl" default="member.member_srl" />
|
||||||
|
* </conditions>
|
||||||
|
* </table>
|
||||||
|
* </tables>
|
||||||
|
*/
|
||||||
|
function testGetTables(){
|
||||||
|
$xml_file = $this->xmlPath . "tables_two_tables_with_join.xml";
|
||||||
|
$xml_obj = Helper::getXmlObject($xml_file);
|
||||||
|
$tag = new TablesTag($xml_obj->tables);
|
||||||
|
|
||||||
|
$tables = $tag->getTables();
|
||||||
|
|
||||||
|
$this->assertEquals(2, count($tables));
|
||||||
|
$this->assertTrue(is_a($tables[0], 'TableTag'));
|
||||||
|
$this->assertTrue(is_a($tables[1], 'TableTag'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
<tables>
|
||||||
|
<table name="member" />
|
||||||
|
</tables>
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
<tables>
|
||||||
|
<table name="member_group" alias="a" />
|
||||||
|
<table name="member_group_member" alias="b" />
|
||||||
|
</tables>
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
<tables>
|
||||||
|
<table name="files" alias="files" />
|
||||||
|
<table name="member" alias="member" type="left join">
|
||||||
|
<conditions>
|
||||||
|
<condition operation="equal" column="files.member_srl" default="member.member_srl" />
|
||||||
|
</conditions>
|
||||||
|
</table>
|
||||||
|
</tables>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue