diff options
author | umherirrender <umherirrender_de.wp@web.de> | 2012-08-15 15:16:09 +0200 |
---|---|---|
committer | umherirrender <umherirrender_de.wp@web.de> | 2012-08-15 15:16:09 +0200 |
commit | aff21af9aea38ea2939604877e5d39a2c66e1f7a (patch) | |
tree | 66de319baf13bc811914c4082382526e9eb952fc /tests/phpunit/includes/db/DatabaseSQLTest.php | |
parent | 4be016ee5c1e2490abac5d9d9d95607dbe5c97af (diff) | |
download | mediawikicore-aff21af9aea38ea2939604877e5d39a2c66e1f7a.tar.gz mediawikicore-aff21af9aea38ea2939604877e5d39a2c66e1f7a.zip |
Allow aliased field names with separated syntax
This introduce the syntax from aliased table names for aliased field
names into the abstract database layer:
array( 'alias' => 'field' ) gives 'field AS alias'
This patch also includes changes to query pages, api and some more
places to show, how the new syntax looks in "production".
This allow us to remove the "AS" for Non-PostgreSQL databases, if we
want that.
Change-Id: I5f0de1c2f29092c173aec3de93ffdef436799e8d
Diffstat (limited to 'tests/phpunit/includes/db/DatabaseSQLTest.php')
-rw-r--r-- | tests/phpunit/includes/db/DatabaseSQLTest.php | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/phpunit/includes/db/DatabaseSQLTest.php b/tests/phpunit/includes/db/DatabaseSQLTest.php new file mode 100644 index 000000000000..d56e632c3051 --- /dev/null +++ b/tests/phpunit/includes/db/DatabaseSQLTest.php @@ -0,0 +1,75 @@ +<?php + +/** + * Test the abstract database layer + * Using Mysql for the sql at the moment TODO + * + * @group Database + */ +class DatabaseSQLTest extends MediaWikiTestCase { + + public function setUp() { + // TODO support other DBMS or find another way to do it + if( $this->db->getType() !== 'mysql' ) { + $this->markTestSkipped( 'No mysql database' ); + } + } + + /** + * @dataProvider dataSQL + */ + function testSQL( $sql, $sqlText ) { + $this->assertEquals( trim( $this->db->selectSQLText( + isset( $sql['tables'] ) ? $sql['tables'] : array(), + isset( $sql['fields'] ) ? $sql['fields'] : array(), + isset( $sql['conds'] ) ? $sql['conds'] : array(), + __METHOD__, + isset( $sql['options'] ) ? $sql['options'] : array(), + isset( $sql['join_conds'] ) ? $sql['join_conds'] : array() + ) ), $sqlText ); + } + + function dataSQL() { + return array( + array( + array( + 'tables' => 'table', + 'fields' => array( 'field', 'alias' => 'field2' ), + 'conds' => array( 'alias' => 'text' ), + ), + "SELECT field,field2 AS alias " . + "FROM `unittest_table` " . + "WHERE alias = 'text'" + ), + array( + array( + 'tables' => 'table', + 'fields' => array( 'field', 'alias' => 'field2' ), + 'conds' => array( 'alias' => 'text' ), + 'options' => array( 'LIMIT' => 1, 'ORDER BY' => 'field' ), + ), + "SELECT field,field2 AS alias " . + "FROM `unittest_table` " . + "WHERE alias = 'text' " . + "ORDER BY field " . + "LIMIT 1" + ), + array( + array( + 'tables' => array( 'table', 't2' => 'table2' ), + 'fields' => array( 'tid', 'field', 'alias' => 'field2', 't2.id' ), + 'conds' => array( 'alias' => 'text' ), + 'options' => array( 'LIMIT' => 1, 'ORDER BY' => 'field' ), + 'join_conds' => array( 't2' => array( + 'LEFT JOIN', 'tid = t2.id' + )), + ), + "SELECT tid,field,field2 AS alias,t2.id " . + "FROM `unittest_table` LEFT JOIN `unittest_table2` `t2` ON ((tid = t2.id)) " . + "WHERE alias = 'text' " . + "ORDER BY field " . + "LIMIT 1" + ), + ); + } +}
\ No newline at end of file |