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:
ucorina 2011-07-05 19:52:27 +00:00
parent d248d70773
commit 7112d518c8
7 changed files with 178 additions and 4 deletions

View file

@ -63,8 +63,8 @@
new Condition(\'"module_categories"."module_category_srl"\',\'"modules"."module_category_srl"\',"equal")
))
))';
$actual = Helper::cleanQuery($actual);
$expected = Helper::cleanQuery($expected);
$actual = Helper::cleanString($actual);
$expected = Helper::cleanString($expected);
$this->assertEquals($expected, $actual);
}

View 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'));
}
}

View file

@ -0,0 +1,3 @@
<tables>
<table name="member" />
</tables>

View file

@ -0,0 +1,4 @@
<tables>
<table name="member_group" alias="a" />
<table name="member_group_member" alias="b" />
</tables>

View file

@ -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>