From 7112d518c8eae0815435ae9902cc1275716a5f8a Mon Sep 17 00:00:00 2001 From: ucorina Date: Tue, 5 Jul 2011 19:52:27 +0000 Subject: [PATCH] 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 --- test-phpUnit/Helper.class.php | 7 +- .../classes/db/queryparts/table/TableTest.php | 42 +++++++ .../xml/xmlquery/tags/table/TableTagTest.php | 4 +- .../xml/xmlquery/tags/table/TablesTagTest.php | 114 ++++++++++++++++++ .../tags/table/data/tables_one_table.xml | 3 + .../table/data/tables_two_tables_no_join.xml | 4 + .../data/tables_two_tables_with_join.xml | 8 ++ 7 files changed, 178 insertions(+), 4 deletions(-) create mode 100644 test-phpUnit/classes/db/queryparts/table/TableTest.php create mode 100644 test-phpUnit/classes/xml/xmlquery/tags/table/TablesTagTest.php create mode 100644 test-phpUnit/classes/xml/xmlquery/tags/table/data/tables_one_table.xml create mode 100644 test-phpUnit/classes/xml/xmlquery/tags/table/data/tables_two_tables_no_join.xml create mode 100644 test-phpUnit/classes/xml/xmlquery/tags/table/data/tables_two_tables_with_join.xml diff --git a/test-phpUnit/Helper.class.php b/test-phpUnit/Helper.class.php index 68a122883..597d52ac3 100644 --- a/test-phpUnit/Helper.class.php +++ b/test-phpUnit/Helper.class.php @@ -1,14 +1,17 @@ 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()); + } +} +?> diff --git a/test-phpUnit/classes/xml/xmlquery/tags/table/TableTagTest.php b/test-phpUnit/classes/xml/xmlquery/tags/table/TableTagTest.php index 1312199fd..1e7c86d74 100644 --- a/test-phpUnit/classes/xml/xmlquery/tags/table/TableTagTest.php +++ b/test-phpUnit/classes/xml/xmlquery/tags/table/TableTagTest.php @@ -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); } diff --git a/test-phpUnit/classes/xml/xmlquery/tags/table/TablesTagTest.php b/test-phpUnit/classes/xml/xmlquery/tags/table/TablesTagTest.php new file mode 100644 index 000000000..5181cafbd --- /dev/null +++ b/test-phpUnit/classes/xml/xmlquery/tags/table/TablesTagTest.php @@ -0,0 +1,114 @@ +xmlPath = str_replace('TablesTagTest.php', '', str_replace('\\', '/', __FILE__)) . $this->xmlPath; + } + + /** + * Tests a simple tag: + * + * + * + */ + 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 tag: + * + *
+ *
+ * + */ + 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 tag: + * + *
+ *
+ * + * + * + *
+ *
+ */ + 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 tag: + * + * + *
+ * + * + * + *
+ *
+ */ + 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')); + } + } \ No newline at end of file diff --git a/test-phpUnit/classes/xml/xmlquery/tags/table/data/tables_one_table.xml b/test-phpUnit/classes/xml/xmlquery/tags/table/data/tables_one_table.xml new file mode 100644 index 000000000..525df54be --- /dev/null +++ b/test-phpUnit/classes/xml/xmlquery/tags/table/data/tables_one_table.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/test-phpUnit/classes/xml/xmlquery/tags/table/data/tables_two_tables_no_join.xml b/test-phpUnit/classes/xml/xmlquery/tags/table/data/tables_two_tables_no_join.xml new file mode 100644 index 000000000..cdedcb831 --- /dev/null +++ b/test-phpUnit/classes/xml/xmlquery/tags/table/data/tables_two_tables_no_join.xml @@ -0,0 +1,4 @@ + +
+
+ \ No newline at end of file diff --git a/test-phpUnit/classes/xml/xmlquery/tags/table/data/tables_two_tables_with_join.xml b/test-phpUnit/classes/xml/xmlquery/tags/table/data/tables_two_tables_with_join.xml new file mode 100644 index 000000000..fd8d8775e --- /dev/null +++ b/test-phpUnit/classes/xml/xmlquery/tags/table/data/tables_two_tables_with_join.xml @@ -0,0 +1,8 @@ + +
+
+ + + +
+
\ No newline at end of file