You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
3.0 KiB

13 years ago
<?php
12 years ago
namespace yiiunit\framework\db;
13 years ago
use yii\db\Connection;
use yii\db\Command;
use yii\db\Query;
use yii\db\DataReader;
13 years ago
class QueryTest extends \yiiunit\MysqlTestCase
{
function testSelect()
{
// default
$query = new Query;
$query->select('*');
13 years ago
$this->assertEquals('*', $query->select);
13 years ago
$this->assertNull($query->distinct);
13 years ago
$this->assertEquals(null, $query->selectOption);
$query = new Query;
13 years ago
$query->select('id, name', 'something')->distinct(true);
13 years ago
$this->assertEquals('id, name', $query->select);
$this->assertTrue($query->distinct);
$this->assertEquals('something', $query->selectOption);
}
function testFrom()
{
$query = new Query;
$query->from('tbl_user');
$this->assertEquals('tbl_user', $query->from);
}
function testWhere()
{
$query = new Query;
$query->where('id = :id', array(':id' => 1));
$this->assertEquals('id = :id', $query->where);
$this->assertEquals(array(':id' => 1), $query->params);
$query->andWhere('name = :name', array(':name' => 'something'));
$this->assertEquals(array('and', 'id = :id', 'name = :name'), $query->where);
$this->assertEquals(array(':id' => 1, ':name' => 'something'), $query->params);
$query->orWhere('age = :age', array(':age' => '30'));
$this->assertEquals(array('or', array('and', 'id = :id', 'name = :name'), 'age = :age'), $query->where);
$this->assertEquals(array(':id' => 1, ':name' => 'something', ':age' => '30'), $query->params);
}
function testJoin()
{
}
function testGroup()
13 years ago
{
$query = new Query;
12 years ago
$query->groupBy('team');
$this->assertEquals('team', $query->groupBy);
13 years ago
$query->addGroup('company');
12 years ago
$this->assertEquals(array('team', 'company'), $query->groupBy);
13 years ago
$query->addGroup('age');
12 years ago
$this->assertEquals(array('team', 'company', 'age'), $query->groupBy);
13 years ago
}
function testHaving()
{
$query = new Query;
$query->having('id = :id', array(':id' => 1));
$this->assertEquals('id = :id', $query->having);
$this->assertEquals(array(':id' => 1), $query->params);
$query->andHaving('name = :name', array(':name' => 'something'));
$this->assertEquals(array('and', 'id = :id', 'name = :name'), $query->having);
$this->assertEquals(array(':id' => 1, ':name' => 'something'), $query->params);
$query->orHaving('age = :age', array(':age' => '30'));
$this->assertEquals(array('or', array('and', 'id = :id', 'name = :name'), 'age = :age'), $query->having);
$this->assertEquals(array(':id' => 1, ':name' => 'something', ':age' => '30'), $query->params);
}
function testOrder()
13 years ago
{
$query = new Query;
12 years ago
$query->orderBy('team');
$this->assertEquals('team', $query->orderBy);
13 years ago
12 years ago
$query->addOrderBy('company');
$this->assertEquals(array('team', 'company'), $query->orderBy);
13 years ago
12 years ago
$query->addOrderBy('age');
$this->assertEquals(array('team', 'company', 'age'), $query->orderBy);
13 years ago
}
function testLimitOffset()
{
$query = new Query;
$query->limit(10)->offset(5);
$this->assertEquals(10, $query->limit);
$this->assertEquals(5, $query->offset);
}
function testUnion()
{
}
}