diff options
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`"; |