public function testHavingComplexQuery() { $qb = new \Quark\Query\Select(array(array('users.id', 'id'), array('users.username', 'name'), array('users.password', 'pass'))); $query = $qb->from(array('users', 'u'))->havingOpen()->having('u.age', '<', 18)->orHaving('u.status', '=', 'child')->havingClose()->orHavingOpen()->having('u.age', '>=', 18)->andHaving('u.status', '=', 'child')->orHavingClose()->compile(); $expectedQuery = "SELECT users.id AS id, users.username AS name, users.password AS pass FROM users AS u HAVING (u.age < 18 OR u.status = 'child') OR (u.age >= 18 AND u.status = 'child')"; $this->assertSame($expectedQuery, $query); }
public function testExceptionWhenUsingTableAliasInInsertSelectConstruction() { $qb = new \Quark\Query\Select(array('name', 'email')); $select = $qb->from(array('users', 'u'))->join(array('posts', 'p'), 'LEFT')->on('p.user_id', '=', 'u.id')->where('u.name', '=', 'test')->havingOpen()->having('u.age', '>', '10')->orHaving('u.age', '<', '14')->havingClose()->orderBy('u.age', 'DESC'); try { $this->queryBuilder->table(array('posts', 'p'))->columns(array('p.username', 'p.posts', 'p.age'))->select($select)->compile(); $this->assertTrue(false, 'Exception not thrown'); } catch (\Quark\Exception\QuarkException $e) { $this->assertTrue(true, 'Exception thrown'); } }