diff options
author | Igor Moiseev <[email protected]> | 2013-12-01 22:19:43 +0100 |
---|---|---|
committer | Simon Holywell <[email protected]> | 2014-04-26 13:45:46 +0100 |
commit | b2420cb14ab709b6fd2cc4387a0f9fc1a4a5f243 (patch) | |
tree | ec2e859689d01ca5df85223ce65ce04cd4d2b4b5 /test | |
parent | de29638b4891c47b6293a52b76d146675fbcd012 (diff) |
Implemetation of raw_join
Diffstat (limited to 'test')
-rw-r--r-- | test/QueryBuilderPsr1Test53.php | 12 | ||||
-rw-r--r-- | test/QueryBuilderTest.php | 12 |
2 files changed, 24 insertions, 0 deletions
diff --git a/test/QueryBuilderPsr1Test53.php b/test/QueryBuilderPsr1Test53.php index a51103e..88c5a07 100644 --- a/test/QueryBuilderPsr1Test53.php +++ b/test/QueryBuilderPsr1Test53.php @@ -385,6 +385,18 @@ class QueryBuilderPsr1Test53 extends PHPUnit_Framework_TestCase { $this->assertEquals($expected, ORM::getLastQuery()); } + public function testRawJoin() { + ORM::forTable('widget')->rawJoin('INNER JOIN ( SELECT * FROM `widget_handle` )', array('widget_handle.widget_id', '=', 'widget.id'), 'widget_handle')->findMany(); + $expected = "SELECT * FROM `widget` INNER JOIN ( SELECT * FROM `widget_handle` ) `widget_handle` ON `widget_handle`.`widget_id` = `widget`.`id`"; + $this->assertEquals($expected, ORM::getLastQuery()); + } + + public function testRawJoinWithParameters() { + ORM::forTable('widget')->rawJoin('INNER JOIN ( SELECT * FROM `widget_handle` WHERE `widget_handle`.name LIKE ? AND `widget_handle`.category = ?)', array('widget_handle.widget_id', '=', 'widget.id'), 'widget_handle', array('%button%', 2))->findMany(); + $expected = "SELECT * FROM `widget` INNER JOIN ( SELECT * FROM `widget_handle` WHERE `widget_handle`.name LIKE '%button%' AND `widget_handle`.category = '2') `widget_handle` ON `widget_handle`.`widget_id` = `widget`.`id`"; + $this->assertEquals($expected, ORM::getLastQuery()); + } + public function testSelectWithDistinct() { ORM::forTable('widget')->distinct()->select('name')->findMany(); $expected = "SELECT DISTINCT `name` FROM `widget`"; diff --git a/test/QueryBuilderTest.php b/test/QueryBuilderTest.php index ebd2833..fc5b45e 100644 --- a/test/QueryBuilderTest.php +++ b/test/QueryBuilderTest.php @@ -385,6 +385,18 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase { $this->assertEquals($expected, ORM::get_last_query()); } + public function testRawJoin() { + ORM::for_table('widget')->raw_join('INNER JOIN ( SELECT * FROM `widget_handle` )', array('widget_handle.widget_id', '=', 'widget.id'), 'widget_handle')->find_many(); + $expected = "SELECT * FROM `widget` INNER JOIN ( SELECT * FROM `widget_handle` ) `widget_handle` ON `widget_handle`.`widget_id` = `widget`.`id`"; + $this->assertEquals($expected, ORM::get_last_query()); + } + + public function testRawJoinWithParameters() { + ORM::for_table('widget')->raw_join('INNER JOIN ( SELECT * FROM `widget_handle` WHERE `widget_handle`.name LIKE ? AND `widget_handle`.category = ?)', array('widget_handle.widget_id', '=', 'widget.id'), 'widget_handle', array('%button%', 2))->find_many(); + $expected = "SELECT * FROM `widget` INNER JOIN ( SELECT * FROM `widget_handle` WHERE `widget_handle`.name LIKE '%button%' AND `widget_handle`.category = '2') `widget_handle` ON `widget_handle`.`widget_id` = `widget`.`id`"; + $this->assertEquals($expected, ORM::get_last_query()); + } + public function testSelectWithDistinct() { ORM::for_table('widget')->distinct()->select('name')->find_many(); $expected = "SELECT DISTINCT `name` FROM `widget`"; |