Ejemplo n.º 1
0
 /**
  * @test
  */
 public function simpleSelectBuilderWithJoinVeryComplexWhereGroupOrderLimit()
 {
     $select = array('id' => 'users', 'username' => 'users', 'password AS user_password' => 'users');
     $from = array('name' => 'users', 'database' => $this->database1);
     $join = array('types' => array('on' => '`types`.`id` = `usr`.`type_id`', 'type' => 'left'), 'statuses' => array('alias' => 'stt', 'on' => '`stt`.`id` = `usr`.`status_id`', 'database' => 'test'));
     $where = array(array('and' => array('username' => 'test', 'id' => array('value' => array(1, 2, 3)))), array('or' => array('id2' => array('value' => '123', 'condition' => '!='), 'id3' => array('value' => '%test%', 'condition' => 'like'))), array('or' => array('id4' => array('value' => '10', 'condition' => '>='), 'id5' => array('value' => array(1, 100), 'condition' => 'between'), 'id6' => array('value' => array(1, 100), 'condition' => '!='))), array('or' => array('id7' => array('value' => array(1, 100), 'condition' => 'between'), 'id8' => array('value' => array(1, 100), 'condition' => 'between'))));
     $group = array('id1', 'id2' => 'types', 'id3', 'id4' => 'types');
     $order = array('id1', 'id2' => 'types', 'id3 desc', 'id4 DESC' => 'types');
     $results = $this->databaseConnection->simpleSelectBuilder($select, $from, $join, $where, $group, $order, 10, 10);
     $excepted = "SELECT `users`.`id`, `users`.`username`, password AS `user_password` FROM `{$this->trueDatabase1}`.`users` AS `users` LEFT JOIN `{$this->trueDatabase1}`.`types` AS `types` ON `types`.`id` = `usr`.`type_id` INNER JOIN `test`.`statuses` AS `stt` ON `stt`.`id` = `usr`.`status_id` WHERE (`users`.`username` = 'test' AND `users`.`id` IN('1', '2', '3')) AND (`users`.`id2` != '123' OR `users`.`id3` LIKE '%test%') AND (`users`.`id4` >= '10' OR `users`.`id5` BETWEEN '1' AND '100' OR `users`.`id6` NOT IN('1', '100')) AND (`users`.`id7` BETWEEN '1' AND '100' OR `users`.`id8` BETWEEN '1' AND '100') GROUP BY `users`.`id1`, `types`.`id2`, `users`.`id3`, `types`.`id4` ORDER BY `users`.`id1` ASC, `types`.`id2` ASC, `users`.`id3` DESC, `types`.`id4` DESC LIMIT 10, 10";
     $this->assertEquals($excepted, $results);
 }